workflo.macros.view
anonymous-fn
(anonymous-fn {:keys [form-args form-body]})
Make a function f anonymous by replacing its name with fn.
bind-commands
(bind-commands {:keys [form-body form-args], :as f} command-fns)
Wraps the body of a function in a let that makes the view commands available to the body via their names.
bind-query-result
(bind-query-result {:keys [form-body form-args], :as f} props-query computed-query)
Wraps the body of a function, binding the values in props and computed props to the names used in the view query and computed query.
commands-form?
(commands-form? {:keys [form-name]})
Returns true if the input form is a declaration of view commands.
defview
macro
(defview name & forms)
Create a new view with the given name.
Takes an optional query, an optional computed properties “query” and an arbitrary number of Om Next component functions (such as ident
, query
, query-params
, initLocalState
or render
) and JavaScript object methods, without requiring their protocols or argument bindings (like [this]
or [props]
) to be included in the definition.
defview
will wrap the function bodies of all instance functions (ident
, render
, lifecycle functions, any object methods) so that the values in the query result and in computed properties are bound to the names appearing in the queries.
Usage:
(defview User
[name email address [street city zipcode]]
[clicked-fn]
(key name)
(validate ...)
(ident [:user/by-name name])
(render
(html
[:div.user {:onClick clicked-fn}
[:h2 name "(" email ")"]
[:ul.address
[:li street]
[:li city]
[:li zipcode]]])))
The above example would define the following:
- an Om Next component called
User
, - a component factory called
user
, with a:keyfn
, derived from(key ...)
, and a:validator
, derived from(validate ...)
.
If the query includes [db [id]]
, corresponding to the Om Next query attribute :db/id
, it is assumed that the view represents data from DataScript or Datomic. In this case, defview
will automatically infer (ident ...)
and (key ...)
functions based on the database ID. This behavior can be overriden by specifically defining both, ident
and key
.
fn-alias
(fn-alias {:keys [form-name]})
Return the alias for a view function or the name of the function itself if no alias is defined.
fn-aliases
A few aliases allowing to define view functions with shorter or more logicial names.
fn-args
(fn-args {:keys [form-name]})
Return the arguments (e.g. [this]) for a view function.
fn-protocol
(fn-protocol {:keys [form-name]})
Return the scope (e.g. (static om.next/IQuery) for a view function.
fn-scope
(fn-scope {:keys [form-name]})
Return the scope (:static, :instance, :props) for a view function.
fn-specs
Function specifications for all functions that are not Object instance functions taking [this] as the sole argument.
generate-command-fn
(generate-command-fn cmd-name)
Generate an anonymous wrapper function to call the :run-command
hook with a specific command name.
generate-ident-fn
(generate-ident-fn props)
Generate a (ident …) function from the props spec.
inject-fn-args
(inject-fn-args f)
Inject a function argument binding vector into f if it doesn’t already have one.
instance-fn
(instance-fn {:keys [form-name form-args form-body]})
Make a function to put inside a record or defui expression.
maybe-generate-ident-fn
(maybe-generate-ident-fn props fns)
If the props spec includes a :db/id property, an (ident …) function is automatically generated based on this ID.
maybe-generate-key-fn
(maybe-generate-key-fn props fns)
If the props spec includes a :db/id property, a (key …) function is automatically generated based on this ID.
maybe-inject-fn-args
(maybe-inject-fn-args f)
Inject a function argument binding vector into f unless it is a raw function that is assumed to define its own arguments.
maybe-wrap-render
(maybe-wrap-render {:keys [form-name form-body], :as f})
If f is the render function, checks whether it has more than one child expression. If so, wraps these children in a wrapper view according to the :wrapper-view option set via workflo.macros.view/configure!.
normalize-fn-name
(normalize-fn-name {:keys [form-name], :as f})
Normalize the function name of f. This removes the leading . from the names of raw functions.
raw-fn?
(raw-fn? {:keys [form-name]})
Returns true if f is a raw function, that is if its name starts with a ., indicating that its function signature should be left alone.
wrap-render
(wrap-render {:keys [form-body], :as f})
Wraps the body of the function f in a wrapper view according to the :wrapper-view option set via workflo.macros.view/configure!.