Javascript 不可变JS更新映射中的所有对象

Javascript 不可变JS更新映射中的所有对象,javascript,reactjs,redux,immutable.js,Javascript,Reactjs,Redux,Immutable.js,我有这张地图: map1:{ x: {...} y: {...} h: {...} j: {...} k: {...} } 我如何更新一个公共属性,例如映射中所有对象的“selected”,以及使用不可变js尽可能快地更新react-redux js 谢谢。如果map对于您的目的来说足够快,请尝试使用newMap=oldMap.map(value=>value.set('selected',true))Hi。500件物品大约需要2秒钟。有更快的方法吗?@

我有这张地图:

map1:{
    x: {...}
    y: {...}
    h: {...}
    j: {...}
    k: {...}
}
我如何更新一个公共属性,例如映射中所有对象的“selected”,以及使用不可变js尽可能快地更新react-redux js


谢谢。

如果
map
对于您的目的来说足够快,请尝试使用
newMap=oldMap.map(value=>value.set('selected',true))
Hi。500件物品大约需要2秒钟。有更快的方法吗?@YuryTarabanko我得到一个错误值。集合不是function@user3712353这可能是因为您所引用的值不是一个不可变的对象,而是一个普通的javascript对象。当我使用@YuryTarabanko的想法时,它在2600个项目的初始阵列上运行的时间可以忽略不计。
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, :)