-
Notifications
You must be signed in to change notification settings - Fork 0
/
Object.observe.min.js
6 lines (6 loc) · 2.96 KB
/
Object.observe.min.js
1
2
3
4
5
6
Object.observe||function(l,s){var t=function(b){var a=b.call(b),f=typeof f;return"object"===typeof s.alert?function(g){return a===b.call(g)||!!g&&typeof g.toString==f&&typeof g.valueOf==f&&/^\s*\bfunction\b/.test(""+g)}:function(g){return a===b.call(g)}}(l.prototype.toString),q=function(b,a){if("object"!==typeof b)throw new TypeError("Object.observeObject called on non-object");if(!1===t(a))throw new TypeError("Object.observeObject: Expecting function");if(!0===Object.isFrozen(a))throw new TypeError("Object.observeObject: Expecting unfrozen function");
},u=function(){var b=[],a=function(a,k){q(a,k);Object.getNotifier(a).addListener(k);-1===b.indexOf(a)?b.push(a):Object.getNotifier(a)._checkPropertyListing()};a.prototype.deliverChangeRecords=function(a){Object.getNotifier(a).deliverChangeRecords()};b.lastScanned=0;var f=function(a){return function(){for(var b=0,h=a.length,c=new Date,l=!1,b=a.lastScanned;b<h&&!l;b++)Object.getNotifier(a[b])._checkPropertyListing(),l=100<new Date-c;a.lastScanned=b<h?b:0;setTimeout(f,100)}}(b);setTimeout(f,100);return a}(),
v=function(b){var a=[],f=[],g=!1,k=[],h=[],c=this;Object.defineProperty(c,"_watching",{get:function(a){return function(){return a}}(b)});var l=function(a,b){var d=Object.getOwnPropertyDescriptor(a,b),e;(e="getNotifier"===b)||(e=("undefined"===typeof d?!1:"get"in d||"set"in d)||!d.enumerable);if(e)return!1;if(a instanceof Array&&!isNaN(parseFloat(b))&&isFinite(b))return d=k.length,k[d]=b,h[d]=a[b],!0;(function(b,d){k[b]=d;h[b]=a[d];Object.defineProperty(a,d,{get:function(){return h[b]},set:function(e){var c=
h[b];if(c===e?0===c&&1/c!==1/e:c===c||e===e)Object.getNotifier(a).queueUpdate(a,d,"updated",h[b]),h[b]=e}})})(k.length,b);return!0};c._checkPropertyListing=function(a){for(var b=c._watching,d=Object.keys(b),e=0,g=d.length,f=k.slice(0),n=!a,p,m,e=0;e<g;e++)a=d[e],p=b[a],-1===(m=k.indexOf(a))?l(b,a)&&n&&c.queueUpdate(b,a,"new",null,b[a]):(b instanceof Array&&(!isNaN(parseFloat(a))&&isFinite(a))&&h[m]!==p&&(n&&c.queueUpdate(b,a,"updated",h[m],p),h[m]=p),f.splice(f.indexOf(a),1));if(n)for(g=f.length,
e=0;e<g;e++)m=k.indexOf(f[e]),c.queueUpdate(b,f[e],"deleted",h[m]),k.splice(m,1),h.splice(m,1)};c.addListener=function(b){-1===a.indexOf(b)&&a.push(b)};c.removeListener=function(b){b=a.indexOf(b);-1<b&&a.splice(b,1)};c.listeners=function(){return a};c.queueUpdate=function(a,b,d,e){this.queueUpdates([{type:d,object:a,name:b,oldValue:e}])};c.queueUpdates=function(a){for(var b=this,d=0,e=a.length||0,c,d=0;d<e;d++)c=a[d],f.push(c);g&&clearTimeout(g);g=setTimeout(function(){g=!1;b.deliverChangeRecords()},
100)};c.deliverChangeRecords=function(){for(var b=0,c=a.length,d=!0,b=0;b<c&&d;b++)"function"===typeof a[b]&&(a[b]===console.log?console.log(f):d=!a[b](f));f=[]};c._checkPropertyListing(!0)},r=[],n=[];l.getNotifier=function(b){var a=n.indexOf(b),a=-1<a?r[a]:!1;a||(a=n.length,n[a]=b,a=r[a]=new v(b));return a};l.observe=function(b,a){return new u(b,a)};l.unobserve=function(b,a){q(b,a);l.getNotifier(b).removeListener(a)}}(Object,this);