-
Notifications
You must be signed in to change notification settings - Fork 0
/
ObjectObserver.min.js
1 lines (1 loc) · 1.43 KB
/
ObjectObserver.min.js
1
(function(g,h){var i=(function(){var c={size:function(){return this.keys().length},add:function(a,b){this.keys().push(a);this.values().push(b);return this.get(a)},remove:function(a){var b=this.keys().indexOf(a);if(b>=0){this.keys().splice(b,1);this.values().splice(b,1)}},get:function(a){return this.values()[this.keys().indexOf(a)]}};return function(){var a=[],values=[];return h.create(c,{keys:{value:function(){return a}},values:{value:function(){return values}}})}}());(function(){var f=i();function _addListener(c,d){var e,_initialValue=c[d],_initialPropertyDescriptor=h.getOwnPropertyDescriptor(c,d),_initialSetter=_initialPropertyDescriptor&&_initialPropertyDescriptor.set;h.defineProperty(c,d,{set:function(b){_initialSetter&&_initialSetter(b);if(b!==e){f.get(c).get(d).forEach(function(a){a(b)});e=b}},get:function(){return e}});c[d]=_initialValue}function _removeListener(a,b){var c=a[b];delete a[b];a[b]=c}function observe(a,b,c){var d=f.get(a),_callbacks;if(!d){d=f.add(a,i())}_callbacks=d.get(b);if(!_callbacks){_callbacks=d.add(b,[]);_addListener(a,b)}if(_callbacks.indexOf(c)<0){_callbacks.push(c)}}function unobserve(a,b,c){var d=f.get(a),_callbacks,_index;if(!d){return}_callbacks=d.get(b);if(!_callbacks){return}_index=_callbacks.indexOf(c);if(_index>=0){_callbacks.splice(_index,1)}if(!_callbacks.length){d.remove(b);_removeListener(a,b);if(!d.size()){f.remove(a)}}}g.ObjectObserver={observe:observe,unobserve:unobserve}}())}(window,Object));