It's fine to pass in one or more of the build options. They exist to be
used if you need them and each have a different purpose:

:init-state is for initialising a components local state. It can be changed
by the component during its lifecycle, but this allows a parent component
to set the initial value. :init-state also overrides the values set by
om/IInitState, so its useful to set defaults in  IInitState and override
them with :init-state if needed. :init-state is set before IWillMount and
then never again (unless you unmount/remount or mount a new instance).
:state is different because it sets the state on every render. This means
that it always overrides the state even if you set it internally. This is
the most common way for the parent component to pass dynamic data to a
child component outside of the cursor.
:opts is for purely static data. I've used it and seen it used to store
configuration constants, core.async channels, labels and other constant
data that will never change.

The app state cursor can often be used in ways that remove the need for
state and init-state, but I like to separate application domain data from
transient component-only data. The rule of thumb I work with is that domain
data is stuff I would be getting from the server and maybe storing in the
database - WHAT I am rendering - and component local state is temporary
state information about HOW I am rendering the domain data. Others may have
different conventions or tastes as to what to store where or if local state
is even needed at all, especially now with ref cursors.


On Fri Dec 12 2014 at 11:42:02 AM Andrew <[email protected]> wrote:

> Thanks Daniel. By the way, would it be considered acceptable to pass a map
> to build or build-all that contains both :state and :init-state, maybe
> :opts as well? Or it is more idiomatic to use just one of these in your
> build function. As there may be data that will change, and data that will
> not, and it makes sense to keep the non-changing stuff out of the :state
> map.
>
> --
> Note that posts from new members are moderated - please be patient with
> your first post.
> ---
> You received this message because you are subscribed to the Google Groups
> "ClojureScript" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/clojurescript.
>

-- 
Note that posts from new members are moderated - please be patient with your 
first post.
--- 
You received this message because you are subscribed to the Google Groups 
"ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/clojurescript.

Reply via email to