I'm getting started with om and ClojureScript with a very simple application.
My global app-state looks like this:
(def app-state (atom {:animals [ {:name "dog" :img "pic01.jpg"}
{:name "cat" :img "pic02.jpg"}
{:name "mouse" :img "pic03.jpg"}
{:name "camel" :img "pic04.jpg"}]}))
The name property of each hash-map inside the vector "animals" is rendered to a HTML list structure (i.g. LI-tag) by an om component that I called "menu". Each entry is rendered by another component called "entry". (i.g. as UL element). Whenever the user hovers one of the list entries the appearance of the entry changes (maybe the background changes). I capture these current states inside the entry component, which I initialize via om/IInitState.
This works so far. Now I want to add another component, which is called "display". It should be capable to display the images which are associated to the animal names in the global state whenever the user clicks on an entry in the list. I'm asking myself what would be the best way to solve this.
I see two possibilities:
Keeping a local state in the "display" component, which is updated by an onClick event from the "entry" component. Here, my question would be: How can I update an component's state from another component?
Or introducing another property in the global state, maybe called: "active_section", which is updated by the onClick event in the entry component and read by the "display" component. But is that necessary?