-
Notifications
You must be signed in to change notification settings - Fork 10
hot swapping
jiyinyiyong edited this page Mar 21, 2020
·
4 revisions
Hot swapping is done by the compiler. What you need to do is to call respo.core/clear-cache!
before re-rendering happens:
(defn reload! []
(clear-cache!) ; clear component cachees
(render-app!) ; rerender DOM tree, I mean, a diff/patch loop
(println "Code update."))
If you don't, in the next rendering phase old element tree would be used if no argument changes found, which means Respo would still use render functions defined previously.
In Respo, you are asked to define *store
explicitly. They the global states of data. As an Atom, the value inside is immutable, but the reference is mutable. During hot swapping, variables defined with defonce
will be retained. As a result, component states are persistent even code is swapped:
(defonce *store
(atom
(or
(let [raw (or (.getItem js/localStorage "respo") "{:data [], :states {}}")]
(read-string raw))
schema/store)))