Libraryless. Click here for Pure Java version (5665L/31K).
svoid addWeakChangeListener(IHasChangeListeners src, ChangeTriggerable target) { addWeakChangeListener(src, target, o -> o.change()); } svoid <A> addWeakChangeListener(IHasChangeListeners src, A target, IVF1<A> action) { if (src == null || action == null || target == null) ret; var ref = weakRef(target); src.onChange(r { var target = ref!; if (target == null) src.removeChangeListener(this); else action.get(target); }); }
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1034149 |
Snippet name: | addWeakChangeListener - listener with weak reference to target that auto-removes itself when the target has been garbage collected |
Eternal ID of this version: | #1034149/4 |
Text MD5: | ee190d0f660fa4a1897b7b0f5a3d043d |
Transpilation MD5: | b369311b638d3f84cebf79f2099bd919 |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-02-08 05:43:51 |
Source code size: | 477 bytes / 16 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 168 / 271 |
Version history: | 3 change(s) |
Referenced in: | [show references] |