Libraryless. Click here for Pure Java version (4895L/27K).
1 | sclass WatchVariable<A> extends Var<A> { |
2 | IF0<A> f; |
3 | ReliableSingleThread rst = new(r update_impl); |
4 | |
5 | event change; |
6 | |
7 | *(IF0<A> *f) { |
8 | update(); |
9 | } |
10 | |
11 | *(IF0<A> *f, Runnable onChange) { |
12 | onChange(onChange); |
13 | update(); |
14 | } |
15 | |
16 | // only run in rst |
17 | void update_impl() { |
18 | A value = f?!; |
19 | if (!eq(value, get())) { |
20 | set(value); |
21 | change(); |
22 | } |
23 | } |
24 | |
25 | void update aka trigger() { |
26 | rst!; |
27 | } |
28 | } |
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj, pyentgdyhuwx
No comments. add comment
Snippet ID: | #1032283 |
Snippet name: | WatchVariable |
Eternal ID of this version: | #1032283/7 |
Text MD5: | c724822b6d139be65d06c7319113cce2 |
Transpilation MD5: | 20b12c2d5204620a1d79ec2dd86b1aad |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2021-08-25 09:32:53 |
Source code size: | 454 bytes / 28 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 141 / 275 |
Version history: | 6 change(s) |
Referenced in: | [show references] |