From a147cf89b3b76db3bdbd4b7e3a26c54ee5e688de Mon Sep 17 00:00:00 2001 From: Uday Verma Date: Fri, 10 Jul 2015 18:35:48 -0500 Subject: [PATCH 1/2] Make add/remove refs based on ref parent states and paths instead of contains? check, keep the valid refs after the to-cursor -> adapt cycle --- src/om/core.cljs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/om/core.cljs b/src/om/core.cljs index 7486e2e0..806e3ce7 100644 --- a/src/om/core.cljs +++ b/src/om/core.cljs @@ -256,7 +256,7 @@ (when-not (zero? (count refs)) (aset cstate "__om_refs" (into #{} - (filter nil? + (remove nil? (map (fn [ref] (let [ref-val (value ref) @@ -831,17 +831,25 @@ (commit! cursor korks f) (-refresh-deps! cursor)))))) +(defn same-ref? [a b] + (and + (identical? (-state a) (-state b)) + (= (-path a) (-path b)))) + +(defn have-ref? [refs ref] + (some #(same-ref? ref %) refs)) + (defn add-ref-to-component! [c ref] (let [state (.-state c) refs (or (aget state "__om_refs") #{})] - (when-not (contains? refs ref) + (when-not (have-ref? refs ref) (aset state "__om_refs" (conj refs ref))))) (defn remove-ref-from-component! [c ref] (let [state (.-state c) refs (aget state "__om_refs")] - (when (contains? refs ref) - (aset state "__om_refs" (disj refs ref))))) + (when (have-ref? refs ref) + (aset state "__om_refs" (remove #(same-ref? ref %) refs))))) (defn observe "Given a component and a reference cursor have the component observe From 4d6a61ae096ee3ba15a0445c7a0ff413b58c4efc Mon Sep 17 00:00:00 2001 From: Uday Verma Date: Mon, 13 Jul 2015 19:38:02 -0500 Subject: [PATCH 2/2] Make sure ref-cursors can be adpated --- src/om/core.cljs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/om/core.cljs b/src/om/core.cljs index 806e3ce7..37f355d7 100644 --- a/src/om/core.cljs +++ b/src/om/core.cljs @@ -808,6 +808,9 @@ [path] (fnil identity (atom {}))) path)] (specify cursor + IAdapt + (-adapt [_ other] + (ref-cursor other)) ICursorDerive (-derive [this derived state path] (let [cursor' (to-cursor derived state path)]