首页 > 解决方案 > 如何将两个ngrx动作减速器组合成一个角度?

问题描述

以下是单个操作的 reducer 代码。

on(apiContentActions.deleteApiContentsSuccess, (state, action) => {
    return {
      ...state,
      success: true,
    };
  }),
  on(apiContentActions.deleteApiContentSuccess, (state, action) =>
    adapter.updateOne(
      {
        id: action.apiContent.contentId,
        changes: { ...action.apiContent, text: 'deleted' },
      },
      state,
    )
  ),

我如何将它们组合成一个片段,而不是单独编写?

像这样的东西:

on(apiContentActions.deleteApiContentsSuccess, (state, action) => {
    return adapter.updateOne(
        {
          id: action.apiContent.itemId,
          changes: { ...action.apiContent, text: 'deleted' },
        },
        state,
      )
    &&
    {
      ...state,
      success: true,
    };
  }),

没有其他的。只是将减速器功能组合到一个主体中>=

标签: angular

解决方案


推荐阅读