Closed niki4810 closed 7 years ago
Same issue here. o/
This is definitely a bug. Thank you for the awesome repro. I'm on it!
Just wanted to confirm I've come across this bug recently as well.
It's happening because line 33 of provide.js is calling this.effects.initialize if it's present, but it's necessarily present in all children components.
An easier fix than the one proposed by @niki4810 is to overwrite effects.initialize in the child component, so when it's called, the parent's async call isn't fired.
Overwriting w/ a simple initializer: update({}) does the trick
Here's a PR that explicitly excludes a parent's initialize effect when setting a child component's effects.
Fixed in PR and released as v1.1.1
.
Hi @divmain,
Thanks for
freactal
I really love how it composes things. I have been playing with it for past few days and wanted your opinion on few things I've encountered. These may very well be an issue with how I am using the library.I created a simple client-side rendered app with two state container components (i.e. components wrapped with
provideState
one at main level and the second one isnested
within parent).Here is the gist with complete code: https://gist.github.com/niki4810/57f9ca785ccfe00c9789b16668e4c6a4
These are the issues I am noticing: 1) Multiple
fetch
requests which calling service fromeffects.initialize
: I am using the root containers,effects.initialize
to make anfetch
call to initialize the state data. I noticed that when I do this, this results in multiple fetch requests. I don't notice the same behavior when I remove the nested container component.effect.initialize
?injectState
call the async effect from withincomponentDidMount
function. For e.g:This solution fixes the multiple network requests issue, but not sure if this is recommended.
2) If
initialState
returns empty object, the state does not get's merged when server returns data When my root container component returns an empty object as initial state as show belowIf I later on call
effects.getItemDetails
call to my data providers (for e.g. here my service : http://output.jsbin.com/nuxodel.json), the state does not get merged correctly. Am I doing something wrong ?Please let me know if you need further code samples. Looking forward for you feedback.
Thanks, Nikhilesh