observable.map.replace doesn't seem to work for [[k,v], [k,v]] form
See original GitHub issueWelcome to MobX. Please provide as much relevant information as possible!
I have a: 3. [ ✔️] Issue:
-
Elaborate on your issue. What behavior did you expect?
` const newMap = [['a', 'hi'], ['b', 'hello']] @action setMyMap(myNewMap) { if(this.myMap) this.myMap.replace(myMap) //This is not triggering re-render else this.myMap = observable.map(myNewMap) } this.setMyMap(newMap); ` It started working when instead of `this.myMap.replace(myMap)`, I did a ` this.myMap.clear() this.myMap.merge(myNewMap) `
-
State the versions of MobX and relevant libraries. Which browser / node / … version?
MobX - 5.7.0
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Subscribing to Map Data Structure in JavaScript doesn't work
Do observables not work when adding/removing data from a Map? Here is the observable: test(): Observable<Map<string, Object>> { return ...
Read more >Map (Java SE 9 & JDK 9 ) - Oracle Help Center
An object that maps keys to values. A map cannot contain duplicate keys; each key can map to at most one value. This...
Read more >Kivy Documentation - Read the Docs
Kivy empowers you with the freedom to write your code once and have it run as-is on different plat- forms. Follow this guide...
Read more >Map | Android Developers
However, if the contained keys or values are themselves mutable, this may cause the Map to behave inconsistently or its contents to appear...
Read more >Coronavirus Disease 2019–COVID-19 - ASM Journals
Coronavirus infection in humans is commonly associated with mild to severe respiratory diseases, with high fever, severe inflammation, cough, and internal organ ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@mweststrate Can confirm this is still a bug in 5.8.0. We are using
replace()
in a sorting context to reorder a map of models by their ids.Calling
_setModels
with a reordered array usingreplace()
doesn’t trigger a rerender:However, this does correctly trigger the rerender:
Full disclosure, we’re in the process of upgrading from 3.3.1 to 5.8.0 where this previously worked because the implementation was just
.clear()
and.merge()
. Would appear that callingreplace()
with a reordered list of values, no longer does anything because it’s not removing or adding any keys, which would be fine except the documentation still says:you may mean to pass
myNewMap
, but you passedmyMap
indeed?and your second way which works passed into
myNewMap