Reputation: 1279
How to use Object.observe on Map? This doesn't work:
var map = new Map();
Object.observe(map, function() { console.log("ok"); });
map.set('key', 'value');
And this too:
var map = new Map();
Array.observe(map, function() { console.log("ok"); });
map.set('key', 'value');
Upvotes: 4
Views: 2123
Reputation: 413709
The Object.observe()
facility is a general way to watch for changes to an object. Calls to the Map
API do not trigger any of the events that the .observe()
facility watches for, because no properties of the Map
object are added, remove, changed, etc.
Current ES6/ES2015 specs make no provisions for observing updates to Map
or Set
instances, as far as I can tell.
Upvotes: 4