首页 文章

我的ngrx reducer只接收`@ngrx / store / init`动作

提问于
浏览
0

我正在使用ngrx商店(加上路由器,路由器存储和效果模块)开发电子商务Angular 6应用程序 .

这是我第一次使用ngrx,到目前为止,一切都进展顺利:我开发了几个ngrx功能,每个功能都有各自的状态和减速器,效果,模型和动作 .

只有这一次,我无法弄清楚我做错了什么 . 对于我的上一个功能,看起来没有任何操作通过其reducer . 它捕获的唯一操作是具有类型'@ngrx / store / init'的操作 .

这是reducer代码:

export function reducer(state = initialState, action: ItemCategoryActions): State {
  console.warn('item-category', action.type);
  switch (action.type) {
    case ItemCategoryActionTypes.LoadItemCategories: {
      return state;
    }

    case ItemCategoryActionTypes.LoadItemCategoriesComplete: {
      return { categories: (<LoadItemCategoriesComplete>action).payload.items};
    }

    default:
      return state;
  }
}

我不会在这里重现我的所有代码,因为它是你典型的ngrx样板,但是让我向你保证我已经将减速器添加到根减速器图中,我已经导入了效果,并且我确保了这些动作正确打字等

运行我的代码的日志跟踪如下:

enter image description here

正如您所看到的,捕获@ ngrx / store / init操作的唯一reducer是我的新 item-category reducer,它不会捕获任何其他操作 .

我所有的其他减速机都按预期工作 .

在这一点上,我已经没有假设,所以任何关于如何调试这个难题的线索将不胜感激 .

1 回答

  • 0

    找到了!在我的 app.module 中,之前的实验中有一个剩余物

    StoreModule.forFeature('itemCategory', fromItemLevel.reducer),
    

    这显然造成了令人困惑的混乱......

相关问题