On Tuesday, July 14, 2015 at 4:51:15 AM UTC-5, Asher Coren wrote:
> Hello,
> Sometimes, when building components, they depend on internal logic that the 
> entire app doesn't care about. For example: A toggle button that toggles 
> display between two fields from the app-state. The status of the toggle 
> (which of the fields is displayed) is only the concern of the toggle 
> component.
> I know it is possible to store this local state in the local state of the 
> component, but is there a way to add it to the cursor of the component 
> without changing the app-state?

I'm not an expert in Om, but I think this (toggle field state) is the perfect 
example of what to store in the local components state and not in your 
application state.  I suppose if you REALLY wanted to you could store this in 
your app-state and just mutate a :selected-field...i.e. 

(defonce app-state (atom {:selected-field :first-field))

(om/update! cursor :selected-field :first-field)
or
(om/update! cursor :selected-field :second-field)

In the render function, you can select what field is visible via display helper 
function:
(dom/input #js {:style (display cursor :first-field} "Field #1")
(dom/input #js {:style (display cursor :second-field} "Field #2")

(defn display [cursor field]
  (if (= (:selected-field cursor) field) 
    #js {}
    #js {display: "none"}))

I think this would work...is this what you were thinking?
Tyler

-- 
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