(build-defc render-body mixins display-name)
(build-defcc render-body mixins display-name)
(build-defcs render-body mixins display-name)
(cursor ref key & options)
Same as rum.core/cursor-in
but accepts single key instead of path vector
Same as `rum.core/cursor-in` but accepts single key instead of path vector
(cursor-in ref path & {:as options})
Given atom with deep nested value and path inside it, creates an atom-like structure that can be used separately from main atom, but will sync changes both ways:
(def db (atom { :users { "Ivan" { :age 30 }}})) (def ivan (rum/cursor db [:users "Ivan"])) @ivan ;; => { :age 30 } (swap! ivan update :age inc) ;; => { :age 31 } @db ;; => { :users { "Ivan" { :age 31 }}} (swap! db update-in [:users "Ivan" :age] inc) ;; => { :users { "Ivan" { :age 32 }}} @ivan ;; => { :age 32 }
Returned value supports deref, swap!, reset!, watches and metadata.
The only supported option is :meta
Given atom with deep nested value and path inside it, creates an atom-like structure that can be used separately from main atom, but will sync changes both ways: (def db (atom { :users { "Ivan" { :age 30 }}})) (def ivan (rum/cursor db [:users "Ivan"])) \@ivan ;; => { :age 30 } (swap! ivan update :age inc) ;; => { :age 31 } \@db ;; => { :users { "Ivan" { :age 31 }}} (swap! db update-in [:users "Ivan" :age] inc) ;; => { :users { "Ivan" { :age 32 }}} \@ivan ;; => { :age 32 } Returned value supports deref, swap!, reset!, watches and metadata. The only supported option is `:meta`
(defc & body)
Defc does couple of things:
(rum/defc label [t] [:div t])
;; creates React class ;; defines ctor fn (defn label [t] ...) => element
(label "text") ;; => returns React element built with label class
Usage:
(defc name doc-string? [< mixins+]? [params*] render-body+)
Defc does couple of things: 1. Wraps body into sablono/compile-html 2. Generates render function from that 3. Takes render function and mixins, builds React class from them 4. Using that class, generates constructor fn [args]->ReactElement 5. Defines top-level var with provided name and assigns ctor to it (rum/defc label [t] [:div t]) ;; creates React class ;; defines ctor fn (defn label [t] ...) => element (label "text") ;; => returns React element built with label class Usage: (defc name doc-string? [< mixins+]? [params*] render-body+)
(defcc & body)
Same as defc, but render will take additional first argument: react component
Usage:
(defcc name doc-string? [< mixins+]? [comp params*] render-body+)
Same as defc, but render will take additional first argument: react component Usage: (defcc name doc-string? [< mixins+]? [comp params*] render-body+)
(defcs & body)
Same as defc, but render will take additional first argument: state
Usage:
(defcs name doc-string? [< mixins+]? [state params*] render-body+)
Same as defc, but render will take additional first argument: state Usage: (defcs name doc-string? [< mixins+]? [state params*] render-body+)
Use this to create “chains” and acyclic graphs of dependent atoms.
derived-atom
will:
f
, passing N dereferenced values of source refsreset!
result of f
to the sink atom(def *a (atom 0)) (def *b (atom 1)) (def *x (derived-atom [*a *b] ::key (fn [a b] (str a ":" b)))) (type *x) ;; => clojure.lang.Atom @*x ;; => 0:1 (swap! *a inc) @*x ;; => 1:1 (reset! *b 7) @*x ;; => 1:7
Arguments:
refs - sequence of source refs
key - unique key to register watcher, see clojure.core/add-watch
f - function that must accept N arguments (same as number of source refs)
and return a value to be written to the sink ref.
Note: f
will be called with already dereferenced values
opts - optional. Map of:
:ref - Use this as sink ref. By default creates new atom
:check-equals? - Do an equality check on each update: (= @sink (f new-vals))
.
If result of f
is equal to the old one, do not call reset!
.
Defaults to true
. Set to false if calling =
would be expensive
Use this to create “chains” and acyclic graphs of dependent atoms. `derived-atom` will: - Take N “source” refs - Set up a watch on each of them - Create “sink” atom - When any of source refs changes: - re-run function `f`, passing N dereferenced values of source refs - `reset!` result of `f` to the sink atom - return sink atom (def *a (atom 0)) (def *b (atom 1)) (def *x (derived-atom [*a *b] ::key (fn [a b] (str a ":" b)))) (type *x) ;; => clojure.lang.Atom \@*x ;; => 0:1 (swap! *a inc) \@*x ;; => 1:1 (reset! *b 7) \@*x ;; => 1:7 Arguments: refs - sequence of source refs key - unique key to register watcher, see `clojure.core/add-watch` f - function that must accept N arguments (same as number of source refs) and return a value to be written to the sink ref. Note: `f` will be called with already dereferenced values opts - optional. Map of: :ref - Use this as sink ref. By default creates new atom :check-equals? - Do an equality check on each update: `(= @sink (f new-vals))`. If result of `f` is equal to the old one, do not call `reset!`. Defaults to `true`. Set to false if calling `=` would be expensive
(dom-node s)
(dom-node state)
Given state, returns top-level DOM node. Can’t be called during render
Given state, returns top-level DOM node. Can’t be called during render
(local initial)
(local initial key)
Mixin constructor. Adds an atom to component’s state that can be used to keep stuff
during component’s lifecycle. Component will be re-rendered if atom’s value changes.
Atom is stored under user-provided key or under :rum/local
by default
Mixin constructor. Adds an atom to component’s state that can be used to keep stuff during component’s lifecycle. Component will be re-rendered if atom’s value changes. Atom is stored under user-provided key or under `:rum/local` by default
(mount c n)
(mount component node)
Add component to the DOM tree. Idempotent. Subsequent mounts will just update component
Add component to the DOM tree. Idempotent. Subsequent mounts will just update component
(react ref)
Works in conjunction with rum.core/reactive
mixin. Use this function instead of
deref
inside render, and your component will subscribe to changes happening
to the derefed atom.
Works in conjunction with `rum.core/reactive` mixin. Use this function instead of `deref` inside render, and your component will subscribe to changes happening to the derefed atom.
Mixin. Works in conjunction with rum.core/react
Mixin. Works in conjunction with `rum.core/react`
(ref s k)
(ref state key)
Given state and ref handle, returns React component
Given state and ref handle, returns React component
(ref-node s k)
(ref-node state key)
Given state and ref handle, returns DOM node associated with ref
Given state and ref handle, returns DOM node associated with ref
Main server-side rendering method. Given component, returns HTML string with
static markup of that component. Serve that string to the browser and
rum.core/mount
same Rum component over it. React will be able to reuse already
existing DOM and will initialize much faster
Main server-side rendering method. Given component, returns HTML string with static markup of that component. Serve that string to the browser and `rum.core/mount` same Rum component over it. React will be able to reuse already existing DOM and will initialize much faster
Same as rum.core/render-html
but returned string has nothing React-specific.
This allows Rum to be used as traditional server-side template engine
Same as `rum.core/render-html` but returned string has nothing React-specific. This allows Rum to be used as traditional server-side template engine
(request-render c)
(request-render component)
Schedules react component to be rendered on next animation frame
Schedules react component to be rendered on next animation frame
(state c)
(state comp)
Given React component, returns Rum state associated with it
Given React component, returns Rum state associated with it
Mixin. Will avoid re-render if none of component’s arguments have changed. Does equality check (=) on all arguments
Mixin. Will avoid re-render if none of component’s arguments have changed. Does equality check (=) on all arguments
(unmount c)
(unmount node)
Removes component from the DOM tree
Removes component from the DOM tree
(with-key element key)
(with-key component key)
Adds React key to component
Adds React key to component
(with-ref element ref)
(with-ref component ref)
Adds React ref (string or callback) to component
Adds React ref (string or callback) to component
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close