-
Notifications
You must be signed in to change notification settings - Fork 55
/
observable-slim.min.js
1 lines (1 loc) · 5.35 KB
/
observable-slim.min.js
1
function _typeof(e){return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},_typeof(e)}var ObservableSlim=function(){var e=[],r=[],t=[],n=[],o=null,a=function a(l,i,u,s){var f=u||null,g=s||[{target:l,property:""}];e.push(g),l instanceof Array&&(l.hasOwnProperty("__length")?l.__length=l.length:Object.defineProperty(l,"__length",{enumerable:!1,value:l.length,writable:!0}));var p=[],c=function(e,r,t){for(var n="",o=null,a=0;a<g.length;a++)o instanceof Array&&!isNaN(g[a].property)&&(g[a].property=o.indexOf(g[a].target)),n=n+"."+g[a].property,o=g[a].target;return n=(n=n+"."+r).substring(2),!0===t&&(n="/"+n.replace(/\./g,"/")),n},v=function(e){if(!0!==f.paused){var r="number"==typeof i;if(r||!0===i)setTimeout((function(){if(e===p.length){var r=p.slice(0);p=[];for(var t=0;t<f.observers.length;t++)f.observers[t](r)}}),r&&i>0?i:10);else{var t=p.slice(0);p=[];for(var n=0;n<f.observers.length;n++)f.observers[n](t)}}},b={get:function(e,r){if("__getTarget"===r)return e;if("__isProxy"===r)return!0;if("__getParent"===r)return function(e){if(void 0===e)e=1;var r=c(0,"__getParent").split(".");return r.splice(-(e+1),e+1),function(e,r){return r.split(".").reduce((function(e,r){return e?e[r]:void 0}),e||self)}(f.parentProxy,r.join("."))};if("__getPath"===r)return c(0,"__getParent").slice(0,-12);var o=e[r];if(e instanceof Date&&o instanceof Function&&null!==o)return o.bind(e);if(o instanceof Object&&null!==o&&e.hasOwnProperty(r)){if(!0===o.__isProxy&&(o=o.__getTarget),o.__targetPosition>-1&&null!==t[o.__targetPosition])for(var l=n[o.__targetPosition],u=0,s=l.length;u<s;u++)if(f===l[u].observable)return l[u].proxy;var p=g.slice(0);return p.push({target:o,property:r}),a(o,i,f,p)}return o},deleteProperty:function(e,r){var a=!0;o===y&&(a=!1,o=null);var l=Object.assign({},e);if(p.push({type:"delete",target:e,property:r,newValue:null,previousValue:l[r],currentPath:c(0,r),jsonPointer:c(0,r,!0),proxy:y}),!0===a){f.changesPaused||delete e[r];for(var i=0,u=t.length;i<u&&e!==t[i];i++);for(var s=n[i]||[],g=s.length;g--;)s[g].proxy!==y&&(o=s[g].proxy,delete s[g].proxy[r])}return v(p.length),!0},set:function(e,r,a,l){a&&a.__isProxy&&(a=a.__getTarget);var i=!0;o===y&&(i=!1,o=null);var u=e[r];if(u!==a||!1===i||"length"===r&&e instanceof Array&&e.__length!==a){var s=!0,g=_typeof(u),b="update";if("undefined"===g&&(b="add"),p.push({type:b,target:e,property:r,newValue:a,previousValue:l[r],currentPath:c(0,r),jsonPointer:c(0,r,!0),proxy:y}),"length"===r&&e instanceof Array&&e.__length!==a&&(p[p.length-1].previousValue=e.__length,e.__length=a),!0===i){f.changesPaused||(e[r]=a),s=!1;for(var h=e.__targetPosition,_=n[h].length;_--;)if(f===n[h][_].observable&&null!==t[n[h][_].observable.parentTarget.__targetPosition]){s=!0;break}if(s){for(var P=n[h],d=0,m=P.length;d<m;d++)P[d].proxy!==y&&(o=P[d].proxy,P[d].proxy[r]=a);setTimeout((function(){if("object"===g&&null!==u){for(var r=Object.keys(e),o=0,a=r.length;o<a;o++)if(e[r[o]]===u)return;var l=!1;if(function e(r){for(var t=Object.keys(r),n=0,o=t.length;n<o;n++){var a=r[t[n]];if(a instanceof Object&&null!==a&&e(a),a===u)return void(l=!0)}}(e),!0===l)return;!function e(r){for(var o=Object.keys(r),a=0,l=o.length;a<l;a++){var i=r[o[a]];i instanceof Object&&null!==i&&e(i)}var u=-1;for(a=0,l=t.length;a<l;a++)if(r===t[a]){u=a;break}if(u>-1){for(var s=n[u],g=s.length;g--;)if(f===s[g].observable){s.splice(g,1);break}0==s.length&&(t[u]=null)}}(u)}}),1e4)}}s&&v(p.length)}return!0}},h=l.__targetPosition;h>-1||Object.defineProperty(l,"__targetPosition",{value:t.length,writable:!1,enumerable:!1,configurable:!1});var y=new Proxy(l,b);null===f&&(f={parentTarget:l,domDelay:i,parentProxy:y,observers:[],paused:!1,path:g,changesPaused:!1},r.push(f));var _={target:l,proxy:y,observable:f};return h>-1?(null===t[h]&&(t[h]=l),n[h].push(_)):(t.push(l),n.push([_])),y};return{create:function(e,r,t){if(!0===e.__isProxy)e=e.__getTarget;var n=a(e,r);return"function"==typeof t&&this.observe(n,t),function e(r){for(var t=r.__getTarget,n=Object.keys(t),o=0,a=n.length;o<a;o++){var l=n[o];t[l]instanceof Object&&null!==t[l]&&e(r[l])}}(n),n},observe:function(e,t){for(var n=r.length;n--;)if(r[n].parentProxy===e){r[n].observers.push(t);break}},pause:function(e){for(var t=r.length,n=!1;t--;)if(r[t].parentProxy===e){r[t].paused=!0,n=!0;break}if(0==n)throw new Error("ObseravableSlim could not pause observable -- matching proxy not found.")},resume:function(e){for(var t=r.length,n=!1;t--;)if(r[t].parentProxy===e){r[t].paused=!1,n=!0;break}if(0==n)throw new Error("ObseravableSlim could not resume observable -- matching proxy not found.")},pauseChanges:function(e){for(var t=r.length,n=!1;t--;)if(r[t].parentProxy===e){r[t].changesPaused=!0,n=!0;break}if(0==n)throw new Error("ObseravableSlim could not pause changes on observable -- matching proxy not found.")},resumeChanges:function(e){for(var t=r.length,n=!1;t--;)if(r[t].parentProxy===e){r[t].changesPaused=!1,n=!0;break}if(0==n)throw new Error("ObseravableSlim could not resume changes on observable -- matching proxy not found.")},remove:function(e){for(var o=null,a=!1,l=r.length;l--;)if(r[l].parentProxy===e){o=r[l],a=!0;break}for(var i=n.length;i--;)for(var u=n[i].length;u--;)n[i][u].observable===o&&(n[i].splice(u,1),0===n[i].length&&(t[i]=null));!0===a&&r.splice(l,1)}}}();try{module.exports=ObservableSlim}catch(e){}