(alts! & cells)
Given a number of cells, returns a formula cell whose value is a seq of values from cells that changed in the last update. Note that multiple cells may update atomically, which is why the formula's value is a seq.
Consider:
(def a (cell {:x 1 :y 2}))
(def x (cell= (:x a)))
(def y (cell= (:y a)))
(def z (alts! x y))
then,
(deref z) ;=> (1 2)
(swap! a assoc :x 42)
(deref z) ;=> (42)
(reset! a {:x 10 :y 20})
(deref z) ;=> (10 20)
Given a number of cells, returns a formula cell whose value is a seq of values from cells that changed in the last update. Note that multiple cells may update atomically, which is why the formula's value is a seq. Consider: (def a (cell {:x 1 :y 2})) (def x (cell= (:x a))) (def y (cell= (:y a))) (def z (alts! x y)) then, (deref z) ;=> (1 2) (swap! a assoc :x 42) (deref z) ;=> (42) (reset! a {:x 10 :y 20}) (deref z) ;=> (10 20)
(bind-syms form)
Given a binding form, returns a seq of the symbols that will be bound.
(bind-syms '[{:keys [foo some.ns/bar] :as baz} baf & quux]) ;=> (foo bar baz baf quux)
Given a binding form, returns a seq of the symbols that will be bound. (bind-syms '[{:keys [foo some.ns/bar] :as baz} baf & quux]) ;=> (foo bar baz baf quux)
(cell x)
(cell x & {:keys [meta]})
Returns a new input cell containing value x. The :meta option can be used to create the cell with the given metadata map.
Returns a new input cell containing value x. The :meta option can be used to create the cell with the given metadata map.
(cell-doseq bindings & body)
Takes a vector of binding-form/collection-cell pairs and one or more body expressions, similar to clojure.core/doseq. Iterating over the collection cells produces a sequence of items that may grow, shrink, or update over time. Whenever this sequence grows the body expressions are evaluated (for side effects) exactly once for each new location in the sequence. Bindings are bound to cells that refer to the item at that location.
Consider:
(def things (cell [{:x :a} {:x :b} {:x :c}]))
(cell-doseq [{:keys [x]} things]
(prn :creating @x)
(add-watch x nil #(prn :updating %3 %4)))
;; the following is printed -- note that x is a cell:
:creating :a
:creating :b
:creating :c
Shrink things by removing the last item:
(swap! things pop)
;; the following is printed (because the 3rd item in things is now nil,
;; since things only contains 2 items) -- note that the doit function is
;; not called (or we would see a :creating message):
:updating :c nil
Grow things such that it is one item larger than it ever was:
(swap! things into [{:x :u} {:x :v}])
;; the following is printed (because things now has 4 items, so the 3rd
;; item is now {:x :u} and the max size increases by one with the new
;; item {:x :v}):
:updating nil :u
:creating :v
A weird imagination is most useful to gain full advantage of all the features.
Takes a vector of binding-form/collection-cell pairs and one or more body expressions, similar to clojure.core/doseq. Iterating over the collection cells produces a sequence of items that may grow, shrink, or update over time. Whenever this sequence grows the body expressions are evaluated (for side effects) exactly once for each new location in the sequence. Bindings are bound to cells that refer to the item at that location. Consider: (def things (cell [{:x :a} {:x :b} {:x :c}])) (cell-doseq [{:keys [x]} things] (prn :creating @x) (add-watch x nil #(prn :updating %3 %4))) ;; the following is printed -- note that x is a cell: :creating :a :creating :b :creating :c Shrink things by removing the last item: (swap! things pop) ;; the following is printed (because the 3rd item in things is now nil, ;; since things only contains 2 items) -- note that the doit function is ;; not called (or we would see a :creating message): :updating :c nil Grow things such that it is one item larger than it ever was: (swap! things into [{:x :u} {:x :v}]) ;; the following is printed (because things now has 4 items, so the 3rd ;; item is now {:x :u} and the max size increases by one with the new ;; item {:x :v}): :updating nil :u :creating :v A weird imagination is most useful to gain full advantage of all the features.
(cell-doseq* c f)
Given a function f and a cell c that contains a seqable collection of items, calls f for side effects once for each item in c, passing one argument: a formula cell equivalent to (cell= (nth c i)) for the ith item in c. Whenever c grows beyond its previous maximum size f is called as above for each item beyond the maximum size. Nothing happens when c shrinks.
See also: the javelin.core/cell-doseq macro.
Consider:
(def things (cell [:a :b :c]))
(cell-doseq*
things
(fn doit [x]
(prn :creating @x)
(add-watch x nil #(prn :updating %3 %4))))
;; the following is printed:
:creating :a
:creating :b
:creating :c
Shrink things by removing the last item:
(swap! things pop)
;; the following is printed (because the 3rd item in things is now nil,
;; since things only contains 2 items) -- note that the doit function is
;; not called (or we would see a :creating message):
:updating :c nil
Grow things such that it is one item larger than it ever was:
(swap! things into [:u :v])
;; the following is printed (because things now has 4 items, so the 3rd
;; item is now :u and the max size increases by one with the new item :v):
:updating nil :u
:creating :v
A weird imagination is most useful to gain full advantage of all the features.
Given a function f and a cell c that contains a seqable collection of items, calls f for side effects once for each item in c, passing one argument: a formula cell equivalent to (cell= (nth c i)) for the ith item in c. Whenever c grows beyond its previous maximum size f is called as above for each item beyond the maximum size. Nothing happens when c shrinks. See also: the javelin.core/cell-doseq macro. Consider: (def things (cell [:a :b :c])) (cell-doseq* things (fn doit [x] (prn :creating @x) (add-watch x nil #(prn :updating %3 %4)))) ;; the following is printed: :creating :a :creating :b :creating :c Shrink things by removing the last item: (swap! things pop) ;; the following is printed (because the 3rd item in things is now nil, ;; since things only contains 2 items) -- note that the doit function is ;; not called (or we would see a :creating message): :updating :c nil Grow things such that it is one item larger than it ever was: (swap! things into [:u :v]) ;; the following is printed (because things now has 4 items, so the 3rd ;; item is now :u and the max size increases by one with the new item :v): :updating nil :u :creating :v A weird imagination is most useful to gain full advantage of all the features.
(cell-map f c)
Given a function f and a cell c that contains a seqable collection of items, returns a seq of formula cells such that the ith formula cell is equivalent to (cell= (f (nth c i))).
Given a function f and a cell c that contains a seqable collection of items, returns a seq of formula cells such that the ith formula cell is equivalent to (cell= (f (nth c i))).
(cell? c)
Returns c if c is a Cell, nil otherwise.
Returns c if c is a Cell, nil otherwise.
(deref* x)
If x is a Cell dereferences x and returns the value, otherwise returns x.
If x is a Cell dereferences x and returns the value, otherwise returns x.
(destroy-cell! this)
(destroy-cell! this keep-watches?)
Unlinks this Cell from the cell graph and resets all internal state. Watches are preserved when keep-watches? is true, otherwise they are all removed.
Unlinks this Cell from the cell graph and resets all internal state. Watches are preserved when keep-watches? is true, otherwise they are all removed.
Select a version of #'destructure that works with the version of the CLJS compiler that is provided. Older versions of CLJS do not provide destructure so we fall back to using Clojure's destructure function in that case.
Select a version of #'destructure that works with the version of the CLJS compiler that is provided. Older versions of CLJS do not provide destructure so we fall back to using Clojure's destructure function in that case.
(dosync & body)
Evaluates the body within a Javelin transaction. Propagation of updates to formula cells is deferred until the transaction is complete. Input cells will update during the transaction. Transactions may be nested.
Evaluates the body within a Javelin transaction. Propagation of updates to formula cells is deferred until the transaction is complete. Input cells *will* update during the transaction. Transactions may be nested.
(dosync* thunk)
Calls the thunk with no arguments within a transaction. Propagation of updates to formula cells is deferred until the transaction is complete. Input cells will update during the transaction. Transactions may be nested.
See also: the javelin.core/dosync macro.
Calls the thunk with no arguments within a transaction. Propagation of updates to formula cells is deferred until the transaction is complete. Input cells *will* update during the transaction. Transactions may be nested. See also: the javelin.core/dosync macro.
(extract-syms bindings)
Extract symbols that will be bound by bindings, including autogenerated symbols produced for destructuring.
Extract symbols that will be bound by bindings, including autogenerated symbols produced for destructuring.
(extract-syms-without-autogen bindings)
Extract only the symbols that the user is binding from bindings, omitting any intermediate autogenerated bindings used for destructuring. A trick is used here taking advantage of the fact that gensym names are produced as a side effect -- successive calls to extract-syms are not redundant.
Extract only the symbols that the user is binding from bindings, omitting any intermediate autogenerated bindings used for destructuring. A trick is used here taking advantage of the fact that gensym names are produced as a side effect -- successive calls to extract-syms are not redundant.
(formula f)
(formula f updatefn)
Returns a function that returns a formula cell with f as its formula, and if updatefn is provided the returned cell is a lens.
See also: the javelin.core/cell= macro.
(def x (cell 100))
(def y (cell 200))
(def z1 (cell= (+ x y)))
(def z2 ((formula +) x y))
The formula cells z1 and z2 are equivalent.
Returns a function that returns a formula cell with f as its formula, and if updatefn is provided the returned cell is a lens. See also: the javelin.core/cell= macro. (def x (cell 100)) (def y (cell 200)) (def z1 (cell= (+ x y))) (def z2 ((formula +) x y)) The formula cells z1 and z2 are equivalent.
(formula-of deps & body)
ALPHA: this macro may change.
Given a vector of dependencies and one or more body expressions, emits a form that will produce a formula cell. The dependencies must be names that will be re-bound to their values within the body. No code walking is done. The value of the formula cell is computed by evaluating the body expressions whenever any of the dependencies change.
Note: the dependencies need not be cells.
E.g. (def x 100) (def y (cell 200)) (def z (cell= (inc y)))
(def c (formula-of [x y z] (+ x y z)))
(deref c) ;=> 501
(swap! y inc)
(deref c) ;=> 503
ALPHA: this macro may change. Given a vector of dependencies and one or more body expressions, emits a form that will produce a formula cell. The dependencies must be names that will be re-bound to their values within the body. No code walking is done. The value of the formula cell is computed by evaluating the body expressions whenever any of the dependencies change. Note: the dependencies need not be cells. E.g. (def x 100) (def y (cell 200)) (def z (cell= (inc y))) (def c (formula-of [x y z] (+ x y z))) (deref c) ;=> 501 (swap! y inc) (deref c) ;=> 503
(formulet bindings & body)
ALPHA: this macro may change.
Given a vector of binding-form/dependency pairs and one or more body expressions, emits a form that will produce a formula cell. Each binding form is bound to the value of the corresponding dependency within the body. No code walking is done. The value of the formula cell is computed by evaluating the body expressions whenever any of the dependencies change.
Note: the depdendency expressions are evaluated only once, when the formula cell is created, and they need not evaluate to javelin cells.
E.g. (def a (cell 42)) (def b (cell {:x 100 :y 200}))
(def c (formulet [v (cell= (inc a))
w (+ 1 2)
{:keys [x y]} b]
(+ v w x y)))
(deref c) ;=> 346
(swap! a inc)
(deref c) ;=> 347
ALPHA: this macro may change. Given a vector of binding-form/dependency pairs and one or more body expressions, emits a form that will produce a formula cell. Each binding form is bound to the value of the corresponding dependency within the body. No code walking is done. The value of the formula cell is computed by evaluating the body expressions whenever any of the dependencies change. Note: the depdendency expressions are evaluated only once, when the formula cell is created, and they need not evaluate to javelin cells. E.g. (def a (cell 42)) (def b (cell {:x 100 :y 200})) (def c (formulet [v (cell= (inc a)) w (+ 1 2) {:keys [x y]} b] (+ v w x y))) (deref c) ;=> 346 (swap! a inc) (deref c) ;=> 347
(lens c f)
Returns a new lens whose value is the same as c's with update function f. This is equivalent to ((formula identity f) c).
Returns a new lens whose value is the same as c's with update function f. This is equivalent to ((formula identity f) c).
This function is deprecated, please use #'javelin.core/formula instead.
This function is deprecated, please use #'javelin.core/formula instead.
(macroexpand* env form)
Expand form if it is a CLJS macro, otherwise just return form.
Expand form if it is a CLJS macro, otherwise just return form.
(macroexpand-all form)
Fully expand all CLJS macros contained in form.
Fully expand all CLJS macros contained in form.
(macroexpand-all* env form)
Fully expand all CLJS macros contained in form.
Fully expand all CLJS macros contained in form.
(mx form)
Expand all macros in form and pretty-print them (as code).
Expand all macros in form and pretty-print them (as code).
(mx2 form)
Expand all macros in form and pretty-print them (as data).
Expand all macros in form and pretty-print them (as data).
(set-cell! c x)
Converts c to an input cell in place, setting its contents to x. It's okay if c was already an input cell. Changes will be propagated to any cells that depend on c.
Converts c to an input cell in place, setting its contents to x. It's okay if c was already an input cell. Changes will be propagated to any cells that depend on c.
(set-formula! this)
(set-formula! this f)
(set-formula! this f sources)
(set-formula! this f sources updatefn)
Given a Cell and optional formula function f and the cells f depends on, sources, updates the formula for this cell in place. If f and/or sources is not spcified they are set to nil.
Given a Cell and optional formula function f and the cells f depends on, sources, updates the formula for this cell in place. If f and/or sources is not spcified they are set to nil.
(with-let [binding resource] & body)
Binds resource to binding and evaluates body. Then, returns resource. It's a cross between doto and with-open.
Binds resource to binding and evaluates body. Then, returns resource. It's a cross between doto and with-open.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close