mirror of https://github.com/status-im/reagent.git
Simplify handling of state
Just compare new state with identical?, and forceUpdate if necessary
This commit is contained in:
parent
1ad5ef44e8
commit
8bd03a8b36
2
Makefile
2
Makefile
|
@ -9,7 +9,7 @@ PROF = dev,test
|
||||||
CLJSBUILD = client
|
CLJSBUILD = client
|
||||||
CLJSDIRS = src test
|
CLJSDIRS = src test
|
||||||
|
|
||||||
VERSION = 0.0.3 # -SNAPSHOT
|
VERSION = 0.0.4-SNAPSHOT
|
||||||
|
|
||||||
all: buildrun
|
all: buildrun
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
|
|
||||||
|
|
||||||
(defproject cloact "0.0.3"
|
(defproject cloact "0.0.4-SNAPSHOT"
|
||||||
:url "http://github.com/holmsand/cloact"
|
:url "http://github.com/holmsand/cloact"
|
||||||
:license {:name "MIT"}
|
:license {:name "MIT"}
|
||||||
:description "A simple ClojureScript interface to React"
|
:description "A simple ClojureScript interface to React"
|
||||||
|
|
|
@ -32,7 +32,8 @@
|
||||||
|
|
||||||
IWatchable
|
IWatchable
|
||||||
(-notify-watches [C old new]
|
(-notify-watches [C old new]
|
||||||
(.replaceState C new))
|
(when-not (identical? old new)
|
||||||
|
(.forceUpdate C)))
|
||||||
(-add-watch [C key f] (assert false "Component isn't really watchable"))
|
(-add-watch [C key f] (assert false "Component isn't really watchable"))
|
||||||
(-remove-watch [C key] (assert false "Component isn't really watchable"))
|
(-remove-watch [C key] (assert false "Component isn't really watchable"))
|
||||||
|
|
||||||
|
@ -120,7 +121,7 @@
|
||||||
;; reset! doesn't call -notifyWatches unless -watches is set
|
;; reset! doesn't call -notifyWatches unless -watches is set
|
||||||
(set! (.-watches C) {})
|
(set! (.-watches C) {})
|
||||||
(when f
|
(when f
|
||||||
(set! (.-cljsOldState C) (merge (.-state C) (f C)))))
|
(set! (.-state C) (merge (.-state C) (f C)))))
|
||||||
|
|
||||||
:componentWillReceiveProps
|
:componentWillReceiveProps
|
||||||
(fn [C props]
|
(fn [C props]
|
||||||
|
@ -128,17 +129,15 @@
|
||||||
|
|
||||||
:shouldComponentUpdate
|
:shouldComponentUpdate
|
||||||
(fn [C nextprops nextstate]
|
(fn [C nextprops nextstate]
|
||||||
|
;; Don't care about nextstate here, we use forceUpdate
|
||||||
|
;; when only when state has changed anyway.
|
||||||
(let [a1 (args-of C)
|
(let [a1 (args-of C)
|
||||||
a2 (-> nextprops .-cljsArgs)
|
a2 (-> nextprops .-cljsArgs)]
|
||||||
ostate (.-cljsOldState C)]
|
|
||||||
(assert (vector? a1))
|
(assert (vector? a1))
|
||||||
(set! (.-cljsOldState C) nextstate)
|
|
||||||
(if (nil? f)
|
(if (nil? f)
|
||||||
(not (and (identical? ostate nextstate)
|
(not (tmpl/equal-args a1 a2))
|
||||||
(tmpl/equal-args a1 a2)))
|
;; Call f with oldprops, newprops
|
||||||
;; Call f with oldprops, newprops, oldstate, newstate
|
(f (props-in-args a1) (props-in-args a2)))))
|
||||||
(f (props-in-args a1) (props-in-args a2)
|
|
||||||
ostate nextstate))))
|
|
||||||
|
|
||||||
:componentWillUnmount
|
:componentWillUnmount
|
||||||
(fn [C]
|
(fn [C]
|
||||||
|
|
Loading…
Reference in New Issue