首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在@angular-redux/store configureStore 9版本中正确注册epics

在@angular-redux/store configureStore 9版本中正确注册epics
EN

Stack Overflow用户
提问于 2018-07-23 20:01:08
回答 1查看 383关注 0票数 0

我已经将自己的项目从5版本移到了angular 6,@angular-redux/store 9。一切都很好,但是在中间件中注册epics的方法不起作用。我从中间件中删除了除记录器和启动之外的所有epics,并执行了所有操作。然后我尝试添加一个epic,得到如下错误

代码语言:javascript
复制
TypeError: action$.pipe is not a function
at SecurityUserEpics.loadSecurityUser (security-user.epic.ts:31)
at combineEpics.js:19

然后我试着解决这个问题,搜索了很多例子和文档,但找不到解决方案。在决定在这里提问,同时为提问准备代码后,解决方案就找到了。所以,我在这里发布了这个解决方案,希望这能为某些人节省时间。史诗:

代码语言:javascript
复制
loadSecurityUser = (action$) => {
  debugger;
  // here i have object of type : {getState: ƒ, dispatch: ƒ} and thats was pain from older version. pipe helps!
  return action$.pipe(
     ofType(SecurityUserActions.LoadSecurityUsers),
     switchMap(q => this._dataSrv.getUserInfo()
        .pipe(map(data => {
           localStorage.setItem('isNeedRelogin', '0');
           return this._securityUserActions.loadSecurityUserComplete(data);
        }))));

}

和最终配置存储:

代码语言:javascript
复制
const epicMiddleware = createEpicMiddleware();
const middleware = [epicMiddleware];
middleware.push(createLogger());
ngRedux.configureStore(combinedReducer, INITIAL_STATE, middleware, storeEnhancers);
const rootEpic = combineEpics(this._securityUserEpics.loadSecurityUser);
// this is new way of middleware registration
epicMiddleware.run(rootEpic);
EN

回答 1

Stack Overflow用户

发布于 2018-08-06 15:36:34

使用provideStore代替configureStore,例如-

代码语言:javascript
复制
export const combinedEpics = combineEpics(
   pingEpic,
   fetchUserEpic
);

//replace ngRedux.configureStore with:
const epicMiddleware = createEpicMiddleware();

const store = createStore(
  combinedReducer,
  INITIAL_STATE,
  applyMiddleware(createLogger(), epicMiddleware),
);

ngRedux.provideStore(store);
epicMiddleware.run(combinedEpics);

有关epics的更多信息- https://redux-observable.js.org/docs/basics/Epics.html

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51478317

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档