Skip to content

Commit

Permalink
Try to make tink_state -> react binding via Invalidatable.
Browse files Browse the repository at this point in the history
  • Loading branch information
back2dos committed Nov 28, 2024
1 parent 6b5ebec commit cf497fa
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/coconut/react/View.hx
Original file line number Diff line number Diff line change
Expand Up @@ -158,17 +158,20 @@ class ViewBase extends NativeComponent<{ revision: Int }, {}, ImplicitContext> {
}
}

private class Binding {//TODO: try to make this an Invalidatable and use the actual Revision ... the last attempt led to infinite recursion though ¯\_(ツ)_/¯
private class Binding implements Invalidatable {//TODO: try to make this an Invalidatable and use the actual Revision ... the last attempt led to infinite recursion though ¯\_(ツ)_/¯

final target:ViewBase;
final link:CallbackLink;

public function new(target) @:privateAccess {
this.target = target;
var first = true;
this.link = target.__rendered.bind(_ -> if (first) first = false else target.__react_setState({ revision: target.__react_state.revision + 1 }));
// var first = true;
this.link = (target.__rendered:ObservableObject<RenderResult>).onInvalidate(this);
}

public function invalidate()
@:privateAccess target.__react_setState({ revision: target.__react_state.revision + 1 });

public function destroy()
this.link.cancel();

Expand Down

0 comments on commit cf497fa

Please sign in to comment.