如何解决在哪里可以找到有关如何创建减速器的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/
获得 上写了两者之间的比较版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。