-
-
Notifications
You must be signed in to change notification settings - Fork 15.3k
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
Custom Observables still use old snapshots. #3404
Comments
Why aren't you using the built-in |
Honestly, because I was aware of the functionality! I didn't see it in the docs, but I now see it in the code for the store. Thanks! |
I am now using the built-in import { Observable, from } from 'rxjs';
import { createStore } from 'redux';
import { pairwise, filter, map } from 'rxjs/operators';
import $$observable from 'symbol-observable';
// redux store
const reducer = (state, { type, data }) => (
(type === 'CHANGE_DATA') ? { data } : state
);
const store = createStore(reducer, { data: 'a' });
// create the observable of the state
const state$ = Observable.create(store[$$observable]().subscribe);
const uniqueState$ = state$.pipe(
pairwise(),
filter(statePair => statePair[0].data !== statePair[1].data),
map(statePair => statePair[1]),
);
// test
uniqueState$.subscribe((state) =>{
console.log(state);
store.dispatch({ type: 'NO_CHANGE_DATA' });
});
store.dispatch({ type: 'CHANGE_DATA', data: 'b' })); We see that state$.pipe(
pairwise(),
filter(statePair => {
console.log(statePair);
return statePair[0].data !== statePair[1].data;
}),
map(statePair => statePair[1]),
) allows me to see that the pair is consistently In short, I expect that |
Might be a bug inside import { Observable } from "rxjs"; // version 6.5.1
import { pairwise, filter, map, tap, take } from "rxjs/operators";
import { EventEmitter } from "events";
const emitter = new EventEmitter();
const state$ = Observable.create(observer => {
observer.next({ data: "a" });
emitter.on("action", data => {
observer.next({ data });
});
});
const uniqueState$ = state$.pipe(
tap(state => console.log("tap1:", state)),
pairwise(),
tap(statePair => console.log("tap2:", statePair)),
filter(statePair => statePair[0].data !== statePair[1].data),
map(statePair => statePair[1]),
take(4)
);
// test
uniqueState$.subscribe(state => {
console.log(state);
emitter.emit("action", "b");
});
emitter.emit("action", "b"); Output: tap1: { data: 'a' }
tap1: { data: 'b' }
tap2: [ { data: 'a' }, { data: 'b' } ]
{ data: 'b' }
tap1: { data: 'b' }
tap2: [ { data: 'a' }, { data: 'b' } ]
{ data: 'b' }
tap1: { data: 'b' }
tap2: [ { data: 'a' }, { data: 'b' } ]
{ data: 'b' }
tap1: { data: 'b' }
tap2: [ { data: 'a' }, { data: 'b' } ]
{ data: 'b' }
tap1: { data: 'b' }
tap2: [ { data: 'a' }, { data: 'b' } ] |
What is the current behavior?
Im creating an Observable from the redux store, as follows.
From here, I produce a new observable, filtering out any of those where the state doesn't change
This does in fact produce the results I want when the subscriptions are nice.
To the contrary, if I put an action that doesn't change the state, I will get a
RangeError
, despite the fact that this listener is subscribed to the Observable corresponding to unique updates.What is the expected behavior?
If I am not missing something here, I believe that since the
'NO_CHANGE_DATA'
dispatch is only called in the listener for the Observable corresponding to unique updates, it should have only been dispatched once in the example above.Which versions of Redux, and which browser and OS are affected by this issue? Did this work in previous versions of Redux?
My
package.json
says that I haveredux ^4.0.1
The text was updated successfully, but these errors were encountered: