heleg
heleg

Reputation: 270

How to update deep list in ImmutableJS?

Can anyone tell me what how to update 'value' by id in this structue in ImmutableJS?

map = {
  list: [
    {
      id: 1,
      value: 'update'  
    }
  ]
}

Upvotes: 0

Views: 86

Answers (1)

Dilek Gencer
Dilek Gencer

Reputation: 131

You can use the code below. However, it is not the best solution, because that will search all items in the list. If you can change your structure instead of List you can use OrderedMap.

var newData = map.set("list", map.get("list").map(data => data.get("id") === 1 ? data.set("value", "updatedValue") : data));

Upvotes: 0

Related Questions