dictionary - Observing changes to ES6 Maps and Sets -


is there way observe additions , removals es6 maps , sets? object.observe doesn't work because applies direct properties of observed object. hypothetically size property observed, no indication provided of has changed. idea replace object's set , get functions proxified versions. there better way? if not, i'm surprised nobody thought of when proposals being written es6.

no, there no way vanilla map/set. in general observation of object properties alone controversial (that why object.observe proposal, , not accepted part of spec). observing private state, internals of map or set (or date or promise, matter), not on table.

note since size getter, not data property, object.observe not notify of changes it.

as mention, can achieve such "observation" via collaboration between mutator , observer. either normal map/set plus side-channel (e.g. function returning { map, eventemitter } object), or via subclass tailored purpose, or specific instance created purpose.