Comments (2)
and tried like this also : map.set(['b','d'], function(value) { return 1000; })
from immutable-js.
Since that value is a mutable object, not an immutable map, the immutable API does not apply to it (see Object's API). If your update backs up one level, then it points to the object instead of the key within the object:
var map1 = Immutable.Map({a:1, b:{d:2}, c:3});
var map2 = map1.update('b', function (value) { value.d = 1000; return value; })
However, note that this has mutated a mutable value, which your original map
still points to, so in this case map2 === map1
.
You could also return a copy of this object:
var map1 = Immutable.Map({a:1, b:{d:2}, c:3});
var map2 = map1.update('b', function (value) {
var newValue = {};
for (var k in value) {
if (value.hasOwnProperty(k)) {
newValue[k] = value[k];
}
}
newValue.d = 1000;
return newValue;
})
And now map2 !== map1
and map1
's mutable object has not been changed. However this highlights one of the use cases of Immutable Map. If you desired the second behavior, then using an immutable Map instead of a mutable Object as a nested value would provide an API much easier to work with:
var map1 = Immutable.Map({a:1, b:Immutable.Map({d:2}), c:3});
var map2 = map1.update('b', function (value) { return value.set('d', 1000); })
from immutable-js.
Related Issues (20)
- createSerializableStateInvariantMiddleware for Record in React Redux TS HOT 1
- Supporting wildcards HOT 7
- Converting a Seq to a list causes RangeError (max call size exceeded) HOT 1
- 4.2.0: partition missing in flow HOT 3
- Question: Wiki article for upgrading to v4 HOT 3
- `toJS` breaks type compatibility between records with object values HOT 8
- Wrong typescript declarations for `.update()` method (continued) HOT 2
- Record with more keys should be assignable to Record with less keys if type is a subset of the first one
- An argument for 'reviver' was not provided. HOT 4
- ReferenceError: Immutable is not defined HOT 9
- Highlight inputs where `Set` can't maintain uniqueness HOT 4
- Flow type definition outdated, not working with last year changes HOT 1
- Urgent: Package Installation Reveals Multiple Vulnerabilities HOT 1
- Type predicate missing on isOrderedSet function type declaration
- support deno HOT 2
- immutable default import in 5.x
- version 4.3.3 breaks TS/Angular/webpack HOT 2
- Typescript: Implement `MapOf::merge `
- Extract sort function from Collection types HOT 6
- Enhancement: Custom equals HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from immutable-js.