mirror of https://github.com/status-im/reagent.git
Add docs for track, track! and dispose!
This commit is contained in:
parent
8141b08bdf
commit
b4dec115b2
|
@ -221,16 +221,31 @@ re-rendered."
|
||||||
([x & rest] (apply ratom/atom x rest)))
|
([x & rest] (apply ratom/atom x rest)))
|
||||||
|
|
||||||
(defn track
|
(defn track
|
||||||
|
"Takes a function and optional arguments, and returns a derefable
|
||||||
|
containing the output of that function. If the function derefs
|
||||||
|
Reagent atoms (or track, etc), the value will be updated whenever
|
||||||
|
the atom changes.
|
||||||
|
|
||||||
|
In other words, @(track foo bar) will produce the same result
|
||||||
|
as (foo bar), but foo will only be called again when the atoms it
|
||||||
|
depends on changes, and will only trigger updates of components when
|
||||||
|
its result changes.
|
||||||
|
|
||||||
|
track is lazy, i.e the function is only evaluated on deref."
|
||||||
[f & args]
|
[f & args]
|
||||||
{:pre [(ifn? f)]}
|
{:pre [(ifn? f)]}
|
||||||
(ratom/make-track f args))
|
(ratom/make-track f args))
|
||||||
|
|
||||||
(defn track!
|
(defn track!
|
||||||
|
"An eager version of track. The function passed is called
|
||||||
|
immediately, and continues to be called when needed, until stopped
|
||||||
|
with dispose!."
|
||||||
[f & args]
|
[f & args]
|
||||||
{:pre [(ifn? f)]}
|
{:pre [(ifn? f)]}
|
||||||
(ratom/make-track! f args))
|
(ratom/make-track! f args))
|
||||||
|
|
||||||
(defn dispose!
|
(defn dispose!
|
||||||
|
"Stop the result of track! from updating."
|
||||||
[x]
|
[x]
|
||||||
(ratom/dispose! x))
|
(ratom/dispose! x))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue