Inspired by redux-observable but felt uncomfortable during use, why should actions come in and out? It feels uncomfortable to use like this. I don't want to trigger other actions at the end of this stream when I have time, so I modified it myself:
Sample Code#
const streamerMiddleware = createStreamMiddleware()
const store = createStore(reducers, applyMiddleware(streamerMiddleware))
streamerMiddleware.run(
combineStreamers((observable$, api) =>
observable$
.pipe(
filterAction(FetchTypes.FETCH_START),
throttleTime(500),
dispatchAction({ type: FetchTypes.SET_LOADING, payload: true }),
delay(1000),
mergeMap(() => from(fetcher().then((response) => response.json()))),
)
.subscribe({
next: (result) => {
if (result) {
api.dispatch({ type: FetchTypes.FETCH_DONE, payload: result })
}
},
error: (err) => {
console.log(err)
api.dispatch({ type: FetchTypes.FETCH_FAILED, payload: err })
},
})
),
store.dispatch
)
github: redux-observable-another