membrane.component
defeffect
macro
(defeffect type args & body)Define an effect.
defeffect is a macro that does 3 things:
- It registers a global effect handler of type.typeshould be a keyword and since it is registered globally, should be namespaced
- It will define a var in the current namespace of effect-*type*where type is the name of the type keyword. This can be useful if you want to be able to use your effect functions in isolation
- It will implicitly add an additional argument as the first parameter named dispatch
The arglist for dispatch! is [type & args]. Calling dispatch! will invoke the effect of type with args.
The role of dispatch! is to allow effects to define themselves in terms of other effects. Effects should not be called directly because while the default for an application is to use all the globally defined effects, this can be overridden for testing, development, or otherwise.
example:
(defeffect ::increment-number $num (dispatch! :update $num inc))
defui
macro
(defui ui-name & fdecl)Define a component.
The arguments for a component must take the form (defui my-component [ & {:keys arg1 arg2 ...}])
make-app
(make-app ui-var)(make-app ui-var initial-state)(make-app ui-var initial-state handler)ui-var The var for a component
initial-state The initial state of the component to run or an atom that contains the initial state.
handler The effect handler for your UI. The handler will be called with all effects returned by the event handlers of your ui.
If handler is nil or an arity that doesn't specify handler is used, then a default handler using all of the globally defined effects from defeffect will be used. In addition to the globally defined effects the handler will provide 3 additional effects:
:update similar to update except instead of a keypath, takes a more generic path.
example: [:update $ref inc]
:set sets the value given a $path
example: [:set $ref val]
:delete deletes value at $path
example: [:delete $ref]
make-app returns a view function.
path-replace
(path-replace form)(path-replace form deps)Given a form, walk and replace all $syms with the lens (or path) for the sym with the same name.
reset-component-cache!
(reset-component-cache!)For debugging purposes only. Ideally, should never be necessary.
top-level-ui
(top-level-ui {:keys [state body path-keys val-key-fns handler extra context]})