Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

28
LINES

< > BotCompany Repo | #1032283 // WatchVariable

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (4895L/27K).

sclass WatchVariable<A> extends Var<A> {
  IF0<A> f;
  ReliableSingleThread rst = new(r update_impl);
  
  event change;
  
  *(IF0<A> *f) {
    update();
  }
  
  *(IF0<A> *f, Runnable onChange) {
    onChange(onChange);
    update();
  }
  
  // only run in rst
  void update_impl() {
    A value = f?!;
    if (!eq(value, get())) {
      set(value);
      change();
    }
  }
  
  void update aka trigger() {
    rst!;
  }
}

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: 140 / 274
Version history: 6 change(s)
Referenced in: #1034167 - Standard Classes + Interfaces (LIVE, continuation of #1003674)