Fork me on GitHub
#reagent
<
2016-09-10
>
rui.yang06:09:17

Hi wonder if someone could tell if the following could work or not

pesterhazy08:09:59

Why do you introduce another atom in the inner component? Don't do that

pesterhazy08:09:42

Just use model directly

pesterhazy08:09:20

Deref the ratom in all components you want to update when state changes

pesterhazy08:09:14

Don't pass the atom around, just use the global variable directly

rui.yang09:09:08

@pesterhazy it's for performance reason. in re-frame, i only want to mutate app state when user finishes input, which is on blur.

rui.yang09:09:48

looking at the re-com link in my snippet, i thought using the internal atom could work

pesterhazy09:09:17

Usually performance doing be going directly updating state with every onchange event

pesterhazy09:09:45

But if not, why don't you use the onblur event?

rui.yang09:09:57

basically on change will mutate internal atom, and on blur mutate app state

pesterhazy09:09:09

You can use a callback ref to get at the input value

rui.yang09:09:17

on blur didnt work for me

rui.yang09:09:48

basically the input wont respond to user typing if i do on blur

pesterhazy09:09:21

Have you tried using default-value instead of value?

pesterhazy09:09:43

Look up controlled components on the react docs

rui.yang09:09:16

@pesterhazy sorry, I actually don’t have much knowledge about the stuff you talked. Haven’t used react in an angle. I am using re-frame, not purely reagent. not sure if that’s the reason or not 😞 all I want is to maintain internal state for input and dispatch updating app-db on blur. If I do updating app-db on change, desktop is ok, but browser in mobile is slow.

rui.yang09:09:02

the user experience is not great on mobile.

pesterhazy09:09:53

Sure. I think it's mostly a react problem.. Re-frame doesn't actually change things compared to reagent

pesterhazy09:09:43

Remember that if the react elements remain the same after an update, the dom isn't touched

pesterhazy09:09:15

So unless pure js calculation is the problem, you should be fine with frequent state updates

rorydouglas13:09:26

@rui.yang i was answering this in the #re-frame channel - probably better not to cross-post in the future

rorydouglas13:09:18

the initial issue has to do with not using reaction, you’re setting the value of the internal m atom one time in main-page - it doesn’t change based on swap!ing model

rorydouglas13:09:50

and the code example does trigger a React warning in the DevTools console regarding value vs defaultValue as @pesterhazy points out