Add docs for track, track! and dispose!

This commit is contained in:
Dan Holmsand 2015-12-18 14:57:16 +01:00
parent 8141b08bdf
commit b4dec115b2
1 changed files with 15 additions and 0 deletions

View File

@ -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))