我有一个包含其他不可变对象的不可变对象,并且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
段。
这里解释了嵌套对象的模式: