From cf497faa4ae719ac866731ef41d2fd3de85e701e Mon Sep 17 00:00:00 2001 From: Juraj Kirchheim Date: Thu, 28 Nov 2024 14:56:24 +0100 Subject: [PATCH] Try to make tink_state -> react binding via Invalidatable. --- src/coconut/react/View.hx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/coconut/react/View.hx b/src/coconut/react/View.hx index f621182..094e113 100644 --- a/src/coconut/react/View.hx +++ b/src/coconut/react/View.hx @@ -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).onInvalidate(this); } + public function invalidate() + @:privateAccess target.__react_setState({ revision: target.__react_state.revision + 1 }); + public function destroy() this.link.cancel();