我已经将自己的项目从5版本移到了angular 6,@angular-redux/store 9。一切都很好,但是在中间件中注册epics的方法不起作用。我从中间件中删除了除记录器和启动之外的所有epics,并执行了所有操作。然后我尝试添加一个epic,得到如下错误
TypeError: action$.pipe is not a function
at SecurityUserEpics.loadSecurityUser (security-user.epic.ts:31)
at combineEpics.js:19然后我试着解决这个问题,搜索了很多例子和文档,但找不到解决方案。在决定在这里提问,同时为提问准备代码后,解决方案就找到了。所以,我在这里发布了这个解决方案,希望这能为某些人节省时间。史诗:
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);
}))));}
和最终配置存储:
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);发布于 2018-08-06 15:36:34
使用provideStore代替configureStore,例如-
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
https://stackoverflow.com/questions/51478317
复制相似问题