redux-observable-action

灵感来自 redux-observable 但是使用过程中感觉很不爽，为什么要 action 入 action 出呢？这样用起来感觉很不爽呀，有时间我并不想在这个流的末端再触发别的 action 了，于是便自己魔改了一版：

示例代码

Copy
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