Comparing version 0.0.0-rc.1 to 0.0.0-rc.2
@@ -1,2 +0,2 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).doura={})}(this,(function(t){"use strict";var e=function(){},n=Object.create(null),i=Object.assign,r=Object.prototype.hasOwnProperty,s=function(t,e){return r.call(t,e)},o=Object.prototype.toString,a=function(t){return o.call(t)},c=Array.isArray,u=function(t){return"[object Map]"===a(t)},f=function(t){return"[object Set]"===a(t)},h=function(t){return"string"==typeof t},l=function(t){return"symbol"==typeof t},p=function(t){return null!==t&&"object"==typeof t},v=function(t){return a(t).slice(8,-1)},d=function(t){return"[object Object]"===a(t)},y=function(t){return h(t)&&"NaN"!==t&&"-"!==t[0]&&""+parseInt(t,10)===t},g=function(t,e){return Object.is(t,e)},b=function(t){var e=Object.create(null);return function(t){return e[t]||(e[t]=function(t){return t.charAt(0).toUpperCase()+t.slice(1)}(t))}}(),_=Array.prototype.slice;function w(t){if(Array.isArray(t))return _.call(t);for(var e=Object.getOwnPropertyDescriptors(t),n=Reflect.ownKeys(e),i=0;i<n.length;i++){var r=n[i],s=e[r];!1===s.writable&&(s.writable=!0,s.configurable=!0),(s.get||s.set)&&(e[r]={configurable:!0,writable:!0,enumerable:s.enumerable,value:t[r]})}return Object.create(Object.getPrototypeOf(t),e)}var m,S="undefined"!=typeof Reflect&&Reflect.ownKeys?Reflect.ownKeys:void 0!==Object.getOwnPropertySymbols?function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:Object.getOwnPropertyNames,O=((m={})[0]="scheduler flush. This is likely a Doura internals bug. Please open an issue at https://github.com/dourajs/doura/issues/new",m);function j(t,e){for(var n=O[e],i=arguments.length,r=new Array(i>2?i-2:0),s=2;s<i;s++)r[s-2]=arguments[s];var o=n?"function"==typeof n?n.apply(null,r):n:"unknown error nr: "+j;throw new Error("[Doura] "+o)}var x=!1,P=!1,R=[],I=0,A=[],M=null,k=0,C=[],T=null,N=0,E=Promise.resolve(),$=null,D=null;function V(t,e){if(void 0===e&&(e=null),A.length){for(D=e,M=[].concat(new Set(A)),A.length=0,k=0;k<M.length;k++)M[k]();M=null,k=0,D=null,V(t,e)}}var L,K=function(t){return null==t.id?Infinity:t.id};function F(t){P=!1,x=!0,V(t),R.sort((function(t,e){return K(t)-K(e)}));try{for(I=0;I<R.length;I++){var e=R[I];if(e&&!1!==e.active)try{e()}catch(t){j(t,0)}}}finally{I=0,R.length=0,function(t){if(V(),C.length){var e,n=[].concat(new Set(C));if(C.length=0,T)return void(e=T).push.apply(e,n);for((T=n).sort((function(t,e){return K(t)-K(e)})),N=0;N<T.length;N++)T[N]();T=null,N=0}}(),x=!1,$=null,(R.length||A.length||C.length)&&F(t)}}function W(){return W=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(t[i]=n[i])}return t},W.apply(this,arguments)}function z(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,i=new Array(e);n<e;n++)i[n]=t[n];return i}function H(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(n)return(n=n.call(t)).next.bind(n);if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return z(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?z(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var i=0;return function(){return i>=t.length?{done:!0}:{done:!1,value:t[i++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var U,q=function(){function t(t){void 0===t&&(t=!1),this.active=!0,this.effects=[],this.cleanups=[],this.parent=void 0,this.scopes=void 0,this.index=void 0,!t&&L&&(this.parent=L,this.index=(L.scopes||(L.scopes=[])).push(this)-1)}var e=t.prototype;return e.run=function(t){if(this.active){var e=L;try{return L=this,t()}finally{L=e}}},e.on=function(){L=this},e.off=function(){L=this.parent},e.stop=function(t){if(this.active){var e,n;for(e=0,n=this.effects.length;e<n;e++)this.effects[e].stop();for(e=0,n=this.cleanups.length;e<n;e++)this.cleanups[e]();if(this.scopes)for(e=0,n=this.scopes.length;e<n;e++)this.scopes[e].stop(!0);if(this.parent&&!t){var i=this.parent.scopes.pop();i&&i!==this&&(this.parent.scopes[this.index]=i,i.index=this.index)}this.active=!1}},t}(),B=function(t){var e=new Set(t);return e.w=0,e.n=0,e},G=function(t){return(t.w&Z)>0},J=function(t){return(t.n&Z)>0},Q=new WeakMap,X=new WeakMap,Y=0,Z=1,tt=Symbol(""),et=Symbol(""),nt=0,it=function(){function t(t,e,n){void 0===e&&(e=null),this.fn=void 0,this.scheduler=void 0,this.id=nt++,this.deps=[],this.active=!0,this.parent=void 0,this.view=void 0,this.allowRecurse=void 0,this.deferStop=void 0,this.onStop=void 0,this.fn=t,this.scheduler=e,function(t,e){void 0===e&&(e=L),e&&e.active&&e.effects.push(t)}(this,n)}var e=t.prototype;return e.run=function(){if(!this.active)return this.fn();for(var t=U,e=st;t;){if(t===this)return;t=t.parent}try{return this.parent=U,U=this,st=!0,Z=1<<++Y,Y<=30?function(t){var e=t.deps;if(e.length)for(var n=0;n<e.length;n++)e[n].w|=Z}(this):rt(this),this.fn()}finally{Y<=30&&function(t){var e=t.deps;if(e.length){for(var n=0,i=0;i<e.length;i++){var r=e[i];G(r)&&!J(r)?r.delete(t):e[n++]=r,r.w&=~Z,r.n&=~Z}e.length=n}}(this),Z=1<<--Y,U=this.parent,st=e,this.parent=void 0,this.deferStop&&this.stop()}},e.stop=function(){U===this?this.deferStop=!0:this.active&&(rt(this),this.onStop&&this.onStop(),this.active=!1)},t}();function rt(t){var e=t.deps;if(e.length){for(var n=0;n<e.length;n++)e[n].delete(t);e.length=0}}var st=!0,ot=[];function at(){ot.push(st),st=!1}function ct(){var t=ot.pop();st=void 0===t||t}function ut(t,e,n,i){if(st&&U){var r=Q.get(t);r||Q.set(t,r=new Map);var s=r.get(n);s||r.set(n,s=B()),ht(s)}}function ft(t){if(st&&U){var e=X.get(t);e||X.set(t,e=B()),ht(e)}}function ht(t){var e=!1;Y<=30?J(t)||(t.n|=Z,e=!G(t)):e=!t.has(U),e&&(t.add(U),U.deps.push(t))}function lt(t,e,n,i,r,s){var o,a=Q.get(t),f=t.base,h=[];if(a)if("clear"===e)h=[].concat(a.values());else if("length"===n&&c(f))a.forEach((function(t,e){("length"===e||e>=i)&&h.push(t)}));else switch(void 0!==n&&h.push(a.get(n)),e){case"add":c(f)?y(n)&&h.push(a.get("length")):(h.push(a.get(tt)),u(f)&&h.push(a.get(et)));break;case"delete":c(f)||(h.push(a.get(tt)),u(f)&&h.push(a.get(et)));break;case"set":u(f)&&h.push(a.get(tt))}if(1===h.length)h[0]&&pt(h[0]);else{for(var l,p=[],v=H(h);!(l=v()).done;){var d=l.value;d&&p.push.apply(p,d)}pt(B(p))}var g=null==(o=t.root)?void 0:o.listeners;g&&g.length&&g.forEach((function(t){return t()}))}function pt(t){for(var e,n=c(t)?t:[].concat(t),i=H(n);!(e=i()).done;){var r=e.value;r.view&&vt(r)}for(var s,o=H(n);!(s=o()).done;){var a=s.value;a.view||vt(a)}}function vt(t){(t!==U||t.allowRecurse)&&(t.scheduler?t.scheduler():t.run())}function dt(t){return!!t&&!!t.__r_state}function yt(t){var e=gt(t);return e?yt(e.base):t}function gt(t){return t&&t.__r_state}function bt(t){return t.copy||t.base}function _t(t){t.copy||(t.copy=w(t.base))}function wt(t){t.modified||(t.modified=!0,function(t){var e=X.get(t);if(e)for(var n,i=H([].concat(e));!(n=i()).done;){var r=n.value;r.view&&(r.view.mightChange=!0)}}(t),t.parent&&wt(t.parent))}var mt=function(){function t(t,e){var n=this,i=e.disableCache,r=void 0!==i&&i;this.dep=void 0,this.effect=void 0,this.mightChange=!1,this._value=void 0,this._cacheable=void 0,this._dirty=!0,this.effect=new it(t,(function(){var t;n._dirty||(n._dirty=!0,(t=yt(t=n)).dep&&pt(t.dep))})),this.effect.view=this,this.effect.active=this._cacheable=!r}var e,n;return e=t,(n=[{key:"value",get:function(){var t,e=yt(this);return t=e,st&&U&&ht((t=yt(t)).dep||(t.dep=B())),!e._dirty&&e._cacheable||(e._dirty=!1,e._value=e.effect.run()),e._value},set:function(t){}}])&&function(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}(e.prototype,n),Object.defineProperty(e,"prototype",{writable:!1}),t}(),St=new Set(["__proto__"]),Ot=new Set(Object.getOwnPropertyNames(Symbol).filter((function(t){return"arguments"!==t&&"caller"!==t})).map((function(t){return Symbol[t]})).filter(l));function jt(t,e){var n=t.__r_state;return(n?bt(n):t)[e]}var xt=It(),Pt=Rt();function Rt(){var t={};return["includes","indexOf","lastIndexOf"].forEach((function(e){t[e]=function(){for(var t=gt(this),n=bt(t),i=0,r=this.length;i<r;i++)ut(t,0,i+"",Reflect.get(n,i));for(var s=arguments.length,o=new Array(s),a=0;a<s;a++)o[a]=arguments[a];var c=n[e].apply(n,o);return-1===c||!1===c?n[e].apply(n,o.map(yt)):c}})),["push","pop","shift","unshift","splice"].forEach((function(e){t[e]=function(){at();for(var t=gt(this),n=bt(t),i=arguments.length,r=new Array(i),s=0;s<i;s++)r[s]=arguments[s];var o=n[e].apply(this,r);return ct(),o}})),t}function It(){return function(t,e,n){var i=bt(t);if("__r_isReactive"===e)return!0;if("__r_state"===e&&n===kt.get(t))return t;if(c(i)&&s(Pt,e))return Reflect.get(Pt,e,n);var r=Reflect.get(i,e,n);if(l(e)?Ot.has(e):St.has(e))return r;if(ut(t,0,e),!s(i,e))return r;if(t.disposed||!p(r))return r;if(r===jt(t.base,e)){_t(t);var o=t.copy[e]=Tt(r,t);return gt(o)&&ft(o.__r_state),o}var a=gt(r);return a&&ft(a),r}}function At(){return function(t,e,n,i){var r=bt(t),o=jt(r,e),a=c(r)&&y(e)?Number(e)<r.length:s(r,e);if(!t.modified){var u=null==o?void 0:o.__r_state;if(u&&u.base===n)return t.copy[e]=n,t.assigned[e]=!1,!0;if(g(n,o)&&(void 0!==n||s(t.base,e)))return!0;_t(t),wt(t)}return g(t.copy[e],n)&&(void 0!==n||e in t.copy)||(t.copy[e]=n,t.assigned[e]=!0,t===gt(i)&&(a?g(n,o)||lt(t,"set",e,n):lt(t,"add",e,n))),!0}}var Mt={get:xt,set:At(),deleteProperty:function(t,e){var n=s(bt(t),e);if(void 0!==jt(t.base,e)||e in t.base?(t.assigned[e]=!1,_t(t),wt(t)):delete t.assigned[e],t.copy){var i=delete t.copy[e];return i&&n&<(t,"delete",e,void 0),i}return!0},has:function(t,e){var n=bt(t),i=Reflect.has(n,e);return l(e)&&Ot.has(e)||ut(t,0,e),i},ownKeys:function(t){var e=bt(t);return ut(t,0,c(e)?"length":tt),Reflect.ownKeys(e)},setPrototypeOf:function(t,e){var n=Reflect.setPrototypeOf(t.base,e);return n&&t.copy&&Reflect.setPrototypeOf(t.copy,e),n},getOwnPropertyDescriptor:function(t,e){var n=bt(t),i=Reflect.getOwnPropertyDescriptor(n,e);return i?{writable:!0,configurable:!c(n)||"length"!==e,enumerable:i.enumerable,value:n[e]}:i}},kt=new WeakMap,Ct=0;function Tt(t,e){if(!p(t))return t;if(t.__r_state)return t;var n;if(0===((n=t).__r_skip||!Object.isExtensible(n)?0:function(t){switch(t){case"Object":case"Array":return 1;case"Map":case"Set":case"WeakMap":case"WeakSet":return 2;default:return 0}}(v(n))))return t;var i=Array.isArray(t),r={id:Ct++,root:null,parent:e,base:t,proxy:null,copy:null,assigned:{},modified:!1,disposed:!1,listeners:[],children:[]};if(i){var s=r;r=[],Object.keys(s).forEach((function(t){Object.defineProperty(r,t,{configurable:!0,enumerable:!0,writable:!0,value:s[t]})}))}var o=new Proxy(r,Mt);return r.proxy=o,e?(r.root=e.root,e.children.push(r)):r.root=r,r.children=[],kt.set(r,o),r.proxy}function Nt(t,e){if(!p(t))return t;var n=function(t){var e=new Map;if(!dt(t))return e;for(var n=[t.__r_state];n.length;){var i=n.pop(),r=i.modified?w(i.copy):i.base;e.set(i,r);for(var s,o=H(i.children);!(s=o()).done;)n.push(s.value)}return e}(e);return function(t,e){var n=function(t){var e={get:function(n,i,r){var s=Reflect.get(n,i,r);return p(s)&&dt(s)?new Proxy(t.get(s.__r_state),e):s},set:function(t,e,n,i){return Reflect.set(t,e,n,i)},has:function(t,e){return Reflect.has(t,e)},ownKeys:function(t){return Reflect.ownKeys(t)}};return e}(e);return dt(t)?new Proxy(e.get(t.__r_state),n):new Proxy(w(t),n)}(t,n)}function Et(t,e){var n=t.createView((function(){return e(this)})),i=function(){return n.value};return i.destory=function(){n.effect.stop();var e=t.effectScope.effects.indexOf(n.effect);e>=0&&t.effectScope.effects.splice(e,1)},i}var $t=i({$rawState:function(t){return t.getState()},$state:function(t){return t.isPrimitiveState?t.stateRef.value:t.stateValue},$patch:function(t){return t.patch},$actions:function(t){return t.actions},$views:function(t){return t.views},$getSnapshot:function(t){return t.getSnapshot},$createSelector:function(t){return Et.bind(null,t)}}),Dt={get:function(t,e){var n=t._,i=n.actions,r=n.views,o=n.accessCache,a=n.accessContext,c=n.depsProxy,u=n.ctx,f=n.stateValue;if("$"!==e[0]){var h=o[e];if(void 0!==h)switch(h){case 0:return f[e];case 2:return r[e];case 1:if(1===a)return;return i[e];case 3:return u[e]}else{if(s(f,e))return o[e]=0,f[e];if(s(r,e))return o[e]=2,r[e];if(s(i,e)){if(1===a)return;return o[e]=1,i[e]}if(s(u,e))return o[e]=3,u[e]}}if("$dep"===e)return c;var l=$t[e];return l?l(n):s(u,e)?(o[e]=3,u[e]):d(f)?f[e]:void 0},set:function(t,e,n){var i=t._,r=i.ctx,o=i.actions,a=i.views,c=i.stateRef.value;return!(1===i.accessContext||(s(c,e)?(c[e]=n,0):"$state"===e?"bigint"==typeof n||"symbol"==typeof n||(i.replace(n),0):s(o,e)||s(a,e)||"$"===e[0]&&s($t,e)||(r[e]=n,0)))}},Vt={INIT:"@@doura/INIT"+function(){return Math.random().toString(36).substring(7).split("").join(".")}(),ACTION:"@@doura/ACTION"},Lt={get:function(t,e){var n=t.get(e);if(n)return n.proxy}};function Kt(t,e){var n=Object.keys(e);n.length&&n.forEach((function(n){s(t,n)&&d(e[n])?Kt(t[n],e[n]):t[n]=e[n]}))}var Ft=function(){function t(t,n){var i=this;this.name=void 0,this.options=void 0,this.deps=void 0,this.depsProxy=void 0,this.ctx=void 0,this.accessCache=void 0,this.proxy=null,this.actions=void 0,this.views=void 0,this.viewInstances=[],this.accessContext=void 0,this.stateRef=void 0,this.stateValue=void 0,this.effectScope=void 0,this.isPrimitiveState=void 0,this._snapshot=null,this._initState=void 0,this._currentState=void 0,this._listeners=new Set,this._viewListeners=new Set,this._isDispatching=void 0,this._draftListenerHandler=void 0,this.patch=this.patch.bind(this),this.getSnapshot=this.getSnapshot.bind(this),this.subscribe=this.subscribe.bind(this),this.reducer=this.reducer.bind(this),this._subscribeFromView=this._subscribeFromView.bind(this),this.options=t,this.name=this.options.name||"",this._initState=n||t.state,this.effectScope=new q(void 0),this.stateRef=Tt({value:this._initState});var r=function(){i.dispatch({type:Vt.ACTION,payload:Nt(i.stateRef.value,i.stateRef.value)})};this._draftListenerHandler=function(t,n){var i=t.__r_state;return i.disposed?e:(i.listeners.push(n),function(){var t=i.listeners.indexOf(n);t>=0&&i.listeners.splice(t,1)})}(this.stateRef,(function(){var t;t=r,R.length&&R.includes(t,x&&t.allowRecurse?I+1:I)||t===D||(null==t.id?R.push(t):R.splice(function(t){for(var e=I+1,n=R.length;e<n;){var i=e+n>>>1;K(R[i])<t?e=i+1:n=i}return e}(t.id),0,t),x||P||(P=!0,$=E.then(F)))})),this.actions=Object.create(null),this.views=Object.create(null),this.deps=new Map,this.accessContext=0,this._isDispatching=!1,this.ctx={_:this},this.accessCache=Object.create(null),this.proxy=new Proxy(this.ctx,Dt),this.depsProxy=new Proxy(this.deps,Lt),this._initActions(),this._initViews(),this.dispatch({type:Vt.INIT})}var n=t.prototype;return n.patch=function(t){d(t)&&this._currentState&&Kt(this.proxy.$state,t)},n.replace=function(t){this.stateRef.value=t,this.stateValue=this.stateRef.value;for(var e,n=H(this.viewInstances);!(e=n()).done;)e.value.effect.scheduler()},n.getState=function(){return this._currentState},n.getSnapshot=function(){return null===this._snapshot&&(this._snapshot=W({$state:this._currentState},this._currentState,this.views)),this._snapshot},n.reducer=function(t,e){switch(e.type){case Vt.INIT:return this._initState;case Vt.ACTION:return e.payload;default:return t}},n.dispatch=function(t){if(void 0===t.type)return t;if(this._isDispatching)return t;var e;try{this._isDispatching=!0,e=this.reducer(this._currentState,t)}finally{this._isDispatching=!1}return e!==this._currentState&&(this._snapshot=null,this._currentState=e,this.isPrimitiveState=!p(e),this.stateValue=this.stateRef.value,this._triggerListener()),t},n.subscribe=function(t){var e=this;return this._listeners.add(t),function(){e._listeners.delete(t)}},n.destroy=function(){this._currentState=null,this.stateRef={value:null},this._listeners.clear(),this.effectScope.stop(),this._draftListenerHandler()},n.depend=function(t,e){var n=this;this.deps.set(t,e),e.subscribe((function(){n._triggerListener()}))},n._triggerListener=function(){for(var t,e=H(this._viewListeners);!(t=e()).done;)(0,t.value)();for(var n,i=H(this._listeners);!(n=i()).done;)(0,n.value)()},n.createView=function(t){var e,n=this;return this.effectScope.run((function(){var i;void 0===i&&(i={}),e=new mt((function(){var e=n.accessContext;n.accessContext=1;try{return t.call(n.proxy)}finally{n.accessContext=e}}),i)})),this.viewInstances.push(e),e},n._initActions=function(){var t=this,e=this.options.actions;e&&Object.keys(e).forEach((function(n){var i=e[n];t.actions[n]=function(){for(var e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];return i.call.apply(i,[t.proxy].concat(n))}}))},n._initViews=function(){var t=this,e=this.options.views;if(e)for(var n=function(){var n=r[i],s=t.createView(e[n]),o=t;Object.defineProperty(t.views,n,{configurable:!0,enumerable:!0,get:function(){var t=s,e=s.value;return s.mightChange?(s.mightChange=!1,t.__snapshot=Nt(e,o.stateRef.value)):t.__pre!==e&&(t.__snapshot=Nt(e,o.stateRef.value)),t.__pre=e,t.__snapshot},set:function(){return!1}})},i=0,r=Object.keys(e);i<r.length;i++)n()},n._subscribeFromView=function(t){var e=this;return this._viewListeners.add(t),function(){e._viewListeners.delete(t)}},t}(),Wt=["name","getState","dispatch","subscribe","reducer","replace"],zt=function(){function t(t,e){var i=this;void 0===t&&(t=n),void 0===e&&(e=[]),this._initialState=void 0,this._hooks=void 0,this._models=void 0,this._initialState=t,this._models=function(){var t=new Map,e={get:function(e){return t.get(e.name||e)},set:function(e,n){t.set(e.name||e,n)},each:function(e){for(var n,i=H(t.values());!(n=i()).done;)e(n.value)},clear:function(){e.each((function(t){return t.destroy()})),t.clear()}};return e}(),this._hooks=e.map((function(t){return(0,t[0])(t[1])})),this._hooks.map((function(e){return null==e.onInit?void 0:e.onInit(i,t)}))}var e=t.prototype;return e.getModel=function(t){return this._getModelInstance(t).proxy},e.getState=function(){var t={},e=[];return this._models.each((function(n){n.name?t[n.name]=n.getState():e.push(n.getState())})),e.length&&(t._=e),t},e.dispatch=function(t){return this._models.each((function(e){e.dispatch(t)})),t},e.subscribe=function(t,e){return this._getModelInstance(t).subscribe(e)},e.destroy=function(){this._hooks.map((function(t){return null==t.onDestroy?void 0:t.onDestroy()})),this._models.clear(),this._initialState=n},e._getModelInstance=function(t){return this._models.get(t)||this._initModel(t)},e._initModel=function(t){this._hooks.map((function(e){return null==e.onModel?void 0:e.onModel(t)}));var e,n,i=(e=t,n=this._getInitialState(t.name),new Ft(e,n)),r=t._depends;if(r)for(var s=0,o=Object.entries(r);s<o.length;s++){var a=o[s],c=a[0],u=this._getModelInstance(a[1]);i.depend(c,u)}var f=new Proxy(i,{get:function(t,e,n){if(Wt.includes(e)){var i=Reflect.get(t,e,n);return"function"==typeof i?i.bind(t):i}}});return this._hooks.map((function(t){null==t.onModelInstance||t.onModelInstance(f)})),this._models.set(t,i),i},e._getInitialState=function(t){var e=this._initialState[t];return e&&delete this._initialState[t],e},t}();t.NOOP=e,t.capitalize=b,t.def=function(t,e,n){Object.defineProperty(t,e,{configurable:!0,enumerable:!1,value:n})},t.defineModel=function(t,e){var n=t;if(e){n._depends={};for(var i=0;i<e.length;i++){var r=e[i];n._depends[r.name||""+i]=r}}return n},t.doura=function(t){var e=void 0===t?{}:t,n=e.plugins;return function(t){var e=void 0===t?{}:t;return new zt(e.initialState,e.plugins)}({initialState:e.initialState,plugins:void 0===n?[]:n})},t.each=function(t,e,n){void 0===n&&(n=!1),d(t)?(n?Object.keys:S)(t).forEach((function(i){n&&"symbol"==typeof i||e(i,t[i],t)})):t.forEach((function(n,i){return e(i,n,t)}))},t.emptyObject=n,t.extend=i,t.hasOwn=s,t.invariant=function(t,e){if(!t)throw new Error("[Doura] "+(e||""))},t.is=g,t.isArray=c,t.isFrozen=function(t){return null==t||"object"!=typeof t||Object.isFrozen(t)},t.isFunction=function(t){return"function"==typeof t},t.isIntegerKey=y,t.isMap=u,t.isObject=p,t.isPlainObject=d,t.isSet=f,t.isString=h,t.isSymbol=l,t.nextTick=function(t){var e=$||E;return t?e.then(this?t.bind(this):t):e},t.objectToString=o,t.ownKeys=S,t.patchObj=function t(e,n){Object.keys(n).forEach((function(i){e.hasOwnProperty(i)&&p(n[i])?t(e[i],n[i]):e[i]=n[i]}))},t.set=function(t,e,n){u(t)?t.set(e,n):f(t)?(t.delete(e),t.add(n)):t[e]=n},t.shallowCopy=w,t.toRawType=v,t.toTypeString=a,Object.defineProperty(t,"__esModule",{value:!0})})); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).doura={})}(this,(function(t){"use strict";var e=function(){},n=Object.create(null),i=Object.assign,r=Object.prototype.hasOwnProperty,s=function(t,e){return r.call(t,e)},o=Object.prototype.toString,a=function(t){return o.call(t)},c=Array.isArray,u=function(t){return"[object Map]"===a(t)},f=function(t){return"[object Set]"===a(t)},h=function(t){return"string"==typeof t},l=function(t){return"symbol"==typeof t},p=function(t){return null!==t&&"object"==typeof t},v=function(t){return a(t).slice(8,-1)},d=function(t){return"[object Object]"===a(t)},y=function(t){return h(t)&&"NaN"!==t&&"-"!==t[0]&&""+parseInt(t,10)===t},g=function(t,e){return Object.is(t,e)},b=function(t){var e=Object.create(null);return function(t){return e[t]||(e[t]=function(t){return t.charAt(0).toUpperCase()+t.slice(1)}(t))}}(),_=Array.prototype.slice;function w(t){if(Array.isArray(t))return _.call(t);for(var e=Object.getOwnPropertyDescriptors(t),n=Reflect.ownKeys(e),i=0;i<n.length;i++){var r=n[i],s=e[r];!1===s.writable&&(s.writable=!0,s.configurable=!0),(s.get||s.set)&&(e[r]={configurable:!0,writable:!0,enumerable:s.enumerable,value:t[r]})}return Object.create(Object.getPrototypeOf(t),e)}var m,S="undefined"!=typeof Reflect&&Reflect.ownKeys?Reflect.ownKeys:void 0!==Object.getOwnPropertySymbols?function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:Object.getOwnPropertyNames,O=((m={})[0]="scheduler flush. This is likely a Doura internals bug. Please open an issue at https://github.com/dourajs/doura/issues/new",m);function j(t,e){for(var n=O[e],i=arguments.length,r=new Array(i>2?i-2:0),s=2;s<i;s++)r[s-2]=arguments[s];var o=n?"function"==typeof n?n.apply(null,r):n:"unknown error nr: "+j;throw new Error("[Doura] "+o)}var x=!1,P=!1,R=[],I=0,A=[],M=null,k=0,C=[],T=null,N=0,E=Promise.resolve(),$=null,D=null;function V(t,e){if(void 0===e&&(e=null),A.length){for(D=e,M=[].concat(new Set(A)),A.length=0,k=0;k<M.length;k++)M[k]();M=null,k=0,D=null,V(t,e)}}var L,K=function(t){return null==t.id?Infinity:t.id};function F(t){P=!1,x=!0,V(t),R.sort((function(t,e){return K(t)-K(e)}));try{for(I=0;I<R.length;I++){var e=R[I];if(e&&!1!==e.active)try{e()}catch(t){j(t,0)}}}finally{I=0,R.length=0,function(t){if(V(),C.length){var e,n=[].concat(new Set(C));if(C.length=0,T)return void(e=T).push.apply(e,n);for((T=n).sort((function(t,e){return K(t)-K(e)})),N=0;N<T.length;N++)T[N]();T=null,N=0}}(),x=!1,$=null,(R.length||A.length||C.length)&&F(t)}}function W(){return W=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(t[i]=n[i])}return t},W.apply(this,arguments)}function z(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,i=new Array(e);n<e;n++)i[n]=t[n];return i}function H(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(n)return(n=n.call(t)).next.bind(n);if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return z(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?z(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var i=0;return function(){return i>=t.length?{done:!0}:{done:!1,value:t[i++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function U(t){return!!t&&!!t.__r_state}function q(t){var e=B(t);return e?q(e.base):t}function B(t){return t&&t.__r_state}function G(t){return t.copy||t.base}function J(t){t.copy||(t.copy=w(t.base))}function Q(t){t.modified||(t.modified=!0,t.parent&&Q(t.parent))}var X,Y=function(){function t(t){void 0===t&&(t=!1),this.active=!0,this.effects=[],this.cleanups=[],this.parent=void 0,this.scopes=void 0,this.index=void 0,!t&&L&&(this.parent=L,this.index=(L.scopes||(L.scopes=[])).push(this)-1)}var e=t.prototype;return e.run=function(t){if(this.active){var e=L;try{return L=this,t()}finally{L=e}}},e.on=function(){L=this},e.off=function(){L=this.parent},e.stop=function(t){if(this.active){var e,n;for(e=0,n=this.effects.length;e<n;e++)this.effects[e].stop();for(e=0,n=this.cleanups.length;e<n;e++)this.cleanups[e]();if(this.scopes)for(e=0,n=this.scopes.length;e<n;e++)this.scopes[e].stop(!0);if(this.parent&&!t){var i=this.parent.scopes.pop();i&&i!==this&&(this.parent.scopes[this.index]=i,i.index=this.index)}this.active=!1}},t}(),Z=function(t){var e=new Set(t);return e.w=0,e.n=0,e},tt=function(t){return(t.w&st)>0},et=function(t){return(t.n&st)>0},nt=new WeakMap,it=new WeakMap,rt=0,st=1,ot=Symbol(""),at=Symbol(""),ct=0,ut=function(){function t(t,e,n){void 0===e&&(e=null),this.fn=void 0,this.scheduler=void 0,this.id=ct++,this.deps=[],this.active=!0,this.parent=void 0,this.view=void 0,this.allowRecurse=void 0,this.deferStop=void 0,this.onStop=void 0,this.fn=t,this.scheduler=e,function(t,e){void 0===e&&(e=L),e&&e.active&&e.effects.push(t)}(this,n)}var e=t.prototype;return e.run=function(){if(!this.active)return this.fn();for(var t=X,e=ht;t;){if(t===this)return;t=t.parent}try{return this.parent=X,X=this,ht=!0,st=1<<++rt,rt<=30?function(t){var e=t.deps;if(e.length)for(var n=0;n<e.length;n++)e[n].w|=st}(this):ft(this),this.fn()}finally{rt<=30&&function(t){var e=t.deps;if(e.length){for(var n=0,i=0;i<e.length;i++){var r=e[i];tt(r)&&!et(r)?r.delete(t):e[n++]=r,r.w&=~st,r.n&=~st}e.length=n}}(this),st=1<<--rt,X=this.parent,ht=e,this.parent=void 0,this.deferStop&&this.stop()}},e.stop=function(){X===this?this.deferStop=!0:this.active&&(ft(this),this.onStop&&this.onStop(),this.active=!1)},t}();function ft(t){var e=t.deps;if(e.length){for(var n=0;n<e.length;n++)e[n].delete(t);e.length=0}}var ht=!0,lt=[];function pt(){lt.push(ht),ht=!1}function vt(){var t=lt.pop();ht=void 0===t||t}function dt(t,e,n,i){if(ht&&X){var r=nt.get(t);r||nt.set(t,r=new Map);var s=r.get(n);s||r.set(n,s=Z()),gt(s)}}function yt(t){if(ht&&X){var e=it.get(t);e||it.set(t,e=Z()),gt(e)}}function gt(t){var e=!1;rt<=30?et(t)||(t.n|=st,e=!tt(t)):e=!t.has(X),e&&(t.add(X),X.deps.push(t))}function bt(t){var e=it.get(t);if(e)for(var n,i=H([].concat(e));!(n=i()).done;){var r=n.value;r.view&&(r.view.mightChange=!0)}}function _t(t,e,n,i,r,s){var o,a=nt.get(t),f=t.base,h=[];if(a)if("clear"===e)h=[].concat(a.values());else if("length"===n&&c(f))a.forEach((function(t,e){("length"===e||e>=i)&&h.push(t)}));else switch(void 0!==n&&h.push(a.get(n)),e){case"add":c(f)?y(n)&&h.push(a.get("length")):(h.push(a.get(ot)),u(f)&&h.push(a.get(at)));break;case"delete":c(f)||(h.push(a.get(ot)),u(f)&&h.push(a.get(at)));break;case"set":u(f)&&h.push(a.get(ot))}if(1===h.length)h[0]&&wt(h[0]);else{for(var l,p=[],v=H(h);!(l=v()).done;){var d=l.value;d&&p.push.apply(p,d)}wt(Z(p))}var g=null==(o=t.root)?void 0:o.listeners;g&&g.length&&g.forEach((function(t){return t()}))}function wt(t){for(var e,n=c(t)?t:[].concat(t),i=H(n);!(e=i()).done;){var r=e.value;r.view&&mt(r)}for(var s,o=H(n);!(s=o()).done;){var a=s.value;a.view||mt(a)}}function mt(t){(t!==X||t.allowRecurse)&&(t.scheduler?t.scheduler():t.run())}var St=function(){function t(t,e){var n=this,i=e.disableCache,r=void 0!==i&&i;this.dep=void 0,this.effect=void 0,this.mightChange=!1,this._value=void 0,this._cacheable=void 0,this._dirty=!0,this.effect=new ut(t,(function(){var t;n._dirty||(n._dirty=!0,(t=q(t=n)).dep&&wt(t.dep))})),this.effect.view=this,this.effect.active=this._cacheable=!r}var e,n;return e=t,(n=[{key:"value",get:function(){var t,e=q(this);return t=e,ht&&X&>((t=q(t)).dep||(t.dep=Z())),!e._dirty&&e._cacheable||(e._dirty=!1,e._value=e.effect.run()),e._value},set:function(t){}}])&&function(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}(e.prototype,n),Object.defineProperty(e,"prototype",{writable:!1}),t}(),Ot=new Set(["__proto__"]),jt=new Set(Object.getOwnPropertyNames(Symbol).filter((function(t){return"arguments"!==t&&"caller"!==t})).map((function(t){return Symbol[t]})).filter(l));function xt(t,e){var n=t.__r_state;return(n?G(n):t)[e]}var Pt=At(),Rt=It();function It(){var t={};return["includes","indexOf","lastIndexOf"].forEach((function(e){t[e]=function(){for(var t=B(this),n=G(t),i=0,r=this.length;i<r;i++)dt(t,0,i+"",Reflect.get(n,i));for(var s=arguments.length,o=new Array(s),a=0;a<s;a++)o[a]=arguments[a];var c=n[e].apply(n,o);return-1===c||!1===c?n[e].apply(n,o.map(q)):c}})),["push","pop","shift","unshift","splice"].forEach((function(e){t[e]=function(){pt();for(var t=B(this),n=G(t),i=arguments.length,r=new Array(i),s=0;s<i;s++)r[s]=arguments[s];var o=n[e].apply(this,r);return vt(),o}})),t}function At(){return function(t,e,n){var i=G(t);if("__r_isReactive"===e)return!0;if("__r_state"===e&&n===Ct.get(t))return t;if(c(i)&&s(Rt,e))return Reflect.get(Rt,e,n);var r=Reflect.get(i,e,n);if(l(e)?jt.has(e):Ot.has(e))return r;if(dt(t,0,e),!s(i,e))return r;if(t.disposed||!p(r))return r;if(r===xt(t.base,e)){J(t);var o=t.copy[e]=Nt(r,t);return B(o)&&yt(o.__r_state),o}var a=B(r);return a&&yt(a),r}}function Mt(){return function(t,e,n,i){var r=G(t),o=xt(r,e),a=c(r)&&y(e)?Number(e)<r.length:s(r,e);if(!t.modified){var u=null==o?void 0:o.__r_state;if(u&&u.base===n)return t.copy[e]=n,t.assigned[e]=!1,!0;if(g(n,o)&&(void 0!==n||s(t.base,e)))return!0;J(t),Q(t)}return g(t.copy[e],n)&&(void 0!==n||e in t.copy)||(t.copy[e]=n,t.assigned[e]=!0,t===B(i)&&(a?g(n,o)||_t(t,"set",e,n):_t(t,"add",e,n),function(t){for(var e=t;e;)bt(t),e=e.parent}(t))),!0}}var kt={get:Pt,set:Mt(),deleteProperty:function(t,e){var n=s(G(t),e);if(void 0!==xt(t.base,e)||e in t.base?(t.assigned[e]=!1,J(t),Q(t)):delete t.assigned[e],t.copy){var i=delete t.copy[e];return i&&n&&_t(t,"delete",e,void 0),i}return!0},has:function(t,e){var n=G(t),i=Reflect.has(n,e);return l(e)&&jt.has(e)||dt(t,0,e),i},ownKeys:function(t){var e=G(t);return dt(t,0,c(e)?"length":ot),Reflect.ownKeys(e)},setPrototypeOf:function(t,e){var n=Reflect.setPrototypeOf(t.base,e);return n&&t.copy&&Reflect.setPrototypeOf(t.copy,e),n},getOwnPropertyDescriptor:function(t,e){var n=G(t),i=Reflect.getOwnPropertyDescriptor(n,e);return i?{writable:!0,configurable:!c(n)||"length"!==e,enumerable:i.enumerable,value:n[e]}:i}},Ct=new WeakMap,Tt=0;function Nt(t,e){if(!p(t))return t;if(t.__r_state)return t;var n;if(0===((n=t).__r_skip||!Object.isExtensible(n)?0:function(t){switch(t){case"Object":case"Array":return 1;case"Map":case"Set":case"WeakMap":case"WeakSet":return 2;default:return 0}}(v(n))))return t;var i=Array.isArray(t),r={id:Tt++,root:null,parent:e,base:t,proxy:null,copy:null,assigned:{},modified:!1,disposed:!1,listeners:[],children:[]};if(i){var s=r;r=[],Object.keys(s).forEach((function(t){Object.defineProperty(r,t,{configurable:!0,enumerable:!0,writable:!0,value:s[t]})}))}var o=new Proxy(r,kt);return r.proxy=o,e?(r.root=e.root,e.children.push(r)):r.root=r,r.children=[],Ct.set(r,o),r.proxy}function Et(t,e){if(!p(t))return t;var n=function(t){var e=new Map;if(!U(t))return e;for(var n=[t.__r_state];n.length;){var i=n.pop(),r=i.modified?w(i.copy):i.base;e.set(i,r);for(var s,o=H(i.children);!(s=o()).done;)n.push(s.value)}return e}(e);return function(t,e){var n=function(t){var e={get:function(n,i,r){var s=Reflect.get(n,i,r);return p(s)&&U(s)?new Proxy(t.get(s.__r_state),e):s},set:function(t,e,n,i){return Reflect.set(t,e,n,i)},has:function(t,e){return Reflect.has(t,e)},ownKeys:function(t){return Reflect.ownKeys(t)}};return e}(e);return U(t)?new Proxy(e.get(t.__r_state),n):new Proxy(w(t),n)}(t,n)}function $t(t,e){var n=t.createView((function(){return e(this)})),i=function(){return n.value};return i.destory=function(){n.effect.stop();var e=t.effectScope.effects.indexOf(n.effect);e>=0&&t.effectScope.effects.splice(e,1)},i}var Dt=i({$rawState:function(t){return t.getState()},$state:function(t){return t.isPrimitiveState?t.stateRef.value:t.stateValue},$patch:function(t){return t.patch},$actions:function(t){return t.actions},$views:function(t){return t.views},$getSnapshot:function(t){return t.getSnapshot},$createSelector:function(t){return $t.bind(null,t)}}),Vt={get:function(t,e){var n=t._,i=n.actions,r=n.views,o=n.accessCache,a=n.accessContext,c=n.depsProxy,u=n.ctx,f=n.stateValue;if("$"!==e[0]){var h=o[e];if(void 0!==h)switch(h){case 0:return f[e];case 2:return r[e];case 1:if(1===a)return;return i[e];case 3:return u[e]}else{if(s(f,e))return o[e]=0,f[e];if(s(r,e))return o[e]=2,r[e];if(s(i,e)){if(1===a)return;return o[e]=1,i[e]}if(s(u,e))return o[e]=3,u[e]}}if("$dep"===e)return c;var l=Dt[e];return l?l(n):s(u,e)?(o[e]=3,u[e]):d(f)?f[e]:void 0},set:function(t,e,n){var i=t._,r=i.ctx,o=i.actions,a=i.views,c=i.stateRef.value;return!(1===i.accessContext||(s(c,e)?(c[e]=n,0):"$state"===e?"bigint"==typeof n||"symbol"==typeof n||(i.replace(n),0):s(o,e)||s(a,e)||"$"===e[0]&&s(Dt,e)||(r[e]=n,0)))}},Lt={INIT:"@@doura/INIT"+function(){return Math.random().toString(36).substring(7).split("").join(".")}(),ACTION:"@@doura/ACTION"},Kt={get:function(t,e){var n=t.get(e);if(n)return n.proxy}};function Ft(t,e){var n=Object.keys(e);n.length&&n.forEach((function(n){s(t,n)&&d(e[n])?Ft(t[n],e[n]):t[n]=e[n]}))}var Wt=function(){function t(t,n){var i=this;this.name=void 0,this.options=void 0,this.deps=void 0,this.depsProxy=void 0,this.ctx=void 0,this.accessCache=void 0,this.proxy=null,this.actions=void 0,this.views=void 0,this.viewInstances=[],this.accessContext=void 0,this.stateRef=void 0,this.stateValue=void 0,this.effectScope=void 0,this.isPrimitiveState=void 0,this._snapshot=null,this._initState=void 0,this._currentState=void 0,this._listeners=new Set,this._viewListeners=new Set,this._isDispatching=void 0,this._draftListenerHandler=void 0,this.patch=this.patch.bind(this),this.getSnapshot=this.getSnapshot.bind(this),this.subscribe=this.subscribe.bind(this),this.reducer=this.reducer.bind(this),this._subscribeFromView=this._subscribeFromView.bind(this),this.options=t,this.name=this.options.name||"",this._initState=n||t.state,this.effectScope=new Y(void 0),this.stateRef=Nt({value:this._initState});var r=function(){i.dispatch({type:Lt.ACTION,payload:Et(i.stateRef.value,i.stateRef.value)})};this._draftListenerHandler=function(t,n){var i=t.__r_state;return i.disposed?e:(i.listeners.push(n),function(){var t=i.listeners.indexOf(n);t>=0&&i.listeners.splice(t,1)})}(this.stateRef,(function(){var t;t=r,R.length&&R.includes(t,x&&t.allowRecurse?I+1:I)||t===D||(null==t.id?R.push(t):R.splice(function(t){for(var e=I+1,n=R.length;e<n;){var i=e+n>>>1;K(R[i])<t?e=i+1:n=i}return e}(t.id),0,t),x||P||(P=!0,$=E.then(F)))})),this.actions=Object.create(null),this.views=Object.create(null),this.deps=new Map,this.accessContext=0,this._isDispatching=!1,this.ctx={_:this},this.accessCache=Object.create(null),this.proxy=new Proxy(this.ctx,Vt),this.depsProxy=new Proxy(this.deps,Kt),this._initActions(),this._initViews(),this.dispatch({type:Lt.INIT})}var n=t.prototype;return n.patch=function(t){d(t)&&this._currentState&&Ft(this.proxy.$state,t)},n.replace=function(t){this.stateRef.value=t,this.stateValue=this.stateRef.value;for(var e,n=H(this.viewInstances);!(e=n()).done;)e.value.effect.scheduler()},n.getState=function(){return this._currentState},n.getSnapshot=function(){return null===this._snapshot&&(this._snapshot=W({$state:this._currentState},this._currentState,this.views)),this._snapshot},n.reducer=function(t,e){switch(e.type){case Lt.INIT:return this._initState;case Lt.ACTION:return e.payload;default:return t}},n.dispatch=function(t){if(void 0===t.type)return t;if(this._isDispatching)return t;var e;try{this._isDispatching=!0,e=this.reducer(this._currentState,t)}finally{this._isDispatching=!1}return e!==this._currentState&&(this._snapshot=null,this._currentState=e,this.isPrimitiveState=!p(e),this.stateValue=this.stateRef.value,this._triggerListener()),t},n.subscribe=function(t){var e=this;return this._listeners.add(t),function(){e._listeners.delete(t)}},n.destroy=function(){this._currentState=null,this.stateRef={value:null},this._listeners.clear(),this.effectScope.stop(),this._draftListenerHandler()},n.depend=function(t,e){var n=this;this.deps.set(t,e),e.subscribe((function(){n._triggerListener()}))},n._triggerListener=function(){for(var t,e=H(this._viewListeners);!(t=e()).done;)(0,t.value)();for(var n,i=H(this._listeners);!(n=i()).done;)(0,n.value)()},n.createView=function(t){var e,n=this;return this.effectScope.run((function(){var i;void 0===i&&(i={}),e=new St((function(){var e=n.accessContext;n.accessContext=1;try{return t.call(n.proxy)}finally{n.accessContext=e}}),i)})),this.viewInstances.push(e),e},n._initActions=function(){var t=this,e=this.options.actions;e&&Object.keys(e).forEach((function(n){var i=e[n];t.actions[n]=function(){for(var e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];return i.call.apply(i,[t.proxy].concat(n))}}))},n._initViews=function(){var t=this,e=this.options.views;if(e)for(var n=function(){var n=r[i],s=t.createView(e[n]),o=t;Object.defineProperty(t.views,n,{configurable:!0,enumerable:!0,get:function(){var t=s,e=s.value;return s.mightChange?(s.mightChange=!1,t.__snapshot=Et(e,o.stateRef.value)):t.__pre!==e&&(t.__snapshot=Et(e,o.stateRef.value)),t.__pre=e,t.__snapshot},set:function(){return!1}})},i=0,r=Object.keys(e);i<r.length;i++)n()},n._subscribeFromView=function(t){var e=this;return this._viewListeners.add(t),function(){e._viewListeners.delete(t)}},t}(),zt=["name","getState","dispatch","subscribe","reducer","replace"],Ht=function(){function t(t,e){var i=this;void 0===t&&(t=n),void 0===e&&(e=[]),this._initialState=void 0,this._hooks=void 0,this._models=void 0,this._initialState=t,this._models=function(){var t=new Map,e={get:function(e){return t.get(e.name||e)},set:function(e,n){t.set(e.name||e,n)},each:function(e){for(var n,i=H(t.values());!(n=i()).done;)e(n.value)},clear:function(){e.each((function(t){return t.destroy()})),t.clear()}};return e}(),this._hooks=e.map((function(t){return(0,t[0])(t[1])})),this._hooks.map((function(e){return null==e.onInit?void 0:e.onInit(i,t)}))}var e=t.prototype;return e.getModel=function(t){return this._getModelInstance(t).proxy},e.getState=function(){var t={},e=[];return this._models.each((function(n){n.name?t[n.name]=n.getState():e.push(n.getState())})),e.length&&(t._=e),t},e.dispatch=function(t){return this._models.each((function(e){e.dispatch(t)})),t},e.subscribe=function(t,e){return this._getModelInstance(t).subscribe(e)},e.destroy=function(){this._hooks.map((function(t){return null==t.onDestroy?void 0:t.onDestroy()})),this._models.clear(),this._initialState=n},e._getModelInstance=function(t){return this._models.get(t)||this._initModel(t)},e._initModel=function(t){this._hooks.map((function(e){return null==e.onModel?void 0:e.onModel(t)}));var e,n,i=(e=t,n=this._getInitialState(t.name),new Wt(e,n)),r=t._depends;if(r)for(var s=0,o=Object.entries(r);s<o.length;s++){var a=o[s],c=a[0],u=this._getModelInstance(a[1]);i.depend(c,u)}var f=new Proxy(i,{get:function(t,e,n){if(zt.includes(e)){var i=Reflect.get(t,e,n);return"function"==typeof i?i.bind(t):i}}});return this._hooks.map((function(t){null==t.onModelInstance||t.onModelInstance(f)})),this._models.set(t,i),i},e._getInitialState=function(t){var e=this._initialState[t];return e&&delete this._initialState[t],e},t}();t.NOOP=e,t.capitalize=b,t.def=function(t,e,n){Object.defineProperty(t,e,{configurable:!0,enumerable:!1,value:n})},t.defineModel=function(t,e){var n=t;if(e){n._depends={};for(var i=0;i<e.length;i++){var r=e[i];n._depends[r.name||""+i]=r}}return n},t.doura=function(t){var e=void 0===t?{}:t,n=e.plugins;return function(t){var e=void 0===t?{}:t;return new Ht(e.initialState,e.plugins)}({initialState:e.initialState,plugins:void 0===n?[]:n})},t.each=function(t,e,n){void 0===n&&(n=!1),d(t)?(n?Object.keys:S)(t).forEach((function(i){n&&"symbol"==typeof i||e(i,t[i],t)})):t.forEach((function(n,i){return e(i,n,t)}))},t.emptyObject=n,t.extend=i,t.hasOwn=s,t.invariant=function(t,e){if(!t)throw new Error("[Doura] "+(e||""))},t.is=g,t.isArray=c,t.isFrozen=function(t){return null==t||"object"!=typeof t||Object.isFrozen(t)},t.isFunction=function(t){return"function"==typeof t},t.isIntegerKey=y,t.isMap=u,t.isObject=p,t.isPlainObject=d,t.isSet=f,t.isString=h,t.isSymbol=l,t.nextTick=function(t){var e=$||E;return t?e.then(this?t.bind(this):t):e},t.objectToString=o,t.ownKeys=S,t.patchObj=function t(e,n){Object.keys(n).forEach((function(i){e.hasOwnProperty(i)&&p(n[i])?t(e[i],n[i]):e[i]=n[i]}))},t.set=function(t,e,n){u(t)?t.set(e,n):f(t)?(t.delete(e),t.add(n)):t[e]=n},t.shallowCopy=w,t.toRawType=v,t.toTypeString=a,Object.defineProperty(t,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=doura.umd.production.min.js.map |
import { draft, draftMap } from './draft'; | ||
import { toBase, toState, latest, prepareCopy, markChanged, } from './common'; | ||
import { track, trackDraft, trigger, ITERATE_KEY, pauseTracking, resetTracking, } from './effect'; | ||
import { track, trackDraft, trigger, ITERATE_KEY, pauseTracking, resetTracking, triggerDraft, } from './effect'; | ||
import { isObject, hasOwn, isSymbol, is, isArray, isIntegerKey } from '../utils'; | ||
@@ -136,2 +136,3 @@ import { warn } from '../warning'; | ||
} | ||
triggerDraft(state); | ||
} | ||
@@ -138,0 +139,0 @@ return true; |
import { shallowCopy, toRawType, def } from '../utils'; | ||
import { triggerDraft } from './effect'; | ||
function targetTypeMap(rawType) { | ||
@@ -50,3 +49,2 @@ switch (rawType) { | ||
state.modified = true; | ||
triggerDraft(state); | ||
if (state.parent) { | ||
@@ -53,0 +51,0 @@ markChanged(state.parent); |
@@ -179,3 +179,3 @@ import { extend, isArray, isMap, isIntegerKey } from '../utils'; | ||
} | ||
export function triggerDraft(state) { | ||
function triggerDraftChange(state) { | ||
const referenceDeps = referenceMap.get(state); | ||
@@ -191,2 +191,9 @@ if (referenceDeps) { | ||
} | ||
export function triggerDraft(state) { | ||
let current = state; | ||
while (current) { | ||
triggerDraftChange(state); | ||
current = current.parent; | ||
} | ||
} | ||
export function trigger(state, type, key, newValue, oldValue, oldTarget) { | ||
@@ -193,0 +200,0 @@ var _a; |
@@ -139,2 +139,3 @@ "use strict"; | ||
} | ||
(0, effect_1.triggerDraft)(state); | ||
} | ||
@@ -141,0 +142,0 @@ return true; |
@@ -5,3 +5,2 @@ "use strict"; | ||
const utils_1 = require("../utils"); | ||
const effect_1 = require("./effect"); | ||
function targetTypeMap(rawType) { | ||
@@ -62,3 +61,2 @@ switch (rawType) { | ||
state.modified = true; | ||
(0, effect_1.triggerDraft)(state); | ||
if (state.parent) { | ||
@@ -65,0 +63,0 @@ markChanged(state.parent); |
@@ -192,3 +192,3 @@ "use strict"; | ||
exports.triggerView = triggerView; | ||
function triggerDraft(state) { | ||
function triggerDraftChange(state) { | ||
const referenceDeps = referenceMap.get(state); | ||
@@ -204,2 +204,9 @@ if (referenceDeps) { | ||
} | ||
function triggerDraft(state) { | ||
let current = state; | ||
while (current) { | ||
triggerDraftChange(state); | ||
current = current.parent; | ||
} | ||
} | ||
exports.triggerDraft = triggerDraft; | ||
@@ -206,0 +213,0 @@ function trigger(state, type, key, newValue, oldValue, oldTarget) { |
{ | ||
"name": "doura", | ||
"version": "0.0.0-rc.1", | ||
"version": "0.0.0-rc.2", | ||
"description": "Reactive and intuitive state management", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
573690
7918