在NgRx中填充状态期间不满足状态不变性



我有一个对象数组,它是从后端下载的,现在我想用它来填充我的状态变量。问题是该对象具有多个嵌套级别。

状态为-

const initialState: SummaryStateInterface = {
summaryList: [], // Problem is only with this one. 
editIndex: null,
editItem: null,
addingNew: false,
modifications: false,
isLoading: false,
}

SummaryStateInterface是这样的:

export interface SummaryStateInterface {
summaryList: Summary[] | null;
editIndex: number | null;
editItem: Summary | null;
addingNew: boolean | null;
modifications: boolean;
isLoading: boolean;
}

摘要模型如下:

export class Summary {
@required()
title: string;
@required()    // these decorators are for form validation  
text: string;
@required()    // these decorators are for form validation
focus: Focus[] = [];
@prop()
focusRef: DocumentReference[];
seqNo: number;
id: string;
}

Focus型号是这个

export class Focus {
@required()
name: string;
seqNo: number;
id: string;
}

将数据传递给此操作的效果是-

this.actions$.pipe(
ofType(readSummaryAction),
switchMap(() =>
this.service.list$.pipe(
map(list => {
console.log('This is the list ', list);
return readSummarySuccessAction({ list });
}),
catchError(() => of(readSummaryFailureAction())),
),
),
),
);

我试图填充summaryList的reducer是这样的-

on(
readSummarySuccessAction,
(state, action): SummaryStateInterface => {
const updatedSummaryList = [...state.summaryList].concat(
JSON.parse(JSON.stringify(action.list)),
);
return {
...state,
summaryList: updatedSummaryList,
),
};
},
),

为此操作传递的数据是一个由2项组成的数组(2( [{…},{…}]0:{title:"简历",url:"履历",ionicCon:",customIcon:"./assets/portfolio.svg",open:false,…}1:{title:"数据库",url:",ionicCon:",customIcon:"./assets/server.svg",open:false,…}长度:2proto:阵列(0(

其中一项是

focus: Array(3)
0: {id: "focusId1", name: "Main", seqNo: 1}
1: {id: "focusId2", name: "CFD", seqNo: 2}
2: {id: "focusId3", seqNo: 4.5, name: "Web"}
length: 3
__proto__: Array(0)
focusRef: (3) [n, n, n] // Firebase document reference
id: "sum1"
seqNo: 2.5
text: "Versatile and detail-driven Mechanical Engineer with a wealth of experience and knowledge in the Thermal-Fluids area. "
title: "Professional Summary"

抛出的错误是-

core.js:4197 ERROR TypeError: Cannot freeze
at Function.freeze (<anonymous>)
at freeze (http://localhost:8101/vendor.js:103583:12)
at http://localhost:8101/vendor.js:103603:17
at Array.forEach (<anonymous>)
at freeze (http://localhost:8101/vendor.js:103586:40)
at http://localhost:8101/vendor.js:103603:17
at Array.forEach (<anonymous>)
at freeze (http://localhost:8101/vendor.js:103586:40)
at http://localhost:8101/vendor.js:103603:17
at Array.forEach (<anonymous>)

取消订阅ErrorImpl{message:"取消订阅期间发生2个错误:↵1( TypeEr…:无法添加属性0,对象不可扩展",名称:";取消订阅错误";,错误:数组(2(}

core.js:4197错误类型错误:无法分配给对象'[object object]'的只读属性'__zone_symbol__state'

区域常青.js:976未捕获类型错误:无法添加属性0,对象不可扩展

是否可以获得一些反馈
我愿意重组(拉平(状态,但我不知道重组到什么程度以及如何重组。

Summary类中的focusRef属性是DocumentReference。不幸的是,无论出于何种原因,Firebase中的DocumentReference字段都有循环引用。

本文讨论了循环参考主题:Firestore引用创建一个";TypeError:将循环结构转换为JSON";

我使用它们的路径属性(ref.path(将这些引用(ref(转换为字符串。

一旦字符串,所有这些错误都消失了。如果有人能解释一下core.js的冻结是如何工作的,我会很高兴

core.js:4197 ERROR TypeError: Cannot freeze
at Function.freeze (<anonymous>)
at freeze (http://localhost:8101/vendor.js:103583:12)
at http://localhost:8101/vendor.js:103603:17
at Array.forEach (<anonymous>)
at freeze (http://localhost:8101/vendor.js:103586:40)
at http://localhost:8101/vendor.js:103603:17
at Array.forEach (<anonymous>)
at freeze (http://localhost:8101/vendor.js:103586:40)
at http://localhost:8101/vendor.js:103603:17
at Array.forEach (<anonymous>)

不相关但有用检测对象(x(中的循环引用是:DoJSON.parse(JSON.stringfy(x((。此表达式将失败。

相关内容

  • 没有找到相关文章

最新更新