Skip to content

Instantly share code, notes, and snippets.

@asolove asolove/cursor.cljs
Created Jan 8, 2014

Embed
What would you like to do?
Om cursor protocol idea
(defprotocol ICursor
(value [self] "Get the current value of the cursor")
(transact [self f] "Update the current value of the cursor"))
(extend Atom
ICursor
(value [self]
(deref self))
(transact [self f]
(swap! self f)))
(defrecord PathCursor [parent path]
ICursor
(value [self]
(get-in (value parent) path))
(transact [self f]
(transact parent #(update-in % path f))))
(defn join [parent korks]
(let [path (if (seq? korks) korks [korks])]
(PathCursor. parent path)))
(defrecord RenameCursor [parent renames]
ICursor
(value [self]
(rename (value parent) renames))
(transact [self f]
(transact parent (fn [state]
(rename
(f (rename state renames))
(map-invert renames))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.