Skip to content

Commit

Permalink
Auto-increment atom watcher key. Closes lynaghk#10.
Browse files Browse the repository at this point in the history
  • Loading branch information
lynaghk committed Mar 29, 2012
1 parent 76eba58 commit 16bfa87
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/cljs/c2/core.cljs
Expand Up @@ -68,7 +68,8 @@
;;(defmethod unify! :seq)



;;Used to generate unique IDs for auto-unify atom watchers
(def ^:private auto-unify-id (atom 0))

(defn unify!
"Calls (mapping datum idx) for each datum and appends resulting elements to container.
Expand All @@ -93,7 +94,7 @@ Optional enter, update, and exit functions called before DOM is changed; return
;;This logic should be abstracted out via a (unify!) multimethod, once (apply multimethod) is fixed in ClojureScript
data (if (instance? cljs.core.Atom data)
;;Then add a watcher to auto-unify when the atom changes, and deference data for this run
(do (add-watch data :auto-unify
(do (add-watch data (keyword (str "auto-unify" (swap! auto-unify-id inc)))
(fn [key data-atom old new]
(p "atom updated; automatically calling unify!")
(unify! container data mapping
Expand Down

0 comments on commit 16bfa87

Please sign in to comment.