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

19
LINES

< > BotCompany Repo | #1034093 // varWithNotifyToLiveValue

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

Libraryless. Click here for Pure Java version (6254L/35K).

1  
static <A> SimpleLiveValue<A> varWithNotifyToLiveValue(Class<A> type, IVarWithNotify<A> var) {
2  
  if (var == null) null;
3  
  var lv = new SimpleLiveValue<A>(type);
4  
  var lvRef = weakRef(lv);
5  
  var.onChange(r {
6  
    var lv = lvRef!;
7  
    print ifdef varWithNotifyToLiveValue_debug("varWithNotifyToLiveValue var.onChange " + lv);
8  
    if (lv == null)
9  
      var.removeChangeListener(this);
10  
    else {
11  
      var value = var!;
12  
      print ifdef varWithNotifyToLiveValue_debug("varWithNotifyToLiveValue value " + value);
13  
      lv.set(value);
14  
    }
15  
  });
16  
  lv.onChange(-> var.set(lv!));
17  
  lv.set(var!);
18  
  ret lv;
19  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1034093
Snippet name: varWithNotifyToLiveValue
Eternal ID of this version: #1034093/7
Text MD5: 35f776f1de61712be618e99eaa999fae
Transpilation MD5: f4b6712798262972900514484e254b8f
Author: stefan
Category: javax / gui
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-02-08 02:31:09
Source code size: 619 bytes / 19 lines
Pitched / IR pitched: No / No
Views / Downloads: 117 / 208
Version history: 6 change(s)
Referenced in: [show references]