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

时间:2018-06-18 18:10:15

标签: angular typescript ngrx angular6 ngrx-store

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

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

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

这里是减速器代码:



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;
  }
}
&#13;
&#13;
&#13;

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

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

enter image description here

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

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

此时,我的假设已经用尽,所以任何关于如何调试这个谜题的线索都将受到赞赏。

1 个答案:

答案 0 :(得分:0)

发现它!我app.module

中的先前实验中有一个遗留物
StoreModule.forFeature('itemCategory', fromItemLevel.reducer),

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

相关问题