dipole-es3
Advanced tools
Comparing version 2.2.8 to 2.2.9
@@ -1,2 +0,2 @@ | ||
function t(t){for(var n=new Array(t),i=0;i<t;i++)n[i]=void 0;return n}var HashSet=/*#__PURE__*/function(){function HashSet(){this._items=t(4),this._size=0,this._maxSizeBeforeClear=0,this._isInIteration=!1}var n=HashSet.prototype;return n.add=function(t){if(this._isInIteration)return!1;for(var n=this._items,i=n.length,r=i-1,o=t._hash&r;void 0!==n[o]&&n[o]!==t;)o=o+1&r;return void 0===n[o]&&(n[o]=t,++this._size>11*i>>4&&this._rehashUp(2*i),this._maxSizeBeforeClear<this._size&&(this._maxSizeBeforeClear=this._size),!0)},n._rehashUp=function(n){var i=this._items,r=i.length;this._items=t(n),this._size=0;for(var o=0;o<r;o++){var s=i[o];void 0!==s&&this.add(s)}},n.remove=function(t){if(this._isInIteration)return!1;for(var n=this._items,i=n.length-1,r=t._hash&i;void 0!==n[r]&&n[r]!==t;)r=r+1&i;if(void 0!==n[r]){for(var o=r,s=1;;){var e=n[o=o+1&i];if(void 0===e){n[r]=void 0;break}(o-e._hash&i)>=s?(n[r]=e,r=o,s=1):s++}return this._size--,!0}return!1},n.size=function(){return this._size},n.forEach=function(t){this._isInIteration=!0;for(var n=this._items,i=n.length,r=0;r<i;r++){var o=n[r];void 0!==o&&t(o)}this._isInIteration=!1},n.clearAndResize=function(){for(var n=this._maxSizeBeforeClear,i=4;n>11*i>>4;)i*=2;if(4*i<this._items.length)this._items=t(i);else for(var r=this._items,o=r.length,s=0;s<o;s++)r[s]=void 0;this._size=0,this._maxSizeBeforeClear=0},HashSet}(),n=[],i=[],r=new HashSet,o=[],s=null,e={t:null,i:0};function u(){for(var t;t=n.pop();)5===t._state&&t.runManager()}function f(){for(var t;t=o.pop();)r.remove(t),t._checkSubscribers();s=null}function h(){for(var t;t=i.pop();)t._actualizeState()}function c(t){++e.i;try{t()}finally{0==--e.i&&v()}}function a(t){var n=e.t;e.t=null,++e.i;try{return t()}finally{0==--e.i&&v(),e.t=n}}function l(t){var n=e.t;e.t=null;try{return t()}finally{e.t=n}}function v(){for(;i.length>0||n.length>0;)h(),u()}function b(){return 1e9*Math.random()|0}var y=void 0,p={},d={};function w(t){var n=e.t;return n===p?(y=t,!0):n===d&&(t.notify(),!0)}function x(t){var n=e.t;null!==n&&t._subscribers.add(n)&&n._subscribeTo(t)}function m(t){t._subscriptions.forEach(function(n){n._removeSubscriber(t)}),t._subscriptions=[],t._maybeDirtySubscriptions&&(t._maybeDirtySubscriptions=null)}function g(t,n,i){t._subscribers.forEach(function(i){i._notify(n,t)}),i&&t._subscribers.clearAndResize()}function O(t){if(t&&"object"==typeof t){var n=t.checkValue;if("function"==typeof n)return n}return null}var Computed=/*#__PURE__*/function(){function Computed(t,n){this._hash=b(),this._subscribers=new HashSet,this._value=void 0,this._checkValueFn=O(n),this._state=0,this._computer=t,this._subscriptions=[],this._maybeDirtySubscriptions=null}var t=Computed.prototype;return t.get=function(){if(2===this._state)throw new Error("Trying to get computed value while in computing state");return w(this)||(this._actualizeState(),x(this)),this._value},t.destroy=function(){m(this),this._state=0},t._actualizeState=function(){var t;4===this._state&&((t=this)._maybeDirtySubscriptions.every(function(n){return n._actualizeState(),4===t._state})&&(t._state=3),t._maybeDirtySubscriptions=null),5!==this._state&&0!==this._state||this._recomputeAndCheckValue()},t._recomputeAndCheckValue=function(){var t=this,n=this._state,i=this._recomputeValue();if(null!==this._checkValueFn&&0!==n){if(l(function(){return t._checkValueFn(t._value,i)}))return;g(this,5,!0)}this._value=i},t._recomputeValue=function(){var t=e.t;e.t=this;var n=this._state;this._state=2;try{var i=this._computer();return this._state=3,i}catch(t){throw m(this),this._state=n,t}finally{e.t=t}},t._subscribeTo=function(t){this._subscriptions.push(t)},t._notify=function(t,n){this._state>=t||(null!==this._checkValueFn?3===this._state&&g(this,4,!1):g(this,t,5===t),this._state=t,4===t?function(t,n){(t._maybeDirtySubscriptions||(t._maybeDirtySubscriptions=[])).push(n)}(this,n):5===t&&m(this))},t._removeSubscriber=function(t){this._subscribers.remove(t),0===this._subscribers.size()&&function(t){r.add(t)&&(o.push(t),s||(s=setTimeout(f,1e3)))}(this)},t._checkSubscribers=function(){0===this._subscribers.size()&&this.destroy()},Computed}();function j(t,n){return new Computed(t,n)}j.prop=j;var Observable=/*#__PURE__*/function(){function Observable(t,n){this._subscribers=new HashSet,this._value=t,this._checkValueFn=O(n)}var t=Observable.prototype;return t.get=function(){return w(this)||x(this),this._value},t.set=function(t){if(e.t instanceof Computed)throw new Error("Can't change observable value inside of computed");null!==this._checkValueFn&&this._checkValueFn(this._value,t)||(this._value=t,this.notify())},t.notify=function(){g(this,5,!0),0===e.i&&v()},t._removeSubscriber=function(t){this._subscribers.remove(t)},t._actualizeState=function(){},Observable}();function $(t,n){return new Observable(t,n)}$.prop=$;var Reaction=/*#__PURE__*/function(){function Reaction(t,n,i){this._hash=b(),this._reaction=t,this._context=n||null,this._manager=i,this._state=5,this._subscriptions=[],this._children=[];var r=e.t;null!==r&&r instanceof Reaction&&r._addChild(this)}var t=Reaction.prototype;return t._addChild=function(t){this._children.push(t)},t._destroyChildren=function(){this._children.length>0&&(this._children.forEach(function(t){return t._destroyByParent()}),this._children=[])},t._destroyByParent=function(){this._destroyChildren(),m(this),this._state=6},t._notify=function(t,r){this._state>=t||(4===t?function(t){i.push(t)}(r):5===t&&(this._state=t,function(t){n.push(t)}(this),this._destroyChildren()))},t._subscribeTo=function(t){this._subscriptions.push(t)},t.runManager=function(){return this._manager?(m(this),this._manager()):this.run()},t.run=function(){this._destroyChildren(),m(this);var t=e.t;e.t=this,++e.i;try{return this._state=3,this._reaction.apply(this._context,arguments)}finally{e.t=t,1===e.i&&v(),--e.i}},t.destroy=function(){this._destroyChildren(),m(this),this._state=5},Reaction}();function k(t,n,i){return new Reaction(t,n,i)}var C=Object.prototype.hasOwnProperty,E="undefined"!=typeof Symbol,S=E?Symbol("$$observables"):"$$observables",T=E?Symbol("$$observableKeys"):"$$observableKeys";exports.Computed=Computed,exports.Observable=Observable,exports.Reaction=Reaction,exports.action=function(t){return function(){var n=e.t;e.t=null,++e.i;try{return t.apply(this,arguments)}finally{0==--e.i&&v(),e.t=n}}},exports.asProp=function(t){return t},exports.computed=j,exports.fromGetter=function(t){var n=e.t;e.t=p;try{return t(),y}finally{e.t=n,y=void 0}},exports.makeObservable=function(t){var n=[];for(var i in t)if(C.call(t,i)){var r=Object.getOwnPropertyDescriptor(t,i);r.configurable&&void 0!==r.value&&function(){var t=r.value;t instanceof Observable?n.push({key:i,enumerable:!0,configurable:!0,get:function(){return t.get()},set:function(n){t.set(n)}}):t instanceof Computed&&n.push({key:i,enumerable:!0,configurable:!0,get:function(){return t.get()}})}()}return n.forEach(function(n){Object.defineProperty(t,n.key,n)}),t},exports.makeObservableProto=function(t,n,i){var r=n.prototype;if(!C.call(r,T)){var o=Object.keys(i);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(i);s.length>0&&(o=o.concat(s))}var e=o.map(function(t){var n=i[t];if(n instanceof Observable)return{key:t,enumerable:!0,configurable:!1,get:function(){return this[S][t].get()},set:function(n){this[S][t].set(n)}};if(n instanceof Computed)return{key:t,enumerable:!0,configurable:!1,get:function(){return this[S][t].get()}};throw new Error("Only instances of Observable or Computed are allowed")});E?r[T]=o:Object.defineProperty(r,T,{enumerable:!1,writable:!1,value:o}),e.forEach(function(t){Object.defineProperty(r,t.key,t)})}var u=t[S],f=Object.assign(u||{},i);u||(E?t[S]=f:Object.defineProperty(t,S,{enumerable:!1,writable:!1,value:f}))},exports.notify=function(t){var n=e.t;e.t=d;try{c(t)}finally{e.t=n}},exports.observable=$,exports.once=function(t,n){var i=k(function(){t()&&(i.destroy(),a(n))});return i.run(),i},exports.reaction=k,exports.tx=c,exports.untracked=l,exports.utx=a,exports.when=function(t,n){var i=k(function(){t()&&a(n)});return i.run(),i}; | ||
function t(t){for(var n=new Array(t),i=0;i<t;i++)n[i]=void 0;return n}var HashSet=/*#__PURE__*/function(){function HashSet(){this._items=t(4),this._size=0,this._maxSizeBeforeClear=0,this._isInIteration=!1}var n=HashSet.prototype;return n.add=function(t){if(this._isInIteration)return!1;for(var n=this._items,i=n.length,r=i-1,e=t._hash&r;void 0!==n[e]&&n[e]!==t;)e=e+1&r;return void 0===n[e]&&(n[e]=t,++this._size>11*i>>4&&this._rehashUp(2*i),this._maxSizeBeforeClear<this._size&&(this._maxSizeBeforeClear=this._size),!0)},n._rehashUp=function(n){var i=this._items,r=i.length;this._items=t(n),this._size=0;for(var e=0;e<r;e++){var o=i[e];void 0!==o&&this.add(o)}},n.remove=function(t){if(this._isInIteration)return!1;for(var n=this._items,i=n.length-1,r=t._hash&i;void 0!==n[r]&&n[r]!==t;)r=r+1&i;if(void 0!==n[r]){for(var e=r,o=1;;){var u=n[e=e+1&i];if(void 0===u){n[r]=void 0;break}(e-u._hash&i)>=o?(n[r]=u,r=e,o=1):o++}return this._size--,!0}return!1},n.size=function(){return this._size},n.forEach=function(t){this._isInIteration=!0;for(var n=this._items,i=n.length,r=0;r<i;r++){var e=n[r];void 0!==e&&t(e)}this._isInIteration=!1},n.clearAndResize=function(){for(var n=this._maxSizeBeforeClear,i=4;n>11*i>>4;)i*=2;if(4*i<this._items.length)this._items=t(i);else for(var r=this._items,e=r.length,o=0;o<e;o++)r[o]=void 0;this._size=0,this._maxSizeBeforeClear=0},HashSet}(),n=[],i=[],r=new HashSet,e=[],o=null,u={t:null,i:0},s={reactionScheduler:function(t){return t()},subscribersCheckInterval:1e3};function f(){for(var t;t=n.pop();)4===t._state&&t.runManager()}function h(){for(var t;t=e.pop();)r.remove(t),0===t._subscribers.size()&&t.destroy();o=null}function c(){for(var t;t=i.pop();)t._actualizeState()}function a(t){++u.i;try{t()}finally{0==--u.i&&y()}}function l(t){var n=u.t;u.t=null,++u.i;try{return t()}finally{0==--u.i&&y(),u.t=n}}function v(t){var n=u.t;u.t=null;try{return t()}finally{u.t=n}}var b=!1;function y(){!b&&p()&&(b=!0,s.reactionScheduler(d))}function p(){return n.length>0||i.length>0}function d(){for(;p();)c(),f();b=!1}function x(){return 1e9*Math.random()|0}var w=void 0,m={},g={};function j(t){var n=u.t;return n===m?(w=t,!0):n===g&&(t.notify(),!0)}function O(t){var n=u.t;null!==n&&t._subscribers.add(n)&&n._subscribeTo(t)}function k(t){t._subscriptions.forEach(function(n){n._removeSubscriber(t)}),t._subscriptions=[],t._maybeDirtySubscriptions&&(t._maybeDirtySubscriptions=null)}function $(t,n,i){t._subscribers.forEach(function(i){i._notify(n,t)}),i&&t._subscribers.clearAndResize()}var Computed=/*#__PURE__*/function(){function Computed(t,n){this._hash=x(),this._subscribers=new HashSet,this._value=void 0,this._options=function(t){var n={checkValueFn:null,keepAlive:!1};return t&&"object"==typeof t&&(t.checkValue&&"function"==typeof t.checkValue&&(n.checkValueFn=t.checkValue),n.keepAlive=!!t.keepAlive),n}(n),this._state=0,this._computer=t,this._subscriptions=[],this._maybeDirtySubscriptions=null}var t=Computed.prototype;return t.get=function(){if(1===this._state)throw new Error("Trying to get computed value while in computing state");return j(this)||(this._actualizeState(),O(this),null===u.t&&this._checkSubscribers()),this._value},t.destroy=function(){k(this),this._state=0,this._value=void 0},t._actualizeState=function(){var t;3===this._state&&((t=this)._maybeDirtySubscriptions.every(function(n){return n._actualizeState(),3===t._state})&&(t._state=2),t._maybeDirtySubscriptions=null),4!==this._state&&0!==this._state||this._recomputeAndCheckValue()},t._recomputeAndCheckValue=function(){var t=this,n=this._state,i=this._recomputeValue();if(null!==this._options.checkValueFn&&0!==n){if(v(function(){return t._options.checkValueFn(t._value,i)}))return;$(this,4,!0)}this._value=i},t._recomputeValue=function(){var t=u.t;u.t=this;var n=this._state;this._state=1;try{var i=this._computer();return this._state=2,i}catch(t){throw k(this),this._state=n,t}finally{u.t=t}},t._subscribeTo=function(t){this._subscriptions.push(t)},t._notify=function(t,n){this._state>=t||(null!==this._options.checkValueFn?2===this._state&&$(this,3,!1):$(this,t,4===t),this._state=t,3===t?function(t,n){(t._maybeDirtySubscriptions||(t._maybeDirtySubscriptions=[])).push(n)}(this,n):4===t&&k(this))},t._removeSubscriber=function(t){this._subscribers.remove(t),this._checkSubscribers()},t._checkSubscribers=function(){0!==this._subscribers.size()||this._options.keepAlive||function(t){r.add(t)&&(e.push(t),o||(o=setTimeout(h,s.subscribersCheckInterval)))}(this)},Computed}();function C(t,n){return new Computed(t,n)}C.prop=C;var Observable=/*#__PURE__*/function(){function Observable(t,n){this._subscribers=new HashSet,this._value=t,this._options=function(t){var n={checkValueFn:null};return t&&"object"==typeof t&&t.checkValue&&"function"==typeof t.checkValue&&(n.checkValueFn=t.checkValue),n}(n)}var t=Observable.prototype;return t.get=function(){return j(this)||O(this),this._value},t.set=function(t){if(u.t instanceof Computed)throw new Error("Can't change observable value inside of computed");null!==this._options.checkValueFn&&this._options.checkValueFn(this._value,t)||(this._value=t,this.notify())},t.notify=function(){$(this,4,!0),0===u.i&&y()},t._removeSubscriber=function(t){this._subscribers.remove(t)},Observable}();function S(t,n){return new Observable(t,n)}S.prop=S;var Reaction=/*#__PURE__*/function(){function Reaction(t,n,i){this._hash=x(),this._reaction=t,this._context=n||null,this._manager=i,this._state=4,this._subscriptions=[],this._children=[];var r=u.t;null!==r&&r instanceof Reaction&&r._addChild(this)}var t=Reaction.prototype;return t._addChild=function(t){this._children.push(t)},t._destroyChildren=function(){this._children.length>0&&(this._children.forEach(function(t){return t._destroyByParent()}),this._children=[])},t._destroyByParent=function(){this._destroyChildren(),k(this),this._state=5},t._notify=function(t,r){this._state>=t||(3===t?function(t){i.push(t)}(r):4===t&&(this._state=t,function(t){n.push(t)}(this),this._destroyChildren()))},t._subscribeTo=function(t){this._subscriptions.push(t)},t.runManager=function(){return this._manager?(k(this),this._manager()):this.run()},t.run=function(){this._destroyChildren(),k(this);var t=u.t;u.t=this,++u.i;try{return this._state=2,this._reaction.apply(this._context,arguments)}finally{u.t=t,1===u.i&&y(),--u.i}},t.destroy=function(){this._destroyChildren(),k(this),this._state=4},Reaction}();function E(t,n,i){return new Reaction(t,n,i)}var T=Object.prototype.hasOwnProperty,A="undefined"!=typeof Symbol,F=A?Symbol("$$observables"):"$$observables",K=A?Symbol("$$observableKeys"):"$$observableKeys";exports.Computed=Computed,exports.Observable=Observable,exports.Reaction=Reaction,exports.action=function(t){return function(){var n=u.t;u.t=null,++u.i;try{return t.apply(this,arguments)}finally{0==--u.i&&y(),u.t=n}}},exports.asProp=function(t){return t},exports.computed=C,exports.configure=function(t){t.reactionScheduler&&(s.reactionScheduler=t.reactionScheduler),t.subscribersCheckInterval&&(s.subscribersCheckInterval=t.subscribersCheckInterval)},exports.fromGetter=function(t){var n=u.t;u.t=m;try{return t(),w}finally{u.t=n,w=void 0}},exports.makeObservable=function(t){var n=[];for(var i in t)if(T.call(t,i)){var r=Object.getOwnPropertyDescriptor(t,i);r.configurable&&void 0!==r.value&&function(){var t=r.value;t instanceof Observable?n.push({key:i,enumerable:!0,configurable:!0,get:function(){return t.get()},set:function(n){t.set(n)}}):t instanceof Computed&&n.push({key:i,enumerable:!0,configurable:!0,get:function(){return t.get()}})}()}return n.forEach(function(n){Object.defineProperty(t,n.key,n)}),t},exports.makeObservableProto=function(t,n,i){var r=n.prototype;if(!T.call(r,K)){var e=Object.keys(i);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(i);o.length>0&&(e=e.concat(o))}var u=e.map(function(t){var n=i[t];if(n instanceof Observable)return{key:t,enumerable:!0,configurable:!1,get:function(){return this[F][t].get()},set:function(n){this[F][t].set(n)}};if(n instanceof Computed)return{key:t,enumerable:!0,configurable:!1,get:function(){return this[F][t].get()}};throw new Error("Only instances of Observable or Computed are allowed")});A?r[K]=e:Object.defineProperty(r,K,{enumerable:!1,writable:!1,value:e}),u.forEach(function(t){Object.defineProperty(r,t.key,t)})}var s=t[F],f=Object.assign(s||{},i);s||(A?t[F]=f:Object.defineProperty(t,F,{enumerable:!1,writable:!1,value:f}))},exports.notify=function(t){var n=u.t;u.t=g;try{a(t)}finally{u.t=n}},exports.observable=S,exports.once=function(t,n){var i=E(function(){t()&&(i.destroy(),l(n))});return i.run(),i},exports.reaction=E,exports.tx=a,exports.untracked=v,exports.utx=l,exports.when=function(t,n){var i=E(function(){t()&&l(n)});return i.run(),i}; | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((t||self).dipoleEs3={})}(this,function(t){function n(t){for(var n=new Array(t),i=0;i<t;i++)n[i]=void 0;return n}var HashSet=/*#__PURE__*/function(){function HashSet(){this._items=n(4),this._size=0,this._maxSizeBeforeClear=0,this._isInIteration=!1}var t=HashSet.prototype;return t.add=function(t){if(this._isInIteration)return!1;for(var n=this._items,i=n.length,r=i-1,u=t._hash&r;void 0!==n[u]&&n[u]!==t;)u=u+1&r;return void 0===n[u]&&(n[u]=t,++this._size>11*i>>4&&this._rehashUp(2*i),this._maxSizeBeforeClear<this._size&&(this._maxSizeBeforeClear=this._size),!0)},t._rehashUp=function(t){var i=this._items,r=i.length;this._items=n(t),this._size=0;for(var u=0;u<r;u++){var o=i[u];void 0!==o&&this.add(o)}},t.remove=function(t){if(this._isInIteration)return!1;for(var n=this._items,i=n.length-1,r=t._hash&i;void 0!==n[r]&&n[r]!==t;)r=r+1&i;if(void 0!==n[r]){for(var u=r,o=1;;){var e=n[u=u+1&i];if(void 0===e){n[r]=void 0;break}(u-e._hash&i)>=o?(n[r]=e,r=u,o=1):o++}return this._size--,!0}return!1},t.size=function(){return this._size},t.forEach=function(t){this._isInIteration=!0;for(var n=this._items,i=n.length,r=0;r<i;r++){var u=n[r];void 0!==u&&t(u)}this._isInIteration=!1},t.clearAndResize=function(){for(var t=this._maxSizeBeforeClear,i=4;t>11*i>>4;)i*=2;if(4*i<this._items.length)this._items=n(i);else for(var r=this._items,u=r.length,o=0;o<u;o++)r[o]=void 0;this._size=0,this._maxSizeBeforeClear=0},HashSet}(),i=[],r=[],u=new HashSet,o=[],e=null,s={t:null,i:0};function f(){for(var t;t=i.pop();)5===t._state&&t.runManager()}function h(){for(var t;t=o.pop();)u.remove(t),t._checkSubscribers();e=null}function c(){for(var t;t=r.pop();)t._actualizeState()}function a(t){++s.i;try{t()}finally{0==--s.i&&b()}}function l(t){var n=s.t;s.t=null,++s.i;try{return t()}finally{0==--s.i&&b(),s.t=n}}function v(t){var n=s.t;s.t=null;try{return t()}finally{s.t=n}}function b(){for(;r.length>0||i.length>0;)c(),f()}function y(){return 1e9*Math.random()|0}var d=void 0,w={},g={};function m(t){var n=s.t;return n===w?(d=t,!0):n===g&&(t.notify(),!0)}function p(t){var n=s.t;null!==n&&t._subscribers.add(n)&&n._subscribeTo(t)}function j(t){t._subscriptions.forEach(function(n){n._removeSubscriber(t)}),t._subscriptions=[],t._maybeDirtySubscriptions&&(t._maybeDirtySubscriptions=null)}function O(t,n,i){t._subscribers.forEach(function(i){i._notify(n,t)}),i&&t._subscribers.clearAndResize()}function $(t){if(t&&"object"==typeof t){var n=t.checkValue;if("function"==typeof n)return n}return null}var Computed=/*#__PURE__*/function(){function Computed(t,n){this._hash=y(),this._subscribers=new HashSet,this._value=void 0,this._checkValueFn=$(n),this._state=0,this._computer=t,this._subscriptions=[],this._maybeDirtySubscriptions=null}var t=Computed.prototype;return t.get=function(){if(2===this._state)throw new Error("Trying to get computed value while in computing state");return m(this)||(this._actualizeState(),p(this)),this._value},t.destroy=function(){j(this),this._state=0},t._actualizeState=function(){4===this._state&&function(t){t._maybeDirtySubscriptions.every(function(n){return n._actualizeState(),4===t._state})&&(t._state=3),t._maybeDirtySubscriptions=null}(this),5!==this._state&&0!==this._state||this._recomputeAndCheckValue()},t._recomputeAndCheckValue=function(){var t=this,n=this._state,i=this._recomputeValue();if(null!==this._checkValueFn&&0!==n){if(v(function(){return t._checkValueFn(t._value,i)}))return;O(this,5,!0)}this._value=i},t._recomputeValue=function(){var t=s.t;s.t=this;var n=this._state;this._state=2;try{var i=this._computer();return this._state=3,i}catch(t){throw j(this),this._state=n,t}finally{s.t=t}},t._subscribeTo=function(t){this._subscriptions.push(t)},t._notify=function(t,n){this._state>=t||(null!==this._checkValueFn?3===this._state&&O(this,4,!1):O(this,t,5===t),this._state=t,4===t?function(t,n){(t._maybeDirtySubscriptions||(t._maybeDirtySubscriptions=[])).push(n)}(this,n):5===t&&j(this))},t._removeSubscriber=function(t){this._subscribers.remove(t),0===this._subscribers.size()&&function(t){u.add(t)&&(o.push(t),e||(e=setTimeout(h,1e3)))}(this)},t._checkSubscribers=function(){0===this._subscribers.size()&&this.destroy()},Computed}();function k(t,n){return new Computed(t,n)}k.prop=k;var Observable=/*#__PURE__*/function(){function Observable(t,n){this._subscribers=new HashSet,this._value=t,this._checkValueFn=$(n)}var t=Observable.prototype;return t.get=function(){return m(this)||p(this),this._value},t.set=function(t){if(s.t instanceof Computed)throw new Error("Can't change observable value inside of computed");null!==this._checkValueFn&&this._checkValueFn(this._value,t)||(this._value=t,this.notify())},t.notify=function(){O(this,5,!0),0===s.i&&b()},t._removeSubscriber=function(t){this._subscribers.remove(t)},t._actualizeState=function(){},Observable}();function T(t,n){return new Observable(t,n)}T.prop=T;var Reaction=/*#__PURE__*/function(){function Reaction(t,n,i){this._hash=y(),this._reaction=t,this._context=n||null,this._manager=i,this._state=5,this._subscriptions=[],this._children=[];var r=s.t;null!==r&&r instanceof Reaction&&r._addChild(this)}var t=Reaction.prototype;return t._addChild=function(t){this._children.push(t)},t._destroyChildren=function(){this._children.length>0&&(this._children.forEach(function(t){return t._destroyByParent()}),this._children=[])},t._destroyByParent=function(){this._destroyChildren(),j(this),this._state=6},t._notify=function(t,n){this._state>=t||(4===t?function(t){r.push(t)}(n):5===t&&(this._state=t,function(t){i.push(t)}(this),this._destroyChildren()))},t._subscribeTo=function(t){this._subscriptions.push(t)},t.runManager=function(){return this._manager?(j(this),this._manager()):this.run()},t.run=function(){this._destroyChildren(),j(this);var t=s.t;s.t=this,++s.i;try{return this._state=3,this._reaction.apply(this._context,arguments)}finally{s.t=t,1===s.i&&b(),--s.i}},t.destroy=function(){this._destroyChildren(),j(this),this._state=5},Reaction}();function x(t,n,i){return new Reaction(t,n,i)}var C=Object.prototype.hasOwnProperty,E="undefined"!=typeof Symbol,S=E?Symbol("$$observables"):"$$observables",K=E?Symbol("$$observableKeys"):"$$observableKeys";t.Computed=Computed,t.Observable=Observable,t.Reaction=Reaction,t.action=function(t){return function(){var n=s.t;s.t=null,++s.i;try{return t.apply(this,arguments)}finally{0==--s.i&&b(),s.t=n}}},t.asProp=function(t){return t},t.computed=k,t.fromGetter=function(t){var n=s.t;s.t=w;try{return t(),d}finally{s.t=n,d=void 0}},t.makeObservable=function(t){var n=[];for(var i in t)if(C.call(t,i)){var r=Object.getOwnPropertyDescriptor(t,i);r.configurable&&void 0!==r.value&&function(){var t=r.value;t instanceof Observable?n.push({key:i,enumerable:!0,configurable:!0,get:function(){return t.get()},set:function(n){t.set(n)}}):t instanceof Computed&&n.push({key:i,enumerable:!0,configurable:!0,get:function(){return t.get()}})}()}return n.forEach(function(n){Object.defineProperty(t,n.key,n)}),t},t.makeObservableProto=function(t,n,i){var r=n.prototype;if(!C.call(r,K)){var u=Object.keys(i);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(i);o.length>0&&(u=u.concat(o))}var e=u.map(function(t){var n=i[t];if(n instanceof Observable)return{key:t,enumerable:!0,configurable:!1,get:function(){return this[S][t].get()},set:function(n){this[S][t].set(n)}};if(n instanceof Computed)return{key:t,enumerable:!0,configurable:!1,get:function(){return this[S][t].get()}};throw new Error("Only instances of Observable or Computed are allowed")});E?r[K]=u:Object.defineProperty(r,K,{enumerable:!1,writable:!1,value:u}),e.forEach(function(t){Object.defineProperty(r,t.key,t)})}var s=t[S],f=Object.assign(s||{},i);s||(E?t[S]=f:Object.defineProperty(t,S,{enumerable:!1,writable:!1,value:f}))},t.notify=function(t){var n=s.t;s.t=g;try{a(t)}finally{s.t=n}},t.observable=T,t.once=function(t,n){var i=x(function(){t()&&(i.destroy(),l(n))});return i.run(),i},t.reaction=x,t.tx=a,t.untracked=v,t.utx=l,t.when=function(t,n){var i=x(function(){t()&&l(n)});return i.run(),i}}); | ||
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((t||self).dipoleEs3={})}(this,function(t){function n(t){for(var n=new Array(t),i=0;i<t;i++)n[i]=void 0;return n}var HashSet=/*#__PURE__*/function(){function HashSet(){this._items=n(4),this._size=0,this._maxSizeBeforeClear=0,this._isInIteration=!1}var t=HashSet.prototype;return t.add=function(t){if(this._isInIteration)return!1;for(var n=this._items,i=n.length,r=i-1,e=t._hash&r;void 0!==n[e]&&n[e]!==t;)e=e+1&r;return void 0===n[e]&&(n[e]=t,++this._size>11*i>>4&&this._rehashUp(2*i),this._maxSizeBeforeClear<this._size&&(this._maxSizeBeforeClear=this._size),!0)},t._rehashUp=function(t){var i=this._items,r=i.length;this._items=n(t),this._size=0;for(var e=0;e<r;e++){var u=i[e];void 0!==u&&this.add(u)}},t.remove=function(t){if(this._isInIteration)return!1;for(var n=this._items,i=n.length-1,r=t._hash&i;void 0!==n[r]&&n[r]!==t;)r=r+1&i;if(void 0!==n[r]){for(var e=r,u=1;;){var o=n[e=e+1&i];if(void 0===o){n[r]=void 0;break}(e-o._hash&i)>=u?(n[r]=o,r=e,u=1):u++}return this._size--,!0}return!1},t.size=function(){return this._size},t.forEach=function(t){this._isInIteration=!0;for(var n=this._items,i=n.length,r=0;r<i;r++){var e=n[r];void 0!==e&&t(e)}this._isInIteration=!1},t.clearAndResize=function(){for(var t=this._maxSizeBeforeClear,i=4;t>11*i>>4;)i*=2;if(4*i<this._items.length)this._items=n(i);else for(var r=this._items,e=r.length,u=0;u<e;u++)r[u]=void 0;this._size=0,this._maxSizeBeforeClear=0},HashSet}(),i=[],r=[],e=new HashSet,u=[],o=null,s={t:null,i:0},f={reactionScheduler:function(t){return t()},subscribersCheckInterval:1e3};function h(){for(var t;t=i.pop();)4===t._state&&t.runManager()}function c(){for(var t;t=u.pop();)e.remove(t),0===t._subscribers.size()&&t.destroy();o=null}function a(){for(var t;t=r.pop();)t._actualizeState()}function l(t){++s.i;try{t()}finally{0==--s.i&&d()}}function v(t){var n=s.t;s.t=null,++s.i;try{return t()}finally{0==--s.i&&d(),s.t=n}}function b(t){var n=s.t;s.t=null;try{return t()}finally{s.t=n}}var y=!1;function d(){!y&&p()&&(y=!0,f.reactionScheduler(w))}function p(){return i.length>0||r.length>0}function w(){for(;p();)a(),h();y=!1}function g(){return 1e9*Math.random()|0}var m=void 0,j={},O={};function k(t){var n=s.t;return n===j?(m=t,!0):n===O&&(t.notify(),!0)}function $(t){var n=s.t;null!==n&&t._subscribers.add(n)&&n._subscribeTo(t)}function C(t){t._subscriptions.forEach(function(n){n._removeSubscriber(t)}),t._subscriptions=[],t._maybeDirtySubscriptions&&(t._maybeDirtySubscriptions=null)}function T(t,n,i){t._subscribers.forEach(function(i){i._notify(n,t)}),i&&t._subscribers.clearAndResize()}var Computed=/*#__PURE__*/function(){function Computed(t,n){this._hash=g(),this._subscribers=new HashSet,this._value=void 0,this._options=function(t){var n={checkValueFn:null,keepAlive:!1};return t&&"object"==typeof t&&(t.checkValue&&"function"==typeof t.checkValue&&(n.checkValueFn=t.checkValue),n.keepAlive=!!t.keepAlive),n}(n),this._state=0,this._computer=t,this._subscriptions=[],this._maybeDirtySubscriptions=null}var t=Computed.prototype;return t.get=function(){if(1===this._state)throw new Error("Trying to get computed value while in computing state");return k(this)||(this._actualizeState(),$(this),null===s.t&&this._checkSubscribers()),this._value},t.destroy=function(){C(this),this._state=0,this._value=void 0},t._actualizeState=function(){3===this._state&&function(t){t._maybeDirtySubscriptions.every(function(n){return n._actualizeState(),3===t._state})&&(t._state=2),t._maybeDirtySubscriptions=null}(this),4!==this._state&&0!==this._state||this._recomputeAndCheckValue()},t._recomputeAndCheckValue=function(){var t=this,n=this._state,i=this._recomputeValue();if(null!==this._options.checkValueFn&&0!==n){if(b(function(){return t._options.checkValueFn(t._value,i)}))return;T(this,4,!0)}this._value=i},t._recomputeValue=function(){var t=s.t;s.t=this;var n=this._state;this._state=1;try{var i=this._computer();return this._state=2,i}catch(t){throw C(this),this._state=n,t}finally{s.t=t}},t._subscribeTo=function(t){this._subscriptions.push(t)},t._notify=function(t,n){this._state>=t||(null!==this._options.checkValueFn?2===this._state&&T(this,3,!1):T(this,t,4===t),this._state=t,3===t?function(t,n){(t._maybeDirtySubscriptions||(t._maybeDirtySubscriptions=[])).push(n)}(this,n):4===t&&C(this))},t._removeSubscriber=function(t){this._subscribers.remove(t),this._checkSubscribers()},t._checkSubscribers=function(){0!==this._subscribers.size()||this._options.keepAlive||function(t){e.add(t)&&(u.push(t),o||(o=setTimeout(c,f.subscribersCheckInterval)))}(this)},Computed}();function x(t,n){return new Computed(t,n)}x.prop=x;var Observable=/*#__PURE__*/function(){function Observable(t,n){this._subscribers=new HashSet,this._value=t,this._options=function(t){var n={checkValueFn:null};return t&&"object"==typeof t&&t.checkValue&&"function"==typeof t.checkValue&&(n.checkValueFn=t.checkValue),n}(n)}var t=Observable.prototype;return t.get=function(){return k(this)||$(this),this._value},t.set=function(t){if(s.t instanceof Computed)throw new Error("Can't change observable value inside of computed");null!==this._options.checkValueFn&&this._options.checkValueFn(this._value,t)||(this._value=t,this.notify())},t.notify=function(){T(this,4,!0),0===s.i&&d()},t._removeSubscriber=function(t){this._subscribers.remove(t)},Observable}();function S(t,n){return new Observable(t,n)}S.prop=S;var Reaction=/*#__PURE__*/function(){function Reaction(t,n,i){this._hash=g(),this._reaction=t,this._context=n||null,this._manager=i,this._state=4,this._subscriptions=[],this._children=[];var r=s.t;null!==r&&r instanceof Reaction&&r._addChild(this)}var t=Reaction.prototype;return t._addChild=function(t){this._children.push(t)},t._destroyChildren=function(){this._children.length>0&&(this._children.forEach(function(t){return t._destroyByParent()}),this._children=[])},t._destroyByParent=function(){this._destroyChildren(),C(this),this._state=5},t._notify=function(t,n){this._state>=t||(3===t?function(t){r.push(t)}(n):4===t&&(this._state=t,function(t){i.push(t)}(this),this._destroyChildren()))},t._subscribeTo=function(t){this._subscriptions.push(t)},t.runManager=function(){return this._manager?(C(this),this._manager()):this.run()},t.run=function(){this._destroyChildren(),C(this);var t=s.t;s.t=this,++s.i;try{return this._state=2,this._reaction.apply(this._context,arguments)}finally{s.t=t,1===s.i&&d(),--s.i}},t.destroy=function(){this._destroyChildren(),C(this),this._state=4},Reaction}();function E(t,n,i){return new Reaction(t,n,i)}var A=Object.prototype.hasOwnProperty,F="undefined"!=typeof Symbol,K=F?Symbol("$$observables"):"$$observables",V=F?Symbol("$$observableKeys"):"$$observableKeys";t.Computed=Computed,t.Observable=Observable,t.Reaction=Reaction,t.action=function(t){return function(){var n=s.t;s.t=null,++s.i;try{return t.apply(this,arguments)}finally{0==--s.i&&d(),s.t=n}}},t.asProp=function(t){return t},t.computed=x,t.configure=function(t){t.reactionScheduler&&(f.reactionScheduler=t.reactionScheduler),t.subscribersCheckInterval&&(f.subscribersCheckInterval=t.subscribersCheckInterval)},t.fromGetter=function(t){var n=s.t;s.t=j;try{return t(),m}finally{s.t=n,m=void 0}},t.makeObservable=function(t){var n=[];for(var i in t)if(A.call(t,i)){var r=Object.getOwnPropertyDescriptor(t,i);r.configurable&&void 0!==r.value&&function(){var t=r.value;t instanceof Observable?n.push({key:i,enumerable:!0,configurable:!0,get:function(){return t.get()},set:function(n){t.set(n)}}):t instanceof Computed&&n.push({key:i,enumerable:!0,configurable:!0,get:function(){return t.get()}})}()}return n.forEach(function(n){Object.defineProperty(t,n.key,n)}),t},t.makeObservableProto=function(t,n,i){var r=n.prototype;if(!A.call(r,V)){var e=Object.keys(i);if(Object.getOwnPropertySymbols){var u=Object.getOwnPropertySymbols(i);u.length>0&&(e=e.concat(u))}var o=e.map(function(t){var n=i[t];if(n instanceof Observable)return{key:t,enumerable:!0,configurable:!1,get:function(){return this[K][t].get()},set:function(n){this[K][t].set(n)}};if(n instanceof Computed)return{key:t,enumerable:!0,configurable:!1,get:function(){return this[K][t].get()}};throw new Error("Only instances of Observable or Computed are allowed")});F?r[V]=e:Object.defineProperty(r,V,{enumerable:!1,writable:!1,value:e}),o.forEach(function(t){Object.defineProperty(r,t.key,t)})}var s=t[K],f=Object.assign(s||{},i);s||(F?t[K]=f:Object.defineProperty(t,K,{enumerable:!1,writable:!1,value:f}))},t.notify=function(t){var n=s.t;s.t=O;try{l(t)}finally{s.t=n}},t.observable=S,t.once=function(t,n){var i=E(function(){t()&&(i.destroy(),v(n))});return i.run(),i},t.reaction=E,t.tx=l,t.untracked=b,t.utx=v,t.when=function(t,n){var i=E(function(){t()&&v(n)});return i.run(),i}}); | ||
//# sourceMappingURL=index.umd.js.map |
{ | ||
"name": "dipole-es3", | ||
"version": "2.2.8", | ||
"version": "2.2.9", | ||
"description": "dipole - tiny reactive state management that just works", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -53,11 +53,1 @@ import { glob } from "../globals"; | ||
} | ||
export function getCheckValueFn(options) { | ||
if (options && typeof options === "object") { | ||
const checkValueFn = options.checkValue; | ||
if (typeof checkValueFn === "function") { | ||
return checkValueFn; | ||
} | ||
} | ||
return null; | ||
} |
@@ -7,3 +7,2 @@ import { states } from "../constants"; | ||
import { | ||
getCheckValueFn, | ||
checkSpecialContexts, | ||
@@ -16,2 +15,18 @@ trackComputedContext, | ||
function getComputedOptions(options) { | ||
const defaultOptions = { | ||
checkValueFn: null, | ||
keepAlive: false, | ||
}; | ||
if (options && typeof options === "object") { | ||
if (options.checkValue && typeof options.checkValue === "function") { | ||
defaultOptions.checkValueFn = options.checkValue; | ||
} | ||
defaultOptions.keepAlive = !!options.keepAlive; | ||
} | ||
return defaultOptions; | ||
} | ||
function actualizeState(self) { | ||
@@ -36,3 +51,3 @@ const actualizedAndNotNotified = (subscription) => { | ||
this._value = undefined; | ||
this._checkValueFn = getCheckValueFn(options); | ||
this._options = getComputedOptions(options); | ||
this._state = states.NOT_INITIALIZED; | ||
@@ -52,2 +67,6 @@ this._computer = computer; | ||
trackComputedContext(this); | ||
if (glob.gComputedContext === null) { | ||
this._checkSubscribers(); | ||
} | ||
} | ||
@@ -61,2 +80,3 @@ | ||
this._state = states.NOT_INITIALIZED; | ||
this._value = undefined; | ||
} | ||
@@ -78,4 +98,4 @@ | ||
if (this._checkValueFn !== null && stateBefore !== states.NOT_INITIALIZED) { | ||
const isSameValue = untracked(() => this._checkValueFn(this._value, value)); | ||
if (this._options.checkValueFn !== null && stateBefore !== states.NOT_INITIALIZED) { | ||
const isSameValue = untracked(() => this._options.checkValueFn(this._value, value)); | ||
@@ -119,3 +139,3 @@ if (isSameValue) return; | ||
if (this._checkValueFn !== null) { | ||
if (this._options.checkValueFn !== null) { | ||
if (this._state === states.CLEAN) { | ||
@@ -139,11 +159,8 @@ notifySubscribers(this, states.MAYBE_DIRTY, false); | ||
this._subscribers.remove(subscriber); | ||
if (this._subscribers.size() === 0) { | ||
scheduleSubscribersCheck(this); | ||
} | ||
this._checkSubscribers(); | ||
} | ||
_checkSubscribers() { | ||
if (this._subscribers.size() === 0) { | ||
this.destroy(); | ||
if (this._subscribers.size() === 0 && !this._options.keepAlive) { | ||
scheduleSubscribersCheck(this); | ||
} | ||
@@ -150,0 +167,0 @@ } |
@@ -5,10 +5,19 @@ import { glob } from "../globals"; | ||
import { Computed } from "./computed"; | ||
import { | ||
getCheckValueFn, | ||
checkSpecialContexts, | ||
trackComputedContext, | ||
notifySubscribers, | ||
} from "./common"; | ||
import { HashSet } from "../data-structures/hash-set"; | ||
import { checkSpecialContexts, trackComputedContext, notifySubscribers } from "./common"; | ||
function getObservableOptions(options) { | ||
const defaultOptions = { | ||
checkValueFn: null, | ||
}; | ||
if (options && typeof options === "object") { | ||
if (options.checkValue && typeof options.checkValue === "function") { | ||
defaultOptions.checkValueFn = options.checkValue; | ||
} | ||
} | ||
return defaultOptions; | ||
} | ||
export class Observable { | ||
@@ -18,3 +27,3 @@ constructor(value, options) { | ||
this._value = value; | ||
this._checkValueFn = getCheckValueFn(options); | ||
this._options = getObservableOptions(options); | ||
} | ||
@@ -34,3 +43,3 @@ | ||
if (this._checkValueFn !== null && this._checkValueFn(this._value, value)) { | ||
if (this._options.checkValueFn !== null && this._options.checkValueFn(this._value, value)) { | ||
return; | ||
@@ -55,6 +64,2 @@ } | ||
} | ||
_actualizeState() { | ||
// no op | ||
} | ||
} | ||
@@ -61,0 +66,0 @@ |
export const states = { | ||
NOT_INITIALIZED: 0, | ||
NOTIFYING: 1, | ||
COMPUTING: 2, | ||
CLEAN: 3, | ||
MAYBE_DIRTY: 4, | ||
DIRTY: 5, | ||
DESTROYED_BY_PARENT: 6, | ||
COMPUTING: 1, | ||
CLEAN: 2, | ||
MAYBE_DIRTY: 3, | ||
DIRTY: 4, | ||
DESTROYED_BY_PARENT: 5, | ||
}; | ||
export const SCHEDULED_SUBSCRIBERS_CHECK_INTERVAL = 1000; |
@@ -15,2 +15,16 @@ import { SCHEDULED_SUBSCRIBERS_CHECK_INTERVAL, states } from "./constants"; | ||
export const gConfig = { | ||
reactionScheduler: (runner) => runner(), | ||
subscribersCheckInterval: SCHEDULED_SUBSCRIBERS_CHECK_INTERVAL, | ||
}; | ||
export function configure(config) { | ||
if (config.reactionScheduler) { | ||
gConfig.reactionScheduler = config.reactionScheduler; | ||
} | ||
if (config.subscribersCheckInterval) { | ||
gConfig.subscribersCheckInterval = config.subscribersCheckInterval; | ||
} | ||
} | ||
// Work queues functions | ||
@@ -41,3 +55,3 @@ | ||
runScheduledSubscribersChecks, | ||
SCHEDULED_SUBSCRIBERS_CHECK_INTERVAL | ||
gConfig.subscribersCheckInterval | ||
); | ||
@@ -52,3 +66,6 @@ } | ||
gScheduledSubscribersChecks.remove(computed); | ||
computed._checkSubscribers(); | ||
if (computed._subscribers.size() === 0) { | ||
computed.destroy(); | ||
} | ||
} | ||
@@ -55,0 +72,0 @@ gScheduledSubscribersCheckTimeout = null; |
@@ -7,2 +7,3 @@ import { | ||
hasScheduledReactions, | ||
gConfig, | ||
} from "./globals"; | ||
@@ -67,7 +68,21 @@ | ||
let isReactionRunnerScheduled = false; | ||
export function endTransaction() { | ||
while (hasScheduledStateActualizations() || hasScheduledReactions()) { | ||
if (!isReactionRunnerScheduled && shouldRunReactionLoop()) { | ||
isReactionRunnerScheduled = true; | ||
gConfig.reactionScheduler(reactionRunner); | ||
} | ||
} | ||
function shouldRunReactionLoop() { | ||
return hasScheduledReactions() || hasScheduledStateActualizations(); | ||
} | ||
function reactionRunner() { | ||
while (shouldRunReactionLoop()) { | ||
runScheduledStateActualizations(); | ||
runScheduledReactions(); | ||
} | ||
isReactionRunnerScheduled = false; | ||
} |
declare module "dipole" { | ||
interface IConfig { | ||
reactionScheduler?: (runner: () => void) => void; | ||
subscribersCheckInterval?: number; | ||
} | ||
export function configure(config: IConfig): void; | ||
export interface IObservableOptions<T> { | ||
@@ -8,2 +15,3 @@ checkValue?: (prevValue: T, nextValue: T) => boolean; | ||
checkValue?: (prevValue: T, nextValue: T) => boolean; | ||
keepAlive?: boolean; | ||
} | ||
@@ -10,0 +18,0 @@ |
@@ -5,4 +5,5 @@ export * from "./core/classes"; | ||
export { fromGetter, notify } from "./core/extras"; | ||
export { configure } from "./core/globals"; | ||
export * from "./utils/observable"; | ||
export * from "./utils/reaction"; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
173788
967