redux-observable:动作必须是普通对象。使用自定义中间件进行异步操作

时间:2017-05-31 10:17:59

标签: reactjs redux redux-observable

我的史诗有问题,请帮我找出错误的地方。谢谢!

以下代码将我引向错误:



const loginEpic = (action$) =>
  action$
    .ofType('LOGIN')
    .switchMap(() => {
      return Observable.fromPromise(loginService())
        .map((result) => {
          return Observable.of({
            payload: result,
            type: types.loginCompleted,
          });
        })
        .catch((error) => {
          return Observable.of({
            payload: error,
            type: types.loginFailed,
          });
        });
    });




这是我的configureStore文件:



const epicMiddleware = createEpicMiddleware(rootEpic);

// Ref: https://redux-observable.js.org/docs/recipes/HotModuleReplacement.html
if (module.hot) {
  module.hot.accept('./epic', () => {
    const nextEpic = require('./epic');
    epicMiddleware.replaceEpic(nextEpic);
  });
}

const configureStore = (): Store<any> => {

  const store = createStore(rootReducer, composeWithDevTools(applyMiddleware(epicMiddleware)));
  if (module.hot) {
    module.hot.accept('./reducer', () => {
      const nextReducer = require('./reducer').default;
      store.replaceReducer(nextReducer);
    });

    return store;
  }
};
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:3)

我相信你必须从<li ng-repeat="item in problems | filter: {problem: searchCard}"> {{item.problem}} <ul> <li ng-repeat="work in item.works">{{work}}</li> </ul> </li> 编辑 - 感谢paulpdaniels:但不是Observable.of(...))方法中删除map(),因为在此您返回可观察的可观察量的方式 - 请参阅下面的简化代码:

catch()

整个代码应为:

Observable.fromPromise(...)
    .map(result => Observable.of(...))  // maps an object to an observable