So I have a component, and let's say when I click on it this should trigger a state change, e.g.:
:on-click #(om/set-state! this {:activated? true})
now, what If I want to "deactivate" it when clicked anywhere on the document? I guess I could just use addEventListener
by hooking it up onto the document
object, something like this:
(componentDidMount [this]
(events/listen (gdom/getDocument)
(.-CLICK events/EventType)
#(om/set-state! this {:activated? false}) true))
now this does what I want, but first of all if I have 200 instances of the same component it will have 200 event listeners, right? Which is not desirable but ok, I guess
The real question though is how do I distinguish one instance of the component from another when setting its state? I definitely don't want all of them to be "deactivated", but only the one in which context that click event handler is being triggered