(cache data)
(cache data {:keys [tag display type] :as metadata :or {type :atom}})
creates a cache with the following properties
(-> (cache {} {:tag "stuff" :type :ref}) (.state)) => clojure.lang.Ref
(str (cache {:a 1 :b 2} {:type :agent})) => "#cache:agent{:a 1, :b 2}"
creates a cache with the following properties (-> (cache {} {:tag "stuff" :type :ref}) (.state)) => clojure.lang.Ref (str (cache {:a 1 :b 2} {:type :agent})) => "#cache:agent{:a 1, :b 2}"
(clone obj)
(clone obj opts)
clones the state object
(-> (state/container :volatile) (state/create 2) (state/clone)) => volatile?
clones the state object (-> (state/container :volatile) (state/create 2) (state/clone)) => volatile?
(copy source sink)
(copy source sink opts)
copies the value of one state to another
(def -a- (ref nil)) (state/copy (atom 1) -a-) @-a- => 1
copies the value of one state to another (def -a- (ref nil)) (state/copy (atom 1) -a-) @-a- => 1
(create class data)
(create class data opts)
creates a state of a particular type
((juxt deref type) (state/create clojure.lang.Atom 1)) => [1 clojure.lang.Atom]
creates a state of a particular type ((juxt deref type) (state/create clojure.lang.Atom 1)) => [1 clojure.lang.Atom]
(cursor ref selector)
(cursor ref selector key)
adds a cursor to the atom to update on any change
(def a (atom {:a {:b 1}}))
(def ca (cursor a [:a :b]))
(do (swap! ca + 10) (swap! a update-in [:a :b] + 100) [(deref a) (deref ca)]) => [{:a {:b 111}} 111]
adds a cursor to the atom to update on any change (def a (atom {:a {:b 1}})) (def ca (cursor a [:a :b])) (do (swap! ca + 10) (swap! a update-in [:a :b] + 100) [(deref a) (deref ca)]) => [{:a {:b 111}} 111]
(defcache name & [doc? attrs? [type metadata :as opts?]])
defines a cache
(defcache -a-) (.state -a-) => clojure.lang.Atom
(defcache -b- [:volatile {:tag "hello"}]) (.state -b-) => volatile?
defines a cache (defcache -a-) (.state -a-) => clojure.lang.Atom (defcache -b- [:volatile {:tag "hello"}]) (.state -b-) => volatile?
(derived atoms f)
(derived atoms f key)
constructs an atom derived from other atoms
(def a (atom 1)) (def b (atom 10)) (def c (derived [a b] +))
(do (swap! a + 1) (swap! b + 10) [@a @b @c]) => [2 20 22]
constructs an atom derived from other atoms (def a (atom 1)) (def b (atom 10)) (def c (derived [a b] +)) (do (swap! a + 1) (swap! b + 10) [@a @b @c]) => [2 20 22]
(empty obj)
(empty obj opts)
empties the state, extensible through the IStateSet protocol (let [a (atom 1)] (state/empty a) @a) => nil
empties the state, extensible through the IStateSet protocol (let [a (atom 1)] (state/empty a) @a) => nil
(get obj)
(get obj opts)
Like deref but is extensible through the IStateGet protocol
(state/get (atom 1)) => 1
(state/get (ref 1)) => 1
Like deref but is extensible through the IStateGet protocol (state/get (atom 1)) => 1 (state/get (ref 1)) => 1
(set obj v)
(set obj v opts)
Like reset! but is extensible through the IStateSet protocol
(let [a (atom nil)] (state/set a 1) @a) => 1
Like reset! but is extensible through the IStateSet protocol (let [a (atom nil)] (state/set a 1) @a) => 1
(update obj f)
(update obj f & args)
Like swap! but is extensible through the IStateSet protocol
(let [a (atom 0)] (state/update a + 1) @a) => 1
Like swap! but is extensible through the IStateSet protocol (let [a (atom 0)] (state/update a + 1) @a) => 1
(update-apply obj f args)
(update-apply obj f args opts)
Like swap! but is extensible through the IStateSet protocol
(let [a (atom 0)] (state/update-apply a + [1 2 3]) @a) => 6
Like swap! but is extensible through the IStateSet protocol (let [a (atom 0)] (state/update-apply a + [1 2 3]) @a) => 6
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close