redux:在大状态树的叶节点中设置状态

问题描述 投票:0回答:1

我有一个包含其他不可变对象的不可变对象,并且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
1个回答
0
投票

这里解释了嵌套对象的模式:

© www.soinside.com 2019 - 2024. All rights reserved.