Fork me on GitHub
#re-frame
<
2016-02-22
>
leonid-shevtsov05:02:01

hey guys, I've noticed that if I pass an event object from an event handler on a component to dispatch it arrives nullified in the handler; should I expect this behavior or am I doing something wrong? I know that event nullification happens with React, but it should come after the event handler had fired.

nberger05:02:14

@leonid-shevtsov yeah, if you want to use a react event object after the event handler that received it, you have to call (.persist event). It gets recycled by the react event pooling system if you don't do that.

leonid-shevtsov05:02:05

riight, because dispatch happens asynchronously. got it, thanks!

mikethompson06:02:16

It is probably more idiomatic to extract the necessary contents from the event and send just that data along in the event, rather than the js object itself.

mikethompson06:02:59

@leonid-shevtsov: ^^ when your events are pure, simple data (rather than js objects) testing and debugging becomes a fair bit easier. IMO.

mikethompson07:02:48

Thanks for the question and answer. I've created a new FAQ entry (I have seen this question come through before): https://github.com/Day8/re-frame/wiki/FAQ#6-dispatched-events-are-null

nberger13:02:34

Agreed with you @mikethompson, simple data FTW. I should have recommended to not dispatch the react event, instead of helping in how to do it :)

martinklepsch17:02:22

Getting this very strange error with a not-so-helpful stacktrace — does it look familiar to anybody?

martinklepsch17:02:38

Was trying to do something with a dom node that didn't exist

martinklepsch17:02:04

Still that stacktrace was confusing

hugobessaa19:02:01

@martinklepsch: this stacktrace is strange because re-frame dispatches events asynchronously.

hugobessaa19:02:21

@martinklepsch: refer to https://github.com/Day8/re-frame/wiki/Debugging-Event-Handlers to undestand how you can better debug event handlers

kanwei19:02:29

@mikethompson: figured it out, (reagent/props) only works when you pass a map, not a vector, to the inner component, due to hiccup

kanwei19:02:35

blehhhhhhhhhh simple_smile

kanwei19:02:19

in which case I feel like all params should be passed as maps from component->component

mikethompson19:02:46

Either way, could you add an FAQ about this perhaps? Sounds baffling

kanwei19:02:07

no it was from my issue the other day with props not populating

kanwei19:02:12

I was doing something like

kanwei19:02:55

and (reagent/props) was return nil

kanwei19:02:24

but using

[inner-component {:data data}
, (reagent/props) returns {:data [1 2 3]}

mikethompson19:02:30

What if data was a list

kanwei19:02:52

let me try

mikethompson19:02:38

[data '(1 2 3)]

kanwei19:02:10

also returns nil

mikethompson19:02:15

I'm assuming that this works correctly: [inner-component 1 2 3 4]

kanwei19:02:49

that returns nil too

kanwei19:02:53

pretty sure only works with maps

mikethompson19:02:10

Okay, I'm slightly puzzled. But not enough time right now. Feel free to add any insights to the bottom of: https://github.com/Day8/re-frame/wiki/Using-Stateful-JS-Components