compassus.core
application
(application {:keys [routes index-route mixins reconciler], :as opts})
Construct a Compassus application from a configuration map.
Required parameters:
:routes - a map of route handler (keyword or ident) to the Om Next
component that knows how to present that route. The
`:index-route` key in the application's configuration
must be used to define the application's starting route.
Example: {:index Index
:about About}
:index-route - a keyword or ident denoting the initial application route.
Its value must be a key in the `:routes` map.
:reconciler - an Om Next reconciler. Note the parser must be constructed
with `compassus.core/parser`.
Optional parameters:
:mixins - a vector of mixins that hook into the generated Compassus
root component's functionality in order to extend its
capabilities or change its behavior. The currently built-in
mixin constructors are:
- `compassus.core/wrap-render`
- `compassus.core/will-mount`
- `compassus.core/did-mount`
- `compassus.core/will-unmount`
Refer to the specific documentation of those functions
for more information.
application?
(application? x)
Returns true if x is a Compassus application
compassus-merge
(compassus-merge reconciler state res query)
Helper function to replace `om.next/default-merge`. Unwraps the current route
from the remote response and merges that into the state instead.
current-route
(current-route x)
Returns the current application route. x might be the application,
the reconciler or a component instance.
did-mount
(did-mount f)
Constructs a mixin that will hook into the `componentDidMount` lifecycle
method of the generated root component. Takes a function which will receive
the component as argument. Useful to perform any setup after the Compassus
application mounts.
Example: (compassus.core/did-mount
(fn [self]
(start-analytics!)))
get-reconciler
(get-reconciler app)
Returns the Om Next reconciler for the given Compassus application.
mount!
(mount! app target)
Given a Compassus application and a target root DOM node, mount the
application. Analogous to `om.next/add-root!`.
parser
(parser {:keys [route-dispatch], :or {route-dispatch true}, :as opts})
Create a Om Next parser from a configuration map. Possible options include:
:read - the read function passed to the Om Next parser.
:mutate - the mutate function passed to the Om Next parser.
:route-dispatch - boolean indicating whether the parser should dispatch on
the current route. If set to `false`, dispatches on all the
keys in the query of the component pertaining to the current
route. Defaults to `true`.
root-class
(root-class app)
Returns the application's root class.
set-route!
(set-route! x next-route)
(set-route! x next-route {:keys [queue? params tx], :or {queue? true}})
Given a reconciler, Compassus application or component, update the application's
route. `next-route` may be a keyword or an ident. Takes an optional third
options argument, a map with the following supported options:
:queue? - boolean indicating if the application root should be queued for
re-render. Defaults to true.
:params - map of parameters that will be merged into the application state.
:tx - transaction(s) (e.g.: `'(do/it!)` or `'[(do/this!) (do/that!)]`)
that will be run after the mutation that changes the route. Can be
used to perform additional setup for a given route (such as setting
the route's parameters).
will-mount
(will-mount f)
Constructs a mixin that will hook into the `componentWillMount` lifecycle
method of the generated root component. Takes a function which will receive
the component as argument. Useful to perform any setup before the Compassus
application mounts.
Example: (compassus.core/will-mount
(fn [self]
;; sets a property in the state of the root component
(om/set-state! self {:foo 42})))
will-unmount
(will-unmount f)
Constructs a mixin that will hook into the `componentWillUnmount` lifecycle
method of the generated root component. Takes a function which will receive
the component as argument. Useful to perform any cleanup after the Compassus
application unmounts.
Example: (compassus.core/will-unmount
(fn [self]
(stop-analytics!)))
wrap-render
(wrap-render wrapper)
Constructs a mixin that will wrap all the routes in the application. Useful
for applications that have a common layout for every route.
Takes a function or an Om Next component factory, which will be passed a map
with the following keys (props in the case of a component factory):
:owner - the parent component instance
:factory - the component factory for the current route
:props - the props for the current route.
Example: (compassus.core/wrap-render
(fn [{:keys [owner factory props]}]
(dom/div nil
(dom/h1 nil "App title")
(factory props))))