Closed gnimmelf closed 6 years ago
It's 2am, and I found a workaround; returning a promise from the reducer:
export function createState(reducer$, initialState$=Observable.of({})) {
const publisher$ = Observable.empty()
.merge(reducer$)
.scan((promisedState, [scope, reducer]) => {
return promisedState.then(state => {
const reduced = reducer(state[scope]);
if (reduced instanceof Promise) {
return reduced.then(resolved => ({ ...state, [scope]: resolved }));
}
else {
return Promise.resolve({ ...state, [scope]: reduced });
}
});
}, initialState$.toPromise())
.flatMap(promisedState => Observable.from(promisedState))
.publishReplay(1)
.refCount();
return publisher$;
}
Still very interested in how you would have solved it =P Cheers! /Flemming
Never mind, after 7 long nights I see how to use it as you wrote it. Love it! Cheers.
Hi again!
I didn't get the chance to continue with this last year I posted a newbie issue here, so while still at square one with both React and RxJs =(
How do you tie in the async part,
With the actions already created?
...and make it look DRY?
-What I don't understand is how the async part is tied into the reducer:
Thanks for your time!