我有这张地图:
map1:{
x: {...}
y: {...}
h: {...}
j: {...}
k: {...}
}
如何更新公共财产,例如"选择"对于地图中的所有对象,尽可能最快地使用不可变的js反应redux js?
感谢。
答案 0 :(得分:0)
const { fromJS } = require('immutable');
let state = fromJS({
map1: {
x: { selected: false},
y: { selected: false}
}
});
console.log(state.update('map1', item => item.map(
keyValue => keyValue.set('selected', true)
)).toJS());
//result:{ map1: { x: { selected: true }, y: { selected: true } } }
//Have not tried other different methods to test speed,
//since the field is not deep-nested, it should be fast enough, Hope this may help, :)