diff --git a/src/om/core.cljs b/src/om/core.cljs index 7486e2e0..37f355d7 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) @@ -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)] @@ -831,17 +834,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