-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Action from an http requetis fired twice #35
Comments
The problem is with the use of combine: https://github.com/staltz/xstream#-combinestream1-stream2 The second time you call the POST_REQUESTED action from react, it's gonna emit POST_RECEIVED even without a response (because combine uses the latest response). I think you may need sampleCombine instead (https://github.com/staltz/xstream/blob/master/EXTRA_DOCS.md#-samplecombinestreams) But make sure the source stream is the response. Hope it makes sense. Let me know if you can figure it out. |
Thank you very much! I'll look into it and let you know!
That makes the trick, but I will have to understand better cycle for more advanced stuff anyway. |
Yeah if you don't need the post info in the stream, then you don't need combine 😃 Anyway in case you need the post this should work: import sampleCombine from 'xstream/extra/sampleCombine'
const action$ = response$
.compose(sampleCombine(post$))
.map(([ response, post ]) => actions.receivePostById(post, response.body)) |
I have a component that at
componentDidMount
will fire an action that makes an http request.What I want is to set an
isFetching
flag in the reducer.Everything works as expected the first time I load the component, but the second the flag
isFetching
is never set totrue
.I played just a little with the middleware during this weekend so I'm not really sure why I have this problem.
This is my
main
, I just readapted the code from one of the example.And this is the reducer:
If I log what's going on with my request, I can see that
isFetching
is false at the beginning, then the actionPOST_REQUESTED
is fired andisFetching
is set to true. WhenPOST_RECEIVED
is being fired (from the cycle code)isFetching
goes back to false. That's the normal case.On the next time
POST_RECEIVED
is being fired two times for the same action andisFetching
flag is never set totrue
.You can see an online version here https://dbertella.github.io/food-and-quote/ in case.
Am I missing something?
The text was updated successfully, but these errors were encountered: