Closed dbertella closed 7 years ago
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! Edit I couldn't find the right way to make sampleCombine working instead, but I found out that in my case I don't need the combine at all, at least not for the single post.
const action$ = sources.HTTP
.select('post')
.flatten()
.map(res => actions.receivePostById(res.body.id, res.body));
That makes the trick, but I will have to understand better cycle for more advanced stuff anyway. Thank you again!
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 anisFetching
flag in the reducer. Everything works as expected the first time I load the component, but the second the flagisFetching
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 timePOST_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?