cyclejs-community/redux-cycles

Getting odd behaviour when using STATE

lmatteis opened this issue · 1 comments

@goshakkk so I'm trying out your STATE extension but getting some odd behaviour: https://jsbin.com/kijucaw/6/edit?js,output

Try clicking the "odd +" button which triggers a read to the STATE stream. It doesn't work as expected and if you click it multiple times you get a Maximum call stack size exceeded error. I'll be looking into a fix for this.

I was thinking that perhaps rather than a STATE stream we could do it the way redux-observable does: pass in the store reference down the ACTION stream somehow, so we can call store.getState() inside the stream composition whenever it is needed.

It's the issue with the way you use it — every action emits a full stream of STATE changes which leads to the infinite loops.

What would help is either:

  • xs/extra/sampleCombine, which I used in the readme; or
  • limiting the isOdd$ stream to 1 value so that each action would map to just 1 value of isOdd$ instead of all of them (sampleCombine does essentially the same thing)
const isOdd$ = state$
  .debug(state => console.log(state))
  .map(state => state % 2 === 1)
  .take(1);

https://jsbin.com/duzalovane/1/edit?js,output

I was thinking that perhaps rather than a STATE stream we could do it the way redux-observable does: pass in the store reference down the ACTION stream somehow, so we can call store.getState() inside the stream composition whenever it is needed.

To me, that screams anything but "reactive". Very imperative and non-deterministic, since there would be a possibility that by the time store.getState() is executed, the state has already changed and the result of the call would no longer reflect the state at the time this action has occurred.