在哪里可以找到有关如何创建减速器的NgRx版本7文档

问题描述

我只是从版本8开始使用NgRx,所以只对动作和化简使用了create函数。

不幸的是,我现在仍在Angular 7中的项目中工作,我想在此添加NgRx。

我有以下

export interface State {
   templates: MyTemplates[];
}

createAction似乎存在,所以我有以下内容...

export const getTemplatesSuccess = createAction(
        `${actionPrefix} Get templates success`,(payload: MyTemplate[]) => ({ payload })
    );
    
    export const actions = union({
        getTemplates,getTemplatesSuccess,getTemplatesFail,});

    export type ActionsUnion = typeof actions;

但是现在,在我的reducer中,我没有createReducer。我试图找到一些以前的语法,到目前为止有以下...

import * as myActions from './my.actions';

    const initialState: State = {
        templates: []
    }

    
    export function myReducer(
        state = initialState,action: myActions.ActionsUnion)
    {
        switch (action.type) {
            case myActions.getTemplates.type: {
                return state;
            }
            case myActions.getTemplatesSuccess.type: {
                const newState = { ...state };
                newState.templates = action.payload; <------ playoad does not exist
                return newState;
            }
                
        }
    }

上面的问题是该动作上不存在.payload。我不知道我要如何获得成功动作随附的有效载荷。

解决方法

旧版本的文档可在https://v7.ngrx.io/

获得

我还在NgRx creator functions 101

上写了两者之间的比较

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...