Libraryless. Click here for Pure Java version (16460L/99K).
1 | sclass Dyn_FieldWatcher is AutoCloseable {
|
2 | DynModule module; |
3 | S field; |
4 | O value; |
5 | Runnable action; |
6 | |
7 | Runnable changeListener = r check; |
8 | VF1<S> fieldChangeListener = voidfunc(S f) {
|
9 | if (eq(f, field)) |
10 | check(); |
11 | }; |
12 | |
13 | swappable O cloneValue(O o) { ret o; }
|
14 | |
15 | *(DynModule module, S field, Runnable action) {
|
16 | this(module, field, action, null); |
17 | } |
18 | |
19 | *(DynModule *module, S *field, Runnable *action, IF1 *cloneValue) {
|
20 | value = cloneValue(get(module, field)); |
21 | |
22 | // Let's do both for safety |
23 | module.onChange(changeListener); |
24 | module.onFieldChange(fieldChangeListener); |
25 | } |
26 | |
27 | void check {
|
28 | O newValue = cloneValue(get(module, field)); |
29 | if (eq(value, newValue)) ret; |
30 | value = newValue; |
31 | dm_q(module, action); |
32 | } |
33 | |
34 | close {
|
35 | module.removeChangeListener(changeListener); |
36 | module.removeFieldChangeListener(fieldChangeListener); |
37 | } |
38 | } |
download show line numbers debug dex old transpilations
Travelled to 8 computer(s): bhatertpkbcr, cfunsshuasjs, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv
No comments. add comment
| Snippet ID: | #1022885 |
| Snippet name: | Dyn_FieldWatcher - watch a field in a DynModule and call Runnable in module queue. might work for non-persistent fields now too |
| Eternal ID of this version: | #1022885/12 |
| Text MD5: | 45192cec7a0bebe1bf64b4a652878042 |
| Transpilation MD5: | 6b1d3f7eb1cc5648b4273db5bbae92c9 |
| Author: | stefan |
| Category: | javax / stefan's os |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2022-01-21 18:37:01 |
| Source code size: | 931 bytes / 38 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 610 / 1224 |
| Version history: | 11 change(s) |
| Referenced in: | [show references] |