Skip to content

Commit

Permalink
fix :bind rebuilding its child when upstream bind change
Browse files Browse the repository at this point in the history
  • Loading branch information
cgrand committed Dec 11, 2024
1 parent f37a729 commit 5c3749f
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions clj/src/cljd/flutter.cljd
Original file line number Diff line number Diff line change
Expand Up @@ -544,17 +544,19 @@
.aspect ~(into [] (map (fn [[sym [type-or-kw]]] type-or-kw)) inherited-bindings)))])))))))

(defn ^:macro-support expand-bind [env bindings-map forms]
`(-widget-cont ~env
:context ctx#
:let [bindings# ~bindings-map
elt# (#/(.getElementForInheritedWidgetOfExactType InheritedBindings) ctx#)
prev-bindings# (some-> elt# ^InheritedBindings (.-widget) .-bindings)
non-shadowed-keys#
(remove (fn [k#] (contains? bindings# k#)) (keys prev-bindings#))
_ (when (seq non-shadowed-keys#)
(.dependOnInheritedElement ctx# elt# .aspect non-shadowed-keys#))]
(cljd.flutter/InheritedBindings. (merge prev-bindings# bindings#)
(-widget-cont ~(assoc env :key nil :closest-ctx false) ~@forms))))
`(let [child# (f/widget ~@forms)]
(reify :extends (widgets/StatelessWidget .key ~(:key env))
:name-hint "bind"
:no-meta true
(~'build [_# ctx#]
(let [bindings# ~bindings-map
elt# (#/(.getElementForInheritedWidgetOfExactType InheritedBindings) ctx#)
prev-bindings# (some-> elt# ^InheritedBindings (.-widget) .-bindings)
non-shadowed-keys#
(remove (fn [k#] (contains? bindings# k#)) (keys prev-bindings#))]
(when (seq non-shadowed-keys#)
(.dependOnInheritedElement ctx# elt# .aspect non-shadowed-keys#))
(cljd.flutter/InheritedBindings. (merge prev-bindings# bindings#) child#))))))

(defn ^:macro-support expand-vsync [env name forms]
`(reify :extends (widgets/StatefulWidget .key ~(:key env))
Expand Down

0 comments on commit 5c3749f

Please sign in to comment.