簡體   English   中英

不可變的JS更新地圖中的所有對象

[英]Immutable JS update all object in map

我有這張地圖:

map1:{
    x: {...}
    y: {...}
    h: {...}
    j: {...}
    k: {...}
}

如何更新一個公共屬性,例如為地圖中的所有對象“選擇”,並盡可能快地對不可變js響應redux js?

謝謝。

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, :)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM