Created
April 11, 2015 05:08
-
-
Save olivergeorge/960dd21e6ec3ffa5232c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defprotocol IClear | |
(clear! [x])) | |
(defn field-as-value [field-cursor] | |
(reify | |
IDeref | |
(-deref [_] (:value field-cursor)) | |
ISwap | |
(-swap! [o f] (reset! o (f @o))) | |
(-swap! [o f a] (reset! o (f @o a))) | |
(-swap! [o f a b] (reset! o (f @o a b))) | |
(-swap! [o f a b xs] (reset! o (apply f @o a b xs))) | |
IReset | |
(-reset! [o new-value] (om/update! field-cursor :value new-value)) | |
IClear | |
(clear! [_] (om/transact! field-cursor :value (:initial field-cursor))))) | |
(defn state-as-value [owner key] | |
(reify | |
IDeref | |
(-deref [_] (om/get-state owner key)) | |
ISwap | |
(-swap! [o f] (reset! o (f @o))) | |
(-swap! [o f a] (reset! o (f @o a))) | |
(-swap! [o f a b] (reset! o (f @o a b))) | |
(-swap! [o f a b xs] (reset! o (apply f @o a b xs))) | |
IReset | |
(-reset! [o new-value] (om/set-state! owner key new-value)) | |
IClear | |
(clear! [_] (om/set-state! owner key nil)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment