在调度注销操作的帮助下使用“Meta Reducers”将整个Ngrx存储状态设置为未定义时出错

时间:2018-04-01 16:44:37

标签: javascript angular redux ngrx

我想从我的应用程序注销,在退出之前我想确保在此代码的帮助下使用MetaReducer完全清除了我的应用程序ngrx存储状态

import { StoreModule, ActionReducer, MetaReducer } from '@ngrx/store';

    export function logout(reducer: ActionReducer<any>): ActionReducer<any> {
      return function (state, action) {
        if (action.type === 'LOGOUT') {
          state = undefined;
        }

        return reducer(state, action);
      };
    }

    export const metaReducers: MetaReducer<any>[] = [logout];

当我在订阅ngrx商店状态之一的组件内部时,例如发票列表,所以当我从这里点击注销按钮时,在控制台enter image description here

并且给出错误的行是

 this.$invoice.takeWhile(() => this.isComponentAlive).subscribe(
      invoice => {

        this.permission = this.departmentService.getPermissionOfInvoiceCurrentDepartment(invoice.currentDepartmentId);

      }
    );

如果我要将代码更改为此

 this.$invoice.takeWhile(() => this.isComponentAlive).subscribe(
      invoice => {

        if (invoice) {
          this.permission = this.departmentService.getPermissionOfInvoiceCurrentDepartment(invoice.currentDepartmentId);
        }

      }
    );

它解决了这个问题,但我有很多这样的地方,所以我想为这个一站式解决方案,任何人都可以帮助我。

0 个答案:

没有答案