Open crobinson42 opened 6 years ago
@crobinson42 AFAIK you can call effects at any point and they will modify the state as expected, so you should be able to subscribe to your Firebase events in your component's initialize
and call effects.updateFromServer()
(or however your call yours) with the new data.
Thanks! I see that's the solution for using freactal inside the component context. I'm looking for a solution to affect state from outside a react component context.
On Feb 16, 2018 3:09 PM, "Aleksey Gurtovoy" notifications@github.com wrote:
@crobinson42 https://github.com/crobinson42 AFAIK you can call effects at any point and they will modify the state as expected, so you should be able to subscribe to your Firebase events in your component's initialize and call effects.updateFromServer() (or however your call yours) with the new data.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/FormidableLabs/freactal/issues/97#issuecomment-366384868, or mute the thread https://github.com/notifications/unsubscribe-auth/AFsmS8ATCHpSmZWhccJ0WEJr2x10qu7zks5tVgqxgaJpZM4R_I9f .
the initialize event has access to the event registry; you could externalize the events into any context you want and call them whenever. (and/or do AJAX stuff there).
I'm assuming that you're happy with the react system on which state has been imposed still being where you SEE the effects.
@bingomanatee Thx, I'll check that out.
I'm assuming that you're happy with the react system on which state has been imposed still being where you SEE the effects.
Not sure what you're assumption is related to or based on... care to share the relevance to problem?
its easy to export the triggers (effects) but the expression of the result (state) will still be scoped to wherever you bind the state machine. so as long as you're cool with that you should be fine.
Going to close this as resolved.
Aside from what has already been mentioned, you could kick off an effect on componentDidMount
, setup your listener there, and it'll have access to any effects you may want to invoke. Of course, you'll want to disable the listener on componentWillUnmount
.
The benefit with this approach is the ability to subscribe to Firebase changes only when the component is mounted, which is often the behavior you'll want anyway.
Hope that helps. Please re-open if you have any further issues with this.
I have a case where Firebase events are emitted asynchronously and new data needs to be injected into the state at any time.
With the exception of being jenky and using
wrapComponentWithState()
to inject new state, nothing jumps out right away.In Redux parlance, you can do this in your app when it mounts to invoke "actions" at anytime to effect the state:
How would one go about this use case? Thanks! Awesome project, btw!