Clojurians
#re-frame
<
2016-03-20
>

This page is not created by, affiliated with, or supported by Slack Technologies, Inc.

hoopes15:03:56

good morning. in a form-3 component, is :reagent-render the only thing that can subscribe to get changed data? or can any of the lifecycle methods subscribe for data? (i'm sure this belies not yet understanding the whole model)

hoopes15:03:22

and if so, is it the job of the render to set the data somewhere on this.state (so to speak), expecting the other lifecycle functions to read the data of the component state?

hoopes15:03:27

thanks very much!

hoopes16:03:46

after more reading, i added a local ratom - when render is rerun, it updates the local "state", and the lifecycle functions can pull the new data off of them - am i in the ballpark? (let [some (local but shared state) from the wiki for creating reagent components

nberger16:03:24

@hoopes yep, that's the way to go

hoopes16:03:44

awesome, thanks!

nberger16:03:13

I mean, that's_one_ way to go... You could also use a subscribe instead of the ratom, you can deref it in the lifecycle methods too

nberger16:03:08

The difference is just local vs app state

nberger16:03:44

Just saying this because you started asking about subscribe :)

hoopes16:03:25

i'm subscribing to app state in render

hoopes16:03:41

but it only re-renders when i actually use the data

hoopes16:03:19

that's why i was asking about subscriptions in the lifecycle functions - i can catch the change in the render function, but then to kinda "pass it off" to those other functions, i wasn't sure how to get it from render to update, for instance

hoopes16:03:04

the local ratom is updated in render, and used in did-mount and did-update

hoopes16:03:09

(does that make sense? simple_smile )

hoopes16:03:52

if i didn't have to use the subscription in render only, i could skip that step, and just use the subscribed data in the did-mount and did-update

nberger16:03:33

Oh I see. One way to accomplish this, is to have an outer and inner component. The outer has the subscribe and passes the deref'ed values to the inner component, as props, so the inner component will update every time the subscription yields new values

hoopes16:03:27

ok, and then the lifecycle functions (of that inner component) just pull the data off the props of the inner component

hoopes16:03:54

i will keep reading up - thanks so much for your time

nberger16:03:21

Exactly. No worries