cyclejs-community / redux-cycles

Bring functional reactive programming to Redux using Cycle.js
MIT License
745 stars 30 forks source link

Getting odd behaviour when using STATE #3

Closed lmatteis closed 7 years ago

lmatteis commented 7 years ago

@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.

goshacmd commented 7 years ago

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:

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.