carry.core
app
(app {:keys [initial-model on-signal on-action], :as _blueprint})
Constructs an app from a blueprint map with keys:
:initial-model
- Initial model value, must be a map.:on-signal
- Signal handler. Function of args:[model signal dispatch-signal dispatch-action]
. It performs side effects, can dispatch actions and new signals. By convention, it must be able to handle:on-start
and:on-stop
signals in order to be wrappable by middleware. Read-only model atom is useful for reading actual model values in async code and to subscribe to model changes. Functiondispatch-signal
returns the result of the underlyingon-signal
call. Functiondispatch-action
always returnsnil
.:on-action
- Action handler. Pure function of args:[model action]
. Given an action and current model value, it must return the new model value.
Returns a map with keys:
:model
- An object that supportsIDeref
andIWatchable
protocols.:dispatch-signal
- Function with a single arg: a signal to be sent to an app. Returns the result of the underlyingon-signal
call.
entangle
(entangle r f)
Creates a read-only reference which automatically syncs its value with (f @r)
. Returned object supports deref
, add-watch
and remove-watch
. Arguments:
r
- source reference, it must supportderef
,add-watch
andremove-watch
(e.g. an atom or another read-only reference)f
- pure function