Working with Sources and converting to Source.
Source is the main abstraction in ripley that provides a way to listen for new changes in a live value.
Source can be anything that has a value and a way to get changes.
Working with Sources and converting to Source. Source is the main abstraction in ripley that provides a way to listen for new changes in a live value. Source can be anything that has a value and a way to get changes.
(c= form)
Short hand form for creating computed sources. Takes form to compute. Symbols beginning with % refer to input sources taken from environment.
Example: ;; Computed source that has two sources: a and b ;; and calculates (* a b) whenever either input ;; source changes. (c= (* %a %b))
Short hand form for creating computed sources. Takes form to compute. Symbols beginning with % refer to input sources taken from environment. Example: ;; Computed source that has two sources: a and b ;; and calculates (* a b) whenever either input ;; source changes. (c= (* %a %b))
(computed f & sources)
Returns new source whose value is computed from the value of one or more other sources.
sources are the sources to listen for changes. Calls ripley.live.source/source on all input sources so anything that can be converted into a source with ripley.live.source/to-source can be used as input.
f is the function to call with the source values. If any of the sources changes, the function will be called. The function must have an arity that has the same amount of parameters as there are input sources. The function must be pure and non blocking.
(computed + a b) will return a new source that calls + on the values of a and b sources when either one changes.
Returns new source whose value is computed from the value of one or more other sources. sources are the sources to listen for changes. Calls ripley.live.source/source on all input sources so anything that can be converted into a source with ripley.live.source/to-source can be used as input. f is the function to call with the source values. If any of the sources changes, the function will be called. The function must have an arity that has the same amount of parameters as there are input sources. The function must be pure and non blocking. (computed + a b) will return a new source that calls + on the values of a and b sources when either one changes.
(future-source d)
(future-source d initial-value)
Source for future or promise. Optionally initial-state can be specified and that will be returned as the source value until the future computation is done.
Source for future or promise. Optionally initial-state can be specified and that will be returned as the source value until the future computation is done.
(listen-with-previous! source listener)
Utility for listening to a source while tracking the previous value as well.
The given listener function is called with both the previous and the current values:
(listener prev-value curr-value)
Utility for listening to a source while tracking the previous value as well. The given listener function is called with both the previous and the current values: (listener prev-value curr-value)
(source x)
If x is a source, return it. Otherwise try to create a source from it.
If x is a source, return it. Otherwise try to create a source from it.
(source-with-listeners current-value-fn)
(source-with-listeners current-value-fn cleanup-fn)
Create new source that tracks listeners in a new atom. Returns vector of [source listeners-atom has-listener-promise].
Calling ripley.live.protocols/write! on this source will send the written value to all currently registered listeners.
Meant for implementing new sources.
Create new source that tracks listeners in a new atom. Returns vector of [source listeners-atom has-listener-promise]. Calling ripley.live.protocols/write! on this source will send the written value to all currently registered listeners. Meant for implementing new sources.
(split parent-source & keysets)
Split a source into multiple subsources based on keysets. Returns a vector of subsources in the same order as the keysets.
This can be used to get more granular updates.
The split sources will update only when the keys selected by it are changed in the parent source. The value of the parent source should be a map.
Split a source into multiple subsources based on keysets. Returns a vector of subsources in the same order as the keysets. This can be used to get more granular updates. The split sources will update only when the keys selected by it are changed in the parent source. The value of the parent source should be a map.
(split-key parent-source key)
Like split
but returns source that takes a single key from parent source.
Like [[split]] but returns source that takes a single key from parent source.
(static data)
Source that does not change. It just holds the given data.
Source that does not change. It just holds the given data.
(use-state initial-value)
Create a source for local (per page render) state.
Returns a vector of [value-source set-state! update-state!] where
the value-source is a source that can be used to read/listen
to the value of the state and set-state! is a callback
for setting the new state. The last update-state! callback
is for applying an update to the current value (like swap!
)
This is meant to be used similar to hooks in some frontend frameworks.
Create a source for local (per page render) state. Returns a vector of [value-source set-state! update-state!] where the value-source is a source that can be used to read/listen to the value of the state and set-state! is a callback for setting the new state. The last update-state! callback is for applying an update to the current value (like `swap!`) This is meant to be used similar to hooks in some frontend frameworks.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close