I am trying to grasp the purpose of the two OM functions get-state and get-props. Have a look at the following example:
(defn example [app owner]
(reify
om/IInitState
(render-state [this state]
(println "app-state: " app )
(println "state: " state )
(println "get-props: " (om/get-props owner) )
(println "get-state: " (om/get-state owner) )
(dom/div nil "hello"))))
You will notice that app
and state
contain exactly what get-props
and get-state
return, which seems at the first glance pretty redundant.
Now, not all the lifecycle functions (e.g. IWillMount
) pass the state
argument, so when you need it in such circumstances, it's obvious that you need to invoke om/get-state
to get access to it.
However, for the app-state it looks different to me. You always have the app-state cursor available in all functions since it's a top-level argument of the function, even if you need it in callbacks you can just pass it around. Most examples/tutorials make use of get-state
but I can't find an example of get-props
. Is get-props redundant? Where would I use it?
And one more thing related to this construct. In React we have props and state, but in OM we have app-state and state (internal state) which confused me when learning OM. Props are passed from parent to child in React, likewise in OM we pass app-state (cursors) to children. Are the following observations valid?
- app-state is the OM equivalent of React' props
- props is React is just data, while app-state in OM is data wrapped in cursors
- this means that OM doesn't have props, only app-state cursors, hence the function
get-props
really meansget-app-state