XPD
XPD

Reputation: 1215

What is the difference between ObservableMap and ObservableArray in mobx

As per the documentation,

observable.map(values?) creates a dynamic keyed observable map. Observable maps are very useful if you don't want to react just to the change of a specific entry, but also to the addition or removal of entries.

I may be the only one who doesn't understand the difference between these two mobx observable types. Even the doc says map can track addition or removal, following array also notifies the console by autorun when a new value is pushed into the array. So what is the real difference between the two?

window.q = observable([1,2,3]);
autorun(()=>{console.log(q[0]);})
q.push(32)

Upvotes: 1

Views: 799

Answers (1)

Kyle Richardson
Kyle Richardson

Reputation: 5645

The difference is in the methods you use to interact with them. Think of one as an array, and the other as a map. Arrays stores indices, maps store keys and values.

Upvotes: 1

Related Questions