使用 redux-observable 中的史诗将两个动作排序在一起
Sequencing two actions together using an epic in redux-observable
我正在使用 redux-observable 使用 react-native 构建应用程序。
现在我正在努力通过使用史诗对 redux-observable 中的两个动作进行简单装饰。我想要实现的只是将两个动作映射到一个。
我得到的错误是:
You provided an invalid object where a stream was expected. You can provide an Observable, Promise, Array, or Iterable.
这是我使用的代码:
import { Observable } from 'rx';
export const startApplicationEpic = (action$: Observable) =>
action$
.ofType('START_APPLICATION')
.flatMap(() =>
Observable.of(
{ type: 'REGISTER_PUSH_NOTIFICATIONS'},
{ type: 'AUTHENTICATION_REQUEST' }
)
);
// index.js
store.dispatch({ type: 'START_APPLICATION' })
对我来说,我使用的 RxJS 代码是有效的,如果 epics 是一个流,那么这应该可以工作,或者是否只能从史诗中调度单个动作?
您似乎正在导入 rx (which is v4) instead of rxjs (which is v5). So your code is providing a v4 Observable to the flatMap
of a v5 Observable (redux-observable internals by default give you v5). The two versions cannot interop by default, but there are temporary interop layers。我承认这一切都很混乱。
将 v4 与 redux-observable 结合使用的最佳方式是包含我们为其创建的适配器 redux-observable-adapter-rxjs-v4。如果您不小心使用了 v4,或者没有任何区别,请务必改用 v5。
修复该问题后,所提供的代码将按预期工作,没有错误:https://jsbin.com/xiqigi/edit?js,console
我正在使用 redux-observable 使用 react-native 构建应用程序。 现在我正在努力通过使用史诗对 redux-observable 中的两个动作进行简单装饰。我想要实现的只是将两个动作映射到一个。
我得到的错误是:
You provided an invalid object where a stream was expected. You can provide an Observable, Promise, Array, or Iterable.
这是我使用的代码:
import { Observable } from 'rx';
export const startApplicationEpic = (action$: Observable) =>
action$
.ofType('START_APPLICATION')
.flatMap(() =>
Observable.of(
{ type: 'REGISTER_PUSH_NOTIFICATIONS'},
{ type: 'AUTHENTICATION_REQUEST' }
)
);
// index.js
store.dispatch({ type: 'START_APPLICATION' })
对我来说,我使用的 RxJS 代码是有效的,如果 epics 是一个流,那么这应该可以工作,或者是否只能从史诗中调度单个动作?
您似乎正在导入 rx (which is v4) instead of rxjs (which is v5). So your code is providing a v4 Observable to the flatMap
of a v5 Observable (redux-observable internals by default give you v5). The two versions cannot interop by default, but there are temporary interop layers。我承认这一切都很混乱。
将 v4 与 redux-observable 结合使用的最佳方式是包含我们为其创建的适配器 redux-observable-adapter-rxjs-v4。如果您不小心使用了 v4,或者没有任何区别,请务必改用 v5。
修复该问题后,所提供的代码将按预期工作,没有错误:https://jsbin.com/xiqigi/edit?js,console