immutablejs update use code example

Example: immutablejs update use

// Act on a single key/value in a Map​const avengersMap = Immutable.Map({  ironMan: 'Tony Stark',  captainAmerica: 'Steve Rogers',  blackWidow: 'Natasha Romanov'});​const updatedAvengers = avengersMap.update('ironMan', (ironManValue) => {  // ironManValue is a JavaScript type - no need for Immutable   // functions to modify it  return ironManValue + ' is ironMan';});​// Output:updatedAvengers Object {  "blackWidow": "Natasha Romanov",    "captainAmerica": "Steve Rogers",      "ironMan": "Tony Stark is ironMan",}

Tags:

Misc Example