mirror of https://github.com/status-im/reagent.git
Be compatible with ClojureScript 0.0-2173: implement IAtom, ISwap,
IReset
This commit is contained in:
parent
7951b43aeb
commit
908452c126
|
@ -4,7 +4,7 @@
|
|||
:license {:name "MIT"}
|
||||
:description "A simple ClojureScript interface to React"
|
||||
:dependencies [[org.clojure/clojure "1.5.1"]
|
||||
[org.clojure/clojurescript "0.0-2156"]]
|
||||
[org.clojure/clojurescript "0.0-2173"]]
|
||||
:plugins [[lein-cljsbuild "1.0.1"]
|
||||
[com.cemerick/clojurescript.test "0.2.1"]]
|
||||
:profiles {:prod {:cljsbuild
|
||||
|
|
|
@ -28,7 +28,9 @@
|
|||
(conj (if (nil? captured) #{} captured)
|
||||
derefable))))))
|
||||
|
||||
(deftype RAtom [state meta validator watches]
|
||||
(deftype RAtom [^:mutable state meta validator ^:mutable watches]
|
||||
IAtom
|
||||
|
||||
IEquiv
|
||||
(-equiv [o other] (identical? o other))
|
||||
|
||||
|
@ -37,6 +39,26 @@
|
|||
(notify-deref-watcher! this)
|
||||
state)
|
||||
|
||||
IReset
|
||||
(-reset! [a new-value]
|
||||
(when-not (nil? validator)
|
||||
(assert (validator new-value) "Validator rejected reference state"))
|
||||
(let [old-value state]
|
||||
(set! state new-value)
|
||||
(when-not (nil? watches)
|
||||
(-notify-watches a old-value new-value))
|
||||
new-value))
|
||||
|
||||
ISwap
|
||||
(-swap! [a f]
|
||||
(-reset! a (f state)))
|
||||
(-swap! [a f x]
|
||||
(-reset! a (f state x)))
|
||||
(-swap! [a f x y]
|
||||
(-reset! a (f state x y)))
|
||||
(-swap! [a f x y more]
|
||||
(-reset! a (apply f state x y more)))
|
||||
|
||||
IMeta
|
||||
(-meta [_] meta)
|
||||
|
||||
|
@ -53,9 +75,9 @@
|
|||
nil)
|
||||
nil watches))
|
||||
(-add-watch [this key f]
|
||||
(set! (.-watches this) (assoc watches key f)))
|
||||
(set! watches (assoc watches key f)))
|
||||
(-remove-watch [this key]
|
||||
(set! (.-watches this) (dissoc watches key)))
|
||||
(set! watches (dissoc watches key)))
|
||||
|
||||
IHash
|
||||
(-hash [this] (goog/getUid this)))
|
||||
|
@ -85,6 +107,8 @@
|
|||
(deftype Reaction [f ^:mutable state ^:mutable dirty? ^:mutable active?
|
||||
^:mutable watching ^:mutable watches
|
||||
auto-run on-set on-dispose]
|
||||
IAtom
|
||||
|
||||
IWatchable
|
||||
(-notify-watches [this oldval newval]
|
||||
(when on-set
|
||||
|
@ -99,6 +123,23 @@
|
|||
(when (empty? watches)
|
||||
(dispose! this)))
|
||||
|
||||
IReset
|
||||
(-reset! [a new-value]
|
||||
(let [old-value state]
|
||||
(set! state new-value)
|
||||
(-notify-watches a old-value new-value)
|
||||
new-value))
|
||||
|
||||
ISwap
|
||||
(-swap! [a f]
|
||||
(-reset! a (f state)))
|
||||
(-swap! [a f x]
|
||||
(-reset! a (f state x)))
|
||||
(-swap! [a f x y]
|
||||
(-reset! a (f state x y)))
|
||||
(-swap! [a f x y more]
|
||||
(-reset! a (apply f state x y more)))
|
||||
|
||||
IComputedImpl
|
||||
(-handle-change [this sender oldval newval]
|
||||
(when (and active? (not dirty?) (not (identical? oldval newval)))
|
||||
|
|
Loading…
Reference in New Issue