Reputation: 3920
Here, it is recommended to use the following code to make an observable stream from a Redux store instead of subscribing directly to it.
function toObservable(store) {
return {
subscribe({ onNext }) {
let dispose = store.subscribe(() => onNext(store.getState()));
onNext(store.getState());
return { dispose };
}
}
}
I can't figure out how this can be integrated into Rx. How something like Observable.fromReduxStore
can be implemented using this code?.
Upvotes: 1
Views: 862
Reputation: 18663
For one there is already a library for this, but if you want to roll your own to work with RxJS. (Disclaimer: untested)
Rx.Observable.fromReduxStore = function(store) {
return Observable.create((observer) => {
let dispose = store.subscribe(() => observer.next(store.getState()));
observer.next(store.getState());
return dispose;
});
};
As a special note depending on the version you are using RxJS v4 Observer
uses onNext
while v5 it is next
.
Upvotes: 2