dispatch a js event object (from a view), it is nullified
by the time it gets to the event-handler. What gives?
:on-click (fn [event] (dispatch [:clicked event]))
If you want to
dispatch a js event object to a re-frame
event handler, you must call
(.persist event) before the
React recycles events (using a pool), and re-frame event handlers
run async. Find out more here
It is better to extract the salient details from the event
dispatch them, rather than the entire js event object. When you
dispatch pure, simple ClojureScript data (ie. rather than js objects) testing
and debugging will be easier.
To put this point even more strongly again, think about it like this:
- a DOM
callbackmight tell us "a button was clicked"
- our application must then interpret that click. The click means the user wanted to achieve something. They had "intent".
- it is this "intent" which should be captured in the re-frame
eventwhich is dispatched. It is this intent which the event handler must later facilitate.
So, in summary, re-frame view functions should transform DOM events
events which capture user intent: "a button was clicked"
user wants to delete item with id 42
As a result, philosophically, low-level DOM objects have no place in an event.