2016-08-29 13:06:41 +00:00
|
|
|
### Question
|
2016-08-29 12:57:35 +00:00
|
|
|
|
|
|
|
If I `dispatch` a js event object (from a view), it is nullified
|
|
|
|
by the time it gets to the event-handler. What gives?
|
|
|
|
|
2016-08-29 13:06:41 +00:00
|
|
|
### Answer
|
2016-08-29 12:57:35 +00:00
|
|
|
|
|
|
|
So there's two things to say about this:
|
|
|
|
- if you want to `dispatch` a js event object to a re-frame
|
|
|
|
event handler, you must call `(.persist event)` before the `dispatch`.
|
|
|
|
React recycles events (using a pool), and re-frame event handlers
|
|
|
|
run async. [Find out more here](https://facebook.github.io/react/docs/events.html)
|
|
|
|
|
|
|
|
- it is probably more idiomatic to extract the salient data from the event
|
|
|
|
and `dispatch` that, rather than the js event object itself. When you
|
|
|
|
`dispatch` pure, simple cljs data (ie. rather than js objects) testing
|
|
|
|
and debugging will become easier.
|
2016-08-29 13:06:41 +00:00
|
|
|
|
|
|
|
|
2016-11-06 20:12:24 +00:00
|
|
|
***
|
|
|
|
|
2016-08-29 13:06:41 +00:00
|
|
|
Up: [FAQ Index](README.md)
|
2016-12-18 12:42:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
|
|
|
|
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
|
|
|
|
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
|