【发布时间】:2020-07-24 17:10:25
【问题描述】:
我有一个 Immutable 对象,其中包含其他 Immutable 对象,并且 redux 状态树设置为最顶层对象的实例:
records.js:
const TypeC = newRecord({
content: null
})
const TypeB = newRecord({
typeC: new TypeC;
})
export const TypeA = newRecord({
typeB: new TypeB;
})
reducer.js:
import {
TypeA,
} from './records';
import types from './types';
const applicationReducer = (state = new TypeA(), action) => {
switch (action.type) {
...
}
default:
return state;
}
};
我的问题是:如何编写reducer 代码来更改TypeC 中的content 字段?我试过类似的东西
CASE types.UPDATECONTENT: {
return state.get('typeB').get('typeC').set('content', "new content")
}
但这似乎只返回我的状态树的 TypeC 段,当我需要从根开始的整个树时。
【问题讨论】:
标签: redux immutable.js