Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

doura

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

doura - npm Package Compare versions

Comparing version 0.0.0-rc.8 to 0.0.1

19

dist/doura.d.ts

@@ -48,7 +48,2 @@ export declare type Action = ModifyAction | PatchAction | ReplaceAction;

/**
* @private
*/
export declare const capitalize: (str: string) => string;
export declare const def: (obj: object, key: string | symbol, value: any) => void;

@@ -58,3 +53,3 @@

export declare const defineModel: <S extends State, A extends ActionOptions, V extends ViewOptions<S>, P extends unknown>(modelOptions: ModelOptions<S, A, V, P>) => DefineModel<S, A, V, P>;
export declare const defineModel: <S extends StateObject, A extends ActionOptions, V extends ViewOptions<S>, P extends unknown>(modelOptions: ModelOptions<S, A, V, P>) => DefineModel<S, A, V, P>;

@@ -97,4 +92,2 @@ export declare const devtool: Plugin_2;

export declare function isFrozen(obj: any): boolean;
export declare const isFunction: (val: unknown) => val is Function;

@@ -133,5 +126,3 @@

export declare type ModelData<Model extends AnyModel> = {
$state: ModelState<Model>;
} & ModelState<Model> & ModelViews<Model>;
export declare type ModelData<Model extends AnyModel> = ModelState<Model> & ModelViews<Model>;

@@ -231,4 +222,2 @@ export declare interface ModelManager {

export declare function patchObj(obj: Record<string, any>, partObj: Record<string, any>): void;
declare type Plugin_2<Option = any> = (option: Option) => PluginHook;

@@ -260,3 +249,3 @@ export { Plugin_2 as Plugin }

export declare type State = StateObject | StatePrimitive;
export declare type State = StateObject;

@@ -267,4 +256,2 @@ declare type StateObject = {

declare type StatePrimitive = String | Number | Boolean | any[] | undefined | null;
declare interface SubscriptionCallback {

@@ -271,0 +258,0 @@ (event: ModelChangeEvent): any;

2

dist/doura.esm-browser.prod.js

@@ -1,1 +0,1 @@

const t=()=>{},e=Object.create(null),s=Object.assign,n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var s in e)e.hasOwnProperty(s)&&(t[s]=e[s])},i=Object.prototype.hasOwnProperty,o=(t,e)=>i.call(t,e),r=Object.prototype.toString,c=t=>r.call(t),a=Array.isArray,l=t=>"[object Map]"===c(t),h=t=>"[object Set]"===c(t),u=t=>"function"==typeof t,f=t=>"string"==typeof t,p=t=>"symbol"==typeof t,d=t=>null!==t&&"object"==typeof t,_=t=>c(t).slice(8,-1),y=t=>"[object Object]"===c(t),g=t=>f(t)&&"NaN"!==t&&"-"!==t[0]&&""+parseInt(t,10)===t,b=(t,e)=>Object.is(t,e),v=(t=>{const e=Object.create(null);return s=>e[s]||(e[s]=t(s))})((t=>t.charAt(0).toUpperCase()+t.slice(1))),w=(t,e,s)=>{Object.defineProperty(t,e,{configurable:!0,enumerable:!1,value:s})};function O(t,e){Object.keys(e).forEach((function(s){t.hasOwnProperty(s)&&d(e[s])?O(t[s],e[s]):t[s]=e[s]}))}function m(t,e){if(!t)throw new Error(`[Doura] ${e||""}`)}const S=Array.prototype.slice;function E(t){if(Array.isArray(t))return S.call(t);const e=Object.getOwnPropertyDescriptors(t);let s=Reflect.ownKeys(e);for(let n=0;n<s.length;n++){const i=s[n],o=e[i];!1===o.writable&&(o.writable=!0,o.configurable=!0),(o.get||o.set)&&(e[i]={configurable:!0,writable:!0,enumerable:o.enumerable,value:t[i]})}return Object.create(Object.getPrototypeOf(t),e)}function N(t){return null==t||"object"!=typeof t||Object.isFrozen(t)}const j="undefined"!=typeof Reflect&&Reflect.ownKeys?Reflect.ownKeys:void 0!==Object.getOwnPropertySymbols?t=>Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t)):Object.getOwnPropertyNames;function x(t,e,s=!1){y(t)?(s?Object.keys:j)(t).forEach((n=>{s&&"symbol"==typeof n||e(n,t[n],t)})):t.forEach(((s,n)=>e(n,s,t)))}function D(t,e,s){l(t)?t.set(e,s):h(t)?(t.delete(e),t.add(s)):t[e]=s}const P=t=>t;function R(t,...e){console.warn(`[Doura warn] ${t}`,...e)}function $(t,e,s){const n=t[e];n&&m(y(n),`model.${e} should be object!`)}function C(t,e,s){if(e[t])for(const n of Object.keys(e[t]))if(s.has(n)){R(`key "${n}" in "${t}" is conflicted with the key in "${s.get(n)}"`)}else s.set(n,t)}function A(t){return!!t&&!!t.__r_state}function M(t){const e=V(t);return e?M(e.base):t}function V(t){return t&&t.__r_state}function I(t){return t.copy||t.base}function k(t){t.copy||(t.copy=E(t.base))}function T(t){t.modified||(t.modified=!0,t.parent&&T(t.parent))}let L;class U{constructor(t=!1){this.active=!0,this.effects=[],this.cleanups=[],!t&&L&&(this.parent=L,this.index=(L.scopes||(L.scopes=[])).push(this)-1)}run(t){if(this.active){const e=L;try{return L=this,t()}finally{L=e}}else"development"===process.env.NODE_ENV&&R("cannot run an inactive effect scope.")}on(){L=this}off(){L=this.parent}stop(t){if(this.active){let e,s;for(e=0,s=this.effects.length;e<s;e++)this.effects[e].stop();for(e=0,s=this.cleanups.length;e<s;e++)this.cleanups[e]();if(this.scopes)for(e=0,s=this.scopes.length;e<s;e++)this.scopes[e].stop(!0);if(this.parent&&!t){const t=this.parent.scopes.pop();t&&t!==this&&(this.parent.scopes[this.index]=t,t.index=this.index)}this.active=!1}}}const K=t=>{const e=new Set(t);return e.w=0,e.n=0,e},X=t=>(t.w&Y)>0,H=t=>(t.n&Y)>0,W=new WeakMap,F=new WeakMap;let J=0,Y=1;let B;const q=Symbol("development"===process.env.NODE_ENV?"iterate":""),z=Symbol("development"===process.env.NODE_ENV?"Map key iterate":"");let G=0;class Q{constructor(t,e=null,s){this.fn=t,this.scheduler=e,this.id=G++,this.deps=[],this.active=!0,this.parent=void 0,function(t,e=L){e&&e.active&&e.effects.push(t)}(this,s)}run(){if(!this.active)return this.fn();let t=B,e=tt;for(;t;){if(t===this)return;t=t.parent}try{return this.parent=B,B=this,tt=!0,Y=1<<++J,J<=30?(({deps:t})=>{if(t.length)for(let e=0;e<t.length;e++)t[e].w|=Y})(this):Z(this),this.fn()}finally{J<=30&&(t=>{const{deps:e}=t;if(e.length){let s=0;for(let n=0;n<e.length;n++){const i=e[n];X(i)&&!H(i)?i.delete(t):e[s++]=i,i.w&=~Y,i.n&=~Y}e.length=s}})(this),Y=1<<--J,B=this.parent,tt=e,this.parent=void 0,this.deferStop&&this.stop()}}stop(){B===this?this.deferStop=!0:this.active&&(Z(this),this.onStop&&this.onStop(),this.active=!1)}}function Z(t){const{deps:e}=t;if(e.length){for(let s=0;s<e.length;s++)e[s].delete(t);e.length=0}}let tt=!0;const et=[];function st(){et.push(tt),tt=!1}function nt(){const t=et.pop();tt=void 0===t||t}function it(t,e,s,n){if(tt&&B){let e=W.get(t);e||W.set(t,e=new Map);let n=e.get(s);n||e.set(s,n=K()),rt(n)}}function ot(t){if(tt&&B){let e=F.get(t);e||F.set(t,e=K()),rt(e)}}function rt(t){let e=!1;J<=30?H(t)||(t.n|=Y,e=!X(t)):e=!t.has(B),e&&(t.add(B),B.deps.push(t))}function ct(t){const e=F.get(t);if(e){const t=[...e];for(const e of t)e.view&&(e.view.mightChange=!0)}}function at(t,e,s,n,i,o){var r;const c=W.get(t),h=t.base;let u=[];if(c)if("clear"===e)u=[...c.values()];else if("length"===s&&a(h))c.forEach(((t,e)=>{("length"===e||e>=n)&&u.push(t)}));else switch(void 0!==s&&u.push(c.get(s)),e){case"add":a(h)?g(s)&&u.push(c.get("length")):(u.push(c.get(q)),l(h)&&u.push(c.get(z)));break;case"delete":a(h)||(u.push(c.get(q)),l(h)&&u.push(c.get(z)));break;case"set":l(h)&&u.push(c.get(q))}if(1===u.length)u[0]&&lt(u[0]);else{const t=[];for(const e of u)e&&t.push(...e);lt(K(t))}const f=null===(r=t.root)||void 0===r?void 0:r.listeners;f&&f.length&&f.forEach((t=>t()))}function lt(t){const e=a(t)?t:[...t];for(const s of e)s.view&&ht(s);for(const s of e)s.view||ht(s)}function ht(t){(t!==B||t.allowRecurse)&&(t.scheduler?t.scheduler():t.run())}class ut{constructor(t,{disableCache:e=!1}){this.dep=void 0,this.mightChange=!1,this._dirty=!0,this.effect=new Q(t,(()=>{this._dirty||(this._dirty=!0,function(t,e){(t=M(t)).dep&&lt(t.dep)}(this))})),this.effect.view=this,this.effect.active=this._cacheable=!e}get value(){const t=M(this);return function(t){tt&&B&&rt((t=M(t)).dep||(t.dep=K()))}(t),!t._dirty&&t._cacheable||(t._dirty=!1,t._value=t.effect.run()),t._value}set value(t){"development"===process.env.NODE_ENV&&R("Write operation failed: computed value is readonly")}}const ft=new Set(["__proto__"]),pt=new Set(Object.getOwnPropertyNames(Symbol).filter((t=>"arguments"!==t&&"caller"!==t)).map((t=>Symbol[t])).filter(p));function dt(t,e){const s=t.__r_state;return(s?I(s):t)[e]}const _t=bt(),yt=gt();function gt(){const t={};return["includes","indexOf","lastIndexOf"].forEach((e=>{t[e]=function(...t){const s=V(this),n=I(s);for(let e=0,o=this.length;e<o;e++)it(s,0,e+"",Reflect.get(n,e));const i=n[e](...t);return-1===i||!1===i?n[e](...t.map(M)):i}})),["push","pop","shift","unshift","splice"].forEach((e=>{t[e]=function(...t){st();const s=I(V(this))[e].apply(this,t);return nt(),s}})),t}function bt(){return function(t,e,s){const n=I(t);if("__r_isReactive"===e)return!0;if("__r_state"===e&&s===Ot.get(t))return t;if(a(n)&&o(yt,e))return Reflect.get(yt,e,s);let i=Reflect.get(n,e,s);if(p(e)?pt.has(e):ft.has(e))return i;if(it(t,0,e),!o(n,e))return i;if(t.disposed||!d(i))return i;if(!A(i)){k(t);const s=t.copy[e]=St(i,t);return V(s)&&ot(s.__r_state),s}ot(V(i));return i}}function vt(){return function(t,e,s,n){const i=I(t),r=dt(i,e),c=a(i)&&g(e)?Number(e)<i.length:o(i,e);if(!t.modified){const n=null==r?void 0:r.__r_state;if(n&&n.base===s)return t.copy[e]=s,t.assigned[e]=!1,!0;if(b(s,r)&&(void 0!==s||o(t.base,e)))return!0;k(t),T(t)}return b(t.copy[e],s)&&(void 0!==s||e in t.copy)||(t.copy[e]=s,t.assigned[e]=!0,t===V(n)&&(c?b(s,r)||at(t,"set",e,s):at(t,"add",e,s),function(t){let e=t;for(;e;)ct(e),e=e.parent}(t))),!0}}const wt={get:_t,set:vt(),deleteProperty:function(t,e){const s=o(I(t),e);if(void 0!==dt(t.base,e)||e in t.base?(t.assigned[e]=!1,k(t),T(t)):delete t.assigned[e],t.copy){const n=delete t.copy[e];return n&&s&&at(t,"delete",e,void 0),n}return!0},has:function(t,e){const s=I(t),n=Reflect.has(s,e);return p(e)&&pt.has(e)||it(t,0,e),n},ownKeys:function(t){const e=I(t);return it(t,0,a(e)?"length":q),Reflect.ownKeys(e)},setPrototypeOf:function(t,e){"development"===process.env.NODE_ENV&&R("not allow setPrototypeOf to set prototype");const s=Reflect.setPrototypeOf(t.base,e);return s&&t.copy&&Reflect.setPrototypeOf(t.copy,e),s},getOwnPropertyDescriptor:function(t,e){const s=I(t),n=Reflect.getOwnPropertyDescriptor(s,e);return n?{writable:!0,configurable:!a(s)||"length"!==e,enumerable:n.enumerable,value:s[e]}:n}};const Ot=new WeakMap;let mt=0;function St(t,e){if(!d(t))return"development"===process.env.NODE_ENV&&console.warn(`value cannot be made reactive: ${String(t)}`),t;if(t.__r_state)return t;var s;if(0===((s=t).__r_skip||!Object.isExtensible(s)?0:function(t){switch(t){case"Object":case"Array":return 1;case"Map":case"Set":case"WeakMap":case"WeakSet":return 2;default:return 0}}(_(s))))return t;const n=Array.isArray(t);let i={id:mt++,root:null,parent:e,base:t,proxy:null,copy:null,assigned:{},modified:!1,disposed:!1,listeners:[],children:[]};if(n){const t=i;i=[],Object.keys(t).forEach((e=>{Object.defineProperty(i,e,{configurable:!0,enumerable:!0,writable:!0,value:t[e]})}))}const o=new Proxy(i,wt);return i.proxy=o,e?(i.root=e.root,e.children.push(i)):i.root=i,i.children=[],Ot.set(i,o),i.proxy}function Et(t,e){const s=function(t){const e={get(s,n,i){const o=Reflect.get(s,n,i);return d(o)&&A(o)?new Proxy(t.get(o.__r_state),e):o},set:(t,e,s,n)=>Reflect.set(t,e,s,n),has:(t,e)=>Reflect.has(t,e),ownKeys:t=>Reflect.ownKeys(t)};return e}(e);if(A(t)){return new Proxy(e.get(t.__r_state),s)}return new Proxy(E(t),s)}function Nt(t,e){if(!d(t))return t;const s=function(t){const e=new Map;if(!A(t))return e;const s=[t.__r_state];for(;s.length;){const t=s.pop();let n;t.modified?(n=E(t.copy),jt(t,n)):n=t.base,e.set(t,n);for(const e of t.children)s.push(e)}return e}(e);return Et(t,s)}function jt(t,e){t.modified=!1,t.base=e,t.assigned={}}function xt(t,e){const s=t.createView((function(){return e(this,this.$actions)})),n=function(){return s.value};return n.destory=function(){s.effect.stop();const e=t.effectScope.effects.indexOf(s.effect);e>=0&&t.effectScope.effects.splice(e,1)},n}const Dt=s({$name:t=>t.name,$rawState:t=>t.getState(),$state:t=>t.isPrimitiveState?t.stateRef.value:t.stateValue,$actions:t=>t.actions,$views:t=>t.views,$patch:t=>t.patch,$onAction:t=>t.onAction,$subscribe:t=>t.subscribe,$isolate:t=>t.isolate,$getApi:t=>t.getApi,$createView:t=>xt.bind(null,t)}),Pt={get:({_:t},e)=>{const{actions:s,views:n,accessCache:i,accessContext:r,ctx:c,stateValue:a}=t;if("$"!==e[0]){const t=i[e];if(void 0!==t)switch(t){case 0:return a[e];case 2:return n[e];case 1:if(1===r)return;return s[e];case 3:return c[e]}else{if(o(a,e))return i[e]=0,a[e];if(o(n,e))return i[e]=2,n[e];if(o(s,e)){if(1===r)return;return i[e]=1,s[e]}if(o(c,e))return i[e]=3,c[e]}}const l=Dt[e];return l?l(t):o(c,e)?(i[e]=3,c[e]):void((t=>"_"===t||"$"===t)(e[0])&&o(a,e)&&R(`Property ${JSON.stringify(e)} must be accessed via $state because it starts with a reserved character ("$" or "_") and is not proxied on the render context.`))},set({_:t},e,s){const{ctx:n,actions:i,views:r,accessContext:c,stateRef:{value:a}}=t;return 1===c?("development"===process.env.NODE_ENV&&R("Cannot change state in view function",t),!1):o(a,e)?(a[e]=s,!0):"$state"===e?"bigint"==typeof s||"symbol"==typeof s?("development"===process.env.NODE_ENV&&R("'BigInt' and 'Symbol' are not assignable to the State"),!1):(t.replace(s),!0):o(i,e)?("development"===process.env.NODE_ENV&&R(`Attempting to mutate action "${e}". Actions are readonly.`,t),!1):o(r,e)?("development"===process.env.NODE_ENV&&R(`Attempting to mutate view "${e}". Views are readonly.`,t),!1):"$"===e[0]&&o(Dt,e)?("development"===process.env.NODE_ENV&&R(`Attempting to mutate public property "${e}". Properties starting with $ are reserved and readonly.`,t),!1):(n[e]=s,!0)},has({_:t},e){const{actions:s,views:n,accessCache:i,accessContext:r,ctx:c,stateValue:a}=t;return!!i[e]||o(a,e)||o(n,e)||1!==r&&o(s,e)||o(c,e)||o(Dt,e)}},Rt={0:"scheduler flush. This is likely a Doura internals bug. Please open an issue at https://github.com/dourajs/doura/issues/new"};function $t(t,e,...s){const n=Rt[e],i=n?"function"==typeof n?n.apply(null,s):n:"unknown error nr: "+$t;throw new Error(`[Doura] ${i}`)}process;let Ct=!1,At=!1;const Mt=[];let Vt=0;const It=[];let kt=null,Tt=0;const Lt=[];let Ut=null,Kt=0;const Xt=Promise.resolve();let Ht=null,Wt=null;function Ft(t){const e=Ht||Xt;return t?e.then(this?t.bind(this):t):e}function Jt(t){Mt.length&&Mt.includes(t,Ct&&t.allowRecurse?Vt+1:Vt)||t===Wt||(null==t.id?Mt.push(t):Mt.splice(function(t){let e=Vt+1,s=Mt.length;for(;e<s;){const n=e+s>>>1;Bt(Mt[n])<t?e=n+1:s=n}return e}(t.id),0,t),Ct||At||(At=!0,Ht=Xt.then(qt)))}function Yt(t,e=null){if(It.length){for(Wt=e,kt=[...new Set(It)],It.length=0,Tt=0;Tt<kt.length;Tt++)kt[Tt]();kt=null,Tt=0,Wt=null,Yt(t,e)}}const Bt=t=>null==t.id?1/0:t.id;function qt(e){At=!1,Ct=!0,Yt(e),Mt.sort(((t,e)=>Bt(t)-Bt(e)));const s=t;try{for(Vt=0;Vt<Mt.length;Vt++){const t=Mt[Vt];if(t&&!1!==t.active){if("development"===process.env.NODE_ENV&&s(t))continue;try{t()}catch(n){console.log("err",n),$t(0,0)}}}}finally{Vt=0,Mt.length=0,function(t){if(Yt(),Lt.length){const t=[...new Set(Lt)];if(Lt.length=0,Ut)return void Ut.push(...t);for(Ut=t,Ut.sort(((t,e)=>Bt(t)-Bt(e))),Kt=0;Kt<Ut.length;Kt++)Ut[Kt]();Ut=null,Kt=0}}(),Ct=!1,Ht=null,(Mt.length||It.length||Lt.length)&&qt(e)}}var zt;function Gt(t,e){const s=Object.keys(e);s.length&&s.forEach((s=>{o(t,s)&&y(e[s])?Gt(t[s],e[s]):t[s]=e[s]}))}!function(t){t.REPLACE="replace",t.MODIFY="modify",t.PATCH="patch"}(zt||(zt={}));class Qt{constructor(e,{name:s,initState:n}){this.viewInstances=[],this._api=null,this._actionListeners=new Set,this._subscribers=new Set,this._watchStateChange=!0,this._destroyed=!1,this.patch=this.patch.bind(this),this.onAction=this.onAction.bind(this),this.subscribe=this.subscribe.bind(this),this.isolate=this.isolate.bind(this),this.getApi=this.getApi.bind(this),this.options=e,this.name=s||"",this._isDispatching=!1,this._initState=n||e.state,this.stateRef=St({value:this._initState});const i=this._update.bind(this);var o;this._draftListenerHandler=function(e,s){const n=e.__r_state;return n.disposed?t:(n.listeners.push(s),()=>{const t=n.listeners.indexOf(s);t>=0&&n.listeners.splice(t,1)})}(this.stateRef,(()=>{this._watchStateChange&&Jt(i)})),this._setState(this._initState),this.actions=Object.create(null),this.views=Object.create(null),this.accessContext=0,this.ctx={},w(this.ctx,"_",this),this.accessCache=Object.create(null),this.proxy=new Proxy(this.ctx,Pt),this.effectScope=new U(o),this._initActions(),this._initViews()}patch(t){y(t)?this._currentState&&(this._watchStateChange=!1,Gt(this.proxy.$state,t),this._watchStateChange=!0,this.dispatch({type:zt.PATCH,payload:Nt(this.stateRef.value,this.stateRef.value),args:{patch:t}})):"development"===process.env.NODE_ENV&&R(`patch argument should be an object, but receive a ${Object.prototype.toString.call(t)}`)}replace(t){this._watchStateChange=!1,this.stateRef.value=t,this._watchStateChange=!0;for(const e of this.viewInstances)e.effect.scheduler();this.dispatch({type:zt.REPLACE,payload:t})}getState(){return this._currentState}getApi(){if(null===this._api){const t=this._api=Object.assign(Object.assign({},this._currentState),this.views);w(t,"$state",this._currentState);for(const e of Object.keys(this.actions))w(t,e,this.actions[e])}return this._api}onAction(t){return this._actionListeners.add(t),()=>{this._actionListeners.delete(t)}}subscribe(t){return this._subscribers.add(t),()=>{this._subscribers.delete(t)}}isolate(t){st();const e=t(this.stateValue);return nt(),e}depend(t){t.subscribe((t=>{this._triggerListener(Object.assign(Object.assign({},t),{model:this.proxy}))}))}createView(t){let e;return this.effectScope.run((()=>{e=function(t,e={}){return new ut(t,e)}((()=>{const e=this.accessContext;this.accessContext=1;try{let s=t.call(this.proxy,this.proxy);return"development"===process.env.NODE_ENV&&d(s)&&(s===this.proxy?R('detect returning "this" in view, it would cause unpected behavior'):s===this.proxy.$state&&R('detect returning "this.$state" in view, it would cause unpected behavior')),s}finally{this.accessContext=e}}))})),this.viewInstances.push(e),e}reducer(t,e){switch(e.type){case zt.REPLACE:case zt.MODIFY:case zt.PATCH:return e.payload;default:return t}}dispatch(t){if(void 0===t.type)return"development"===process.env.NODE_ENV&&R('Actions may not have an undefined "type" property. You may have misspelled an action type string constant.'),t;if(this._isDispatching)return"development"===process.env.NODE_ENV&&R("Cannot dispatch action from a reducer."),t;let e;try{this._isDispatching=!0,e=this.reducer(this._currentState,t)}finally{this._isDispatching=!1}return e!==this._currentState&&(this._setState(e),this._triggerListener(Object.assign({type:t.type,model:this.proxy,target:this.proxy},t.args))),t}destroy(){this._destroyed=!0,this._api=null,this._currentState=null,this.stateRef={value:null},this._subscribers.clear(),this.effectScope.stop(),this._draftListenerHandler()}_setState(t){this._api=null,this._currentState=t,this.isPrimitiveState=!d(t),this.stateValue=this.stateRef.value}_update(){!this._destroyed&&function(t){return t.__r_state.modified}(this.stateRef)&&this.dispatch({type:zt.MODIFY,payload:Nt(this.stateRef.value,this.stateRef)})}_triggerListener(t){for(const e of this._subscribers)e(t)}_initActions(){const t=this.options.actions;if(t){Object.keys(t).forEach((e=>{const s=t[e];Object.defineProperty(this.actions,e,{configurable:!0,enumerable:!0,writable:!1,value:(...t)=>{for(const s of this._actionListeners)s({name:e,args:t});let n;try{n=s.call(this.proxy,...t)}finally{this._update()}return n}})}))}}_initViews(){const t=this.options.views;if(t)for(const e of Object.keys(t)){const s=this.createView(t[e]),n=this;Object.defineProperty(this.views,e,{configurable:!0,enumerable:!0,get(){const t=s;let e=s.value;return s.mightChange?(s.mightChange=!1,t.__snapshot=Nt(e,n.stateRef.value)):t.__pre!==e&&(t.__snapshot=Nt(e,n.stateRef.value)),t.__pre=e,t.__snapshot},set:()=>("development"===process.env.NODE_ENV&&R(`cannot change view property '${String(e)}'`),!1)})}}}function Zt(t,e={}){return"development"===process.env.NODE_ENV&&(t=>{m(t.hasOwnProperty("state"),"state is required"),m("bigint"!=typeof t.state&&"symbol"!=typeof t.state,"state can not be BigInt or Symbol"),$(t,"actions"),$(t,"views");const e=new Map;C("state",t,e),C("views",t,e),e.clear(),C("actions",t,e)})(t),new Qt(t,e)}class te{constructor(t=e,s=[]){this._subscribers=new Set,this._initialState=t,this._models=(()=>{const t=new Map,e={get:e=>t.get(e),set(e,s){t.set(e,s)},each(e){for(const[s,n]of t.entries())e(n,s)},clear(){e.each((t=>t.destroy())),t.clear()}};return e})();const n=()=>{for(const t of this._subscribers)t()};this._onModelChange=()=>{Jt(n)},this._hooks=s.map((([t,e])=>t(e))),this._hooks.map((e=>{var s;return null===(s=e.onInit)||void 0===s?void 0:s.call(e,{initialState:t},{doura:this})}))}getModel(t,e){return this._getNamedModel(t,e).proxy}getDetachedModel(t){return this._getDetachedModel(t).proxy}getState(){const t={};return this._models.each(((e,s)=>{t[s]=e.getState()})),t}subscribe(t){return this._subscribers.add(t),()=>{this._subscribers.delete(t)}}destroy(){this._hooks.map((t=>{var e;return null===(e=t.onDestroy)||void 0===e?void 0:e.call(t)})),this._models.clear(),this._subscribers.clear(),this._initialState=e}_getNamedModel(t,e){let s=this._models.get(t);if(s)return s;if("function"==typeof e){const s=this._createUseContext();e=e({use:this._use.bind(this,s)});const n=this._initModel(t,e);return s.setInitiator(n),n}return this._initModel(t,e)}_createUseContext(){let t,e=[];return{add(s){t?t.depend(s):e.push(s)},setInitiator(s){if(!t){t=s;for(const s of e)t.depend(s);e.length=0}}}}_getDetachedModel(t){let e;if("function"==typeof t){const s=t,n=this._createUseContext();e=Zt(s({use:this._use.bind(this,n)})),n.setInitiator(e)}else{if("object"!=typeof t)throw new Error("invalid model");e=Zt(t)}return e}_use(t,e,s){let n;const i=t;if("string"==typeof e){n=this._getNamedModel(e,s)}else{n=this._getDetachedModel(e)}return i&&i.add(n),n.proxy}_initModel(t,e){this._hooks.map((s=>{var n;return null===(n=s.onModel)||void 0===n?void 0:n.call(s,t,e,{doura:this})}));const s=Zt(e,{name:t,initState:this._getInitialState(t)});return s.subscribe(this._onModelChange),this._models.set(t,s),this._hooks.map((t=>{var e;null===(e=t.onModelInstance)||void 0===e||e.call(t,s.proxy,{doura:this})})),s}_getInitialState(t){const e=this._initialState[t];return e&&delete this._initialState[t],e}}function ee({initialState:t,plugins:e=[]}={}){return function({initialState:t,plugins:e}={}){return new te(t,e)}({initialState:t,plugins:e})}var se=function(){if("undefined"==typeof window||!window.__REDUX_DEVTOOLS_EXTENSION__)return{};let t=0;const e=new Set;let s;return{onInit({},{doura:n}){if(window.__doura=n,"undefined"!=typeof window&&window.__REDUX_DEVTOOLS_EXTENSION__){s=window.__REDUX_DEVTOOLS_EXTENSION__.connect({name:`doura${0===t?"":t}`}),t+=1,s.init(n.getState());const i=t=>{switch(t.type){case"ACTION":return void m("string"==typeof t.payload,"Unsupported action format");case"DISPATCH":switch(t.payload.type){case"RESET":case"COMMIT":return s.init(n.getState());case"ROLLBACK":try{const e=JSON.parse(t.state);return s.init(e)}catch(e){console.warn("[Doura Devtool] Could not parse the received json.")}return s.init(n.getState());case"JUMP_TO_STATE":case"JUMP_TO_ACTION":return}}};e.add(s.subscribe(i))}},onModelInstance(t,{doura:e}){t.$subscribe((t=>{var{type:n,model:i}=t,o=function(t,e){var s={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(s[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(n=Object.getOwnPropertySymbols(t);i<n.length;i++)e.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(t,n[i])&&(s[n[i]]=t[n[i]])}return s}(t,["type","target","model"]);const r=e.getState();delete r._,s.send(Object.assign({type:`${i.$name||"anonymous"}@${n}`},o),r)}))},onDestroy(){window.__REDUX_DEVTOOLS_EXTENSION__.disconnect(s);for(const t of e.values())t();e.clear()}}};export{t as NOOP,s as assign,v as capitalize,w as def,P as defineModel,se as devtool,ee as doura,x as each,e as emptyObject,n as extend,o as hasOwn,m as invariant,b as is,a as isArray,N as isFrozen,u as isFunction,g as isIntegerKey,l as isMap,d as isObject,y as isPlainObject,h as isSet,f as isString,p as isSymbol,Ft as nextTick,r as objectToString,j as ownKeys,O as patchObj,D as set,E as shallowCopy,_ as toRawType,c as toTypeString};
const t=()=>{},e=Object.create(null),s=Object.assign,n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var s in e)e.hasOwnProperty(s)&&(t[s]=e[s])},i=Object.prototype.hasOwnProperty,o=(t,e)=>i.call(t,e),r=Object.prototype.toString,c=t=>r.call(t),a=Array.isArray,l=t=>"[object Map]"===c(t),h=t=>"[object Set]"===c(t),u=t=>"function"==typeof t,f=t=>"string"==typeof t,p=t=>"symbol"==typeof t,d=t=>null!==t&&"object"==typeof t,_=t=>c(t).slice(8,-1),y=t=>"[object Object]"===c(t),g=t=>f(t)&&"NaN"!==t&&"-"!==t[0]&&""+parseInt(t,10)===t,b=(t,e)=>Object.is(t,e),v=(t,e,s)=>{Object.defineProperty(t,e,{configurable:!0,enumerable:!1,value:s})};function w(t,e){if(!t)throw new Error(`[Doura] ${e||""}`)}const O=Array.prototype.slice;function m(t){if(Array.isArray(t))return O.call(t);const e=Object.getOwnPropertyDescriptors(t);let s=Reflect.ownKeys(e);for(let n=0;n<s.length;n++){const i=s[n],o=e[i];!1===o.writable&&(o.writable=!0,o.configurable=!0),(o.get||o.set)&&(e[i]={configurable:!0,writable:!0,enumerable:o.enumerable,value:t[i]})}return Object.create(Object.getPrototypeOf(t),e)}const S="undefined"!=typeof Reflect&&Reflect.ownKeys?Reflect.ownKeys:void 0!==Object.getOwnPropertySymbols?t=>Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t)):Object.getOwnPropertyNames;function E(t,e,s=!1){y(t)?(s?Object.keys:S)(t).forEach((n=>{s&&"symbol"==typeof n||e(n,t[n],t)})):t.forEach(((s,n)=>e(n,s,t)))}function N(t,e,s){l(t)?t.set(e,s):h(t)?(t.delete(e),t.add(s)):t[e]=s}const x=t=>t;function j(t,...e){console.warn(`[Doura warn] ${t}`,...e)}function D(t,e,s){const n=t[e];n&&w(y(n),`model.${e} should be object!`)}function P(t,e,s){if(e[t])for(const n of Object.keys(e[t]))if(s.has(n)){j(`key "${n}" in "${t}" is conflicted with the key in "${s.get(n)}"`)}else s.set(n,t)}function R(t){return!!t&&!!t.__r_state}function $(t){const e=C(t);return e?$(e.base):t}function C(t){return t&&t.__r_state}function A(t){return t.copy||t.base}function M(t){t.copy||(t.copy=m(t.base))}function V(t){t.modified||(t.modified=!0,t.parent&&V(t.parent))}let I;class k{constructor(t=!1){this.active=!0,this.effects=[],this.cleanups=[],!t&&I&&(this.parent=I,this.index=(I.scopes||(I.scopes=[])).push(this)-1)}run(t){if(this.active){const e=I;try{return I=this,t()}finally{I=e}}else"development"===process.env.NODE_ENV&&j("cannot run an inactive effect scope.")}on(){I=this}off(){I=this.parent}stop(t){if(this.active){let e,s;for(e=0,s=this.effects.length;e<s;e++)this.effects[e].stop();for(e=0,s=this.cleanups.length;e<s;e++)this.cleanups[e]();if(this.scopes)for(e=0,s=this.scopes.length;e<s;e++)this.scopes[e].stop(!0);if(this.parent&&!t){const t=this.parent.scopes.pop();t&&t!==this&&(this.parent.scopes[this.index]=t,t.index=this.index)}this.active=!1}}}const L=t=>{const e=new Set(t);return e.w=0,e.n=0,e},T=t=>(t.w&W)>0,U=t=>(t.n&W)>0,H=new WeakMap,K=new WeakMap;let X=0,W=1;let J;const Y=Symbol("development"===process.env.NODE_ENV?"iterate":""),B=Symbol("development"===process.env.NODE_ENV?"Map key iterate":"");let F=0;class q{constructor(t,e=null,s){this.fn=t,this.scheduler=e,this.id=F++,this.deps=[],this.active=!0,this.parent=void 0,function(t,e=I){e&&e.active&&e.effects.push(t)}(this,s)}run(){if(!this.active)return this.fn();let t=J,e=G;for(;t;){if(t===this)return;t=t.parent}try{return this.parent=J,J=this,G=!0,W=1<<++X,X<=30?(({deps:t})=>{if(t.length)for(let e=0;e<t.length;e++)t[e].w|=W})(this):z(this),this.fn()}finally{X<=30&&(t=>{const{deps:e}=t;if(e.length){let s=0;for(let n=0;n<e.length;n++){const i=e[n];T(i)&&!U(i)?i.delete(t):e[s++]=i,i.w&=~W,i.n&=~W}e.length=s}})(this),W=1<<--X,J=this.parent,G=e,this.parent=void 0,this.deferStop&&this.stop()}}stop(){J===this?this.deferStop=!0:this.active&&(z(this),this.onStop&&this.onStop(),this.active=!1)}}function z(t){const{deps:e}=t;if(e.length){for(let s=0;s<e.length;s++)e[s].delete(t);e.length=0}}let G=!0;const Q=[];function Z(){Q.push(G),G=!1}function tt(){const t=Q.pop();G=void 0===t||t}function et(t,e,s,n){if(G&&J){let e=H.get(t);e||H.set(t,e=new Map);let n=e.get(s);n||e.set(s,n=L()),nt(n)}}function st(t){if(G&&J){let e=K.get(t);e||K.set(t,e=L()),nt(e)}}function nt(t){let e=!1;X<=30?U(t)||(t.n|=W,e=!T(t)):e=!t.has(J),e&&(t.add(J),J.deps.push(t))}function it(t){const e=K.get(t);if(e){const t=[...e];for(const e of t)e.view&&(e.view.mightChange=!0)}}function ot(t,e,s,n,i,o){var r;const c=H.get(t),h=t.base;let u=[];if(c)if("clear"===e)u=[...c.values()];else if("length"===s&&a(h))c.forEach(((t,e)=>{("length"===e||e>=n)&&u.push(t)}));else switch(void 0!==s&&u.push(c.get(s)),e){case"add":a(h)?g(s)&&u.push(c.get("length")):(u.push(c.get(Y)),l(h)&&u.push(c.get(B)));break;case"delete":a(h)||(u.push(c.get(Y)),l(h)&&u.push(c.get(B)));break;case"set":l(h)&&u.push(c.get(Y))}if(1===u.length)u[0]&&rt(u[0]);else{const t=[];for(const e of u)e&&t.push(...e);rt(L(t))}const f=null===(r=t.root)||void 0===r?void 0:r.listeners;f&&f.length&&f.forEach((t=>t()))}function rt(t){const e=a(t)?t:[...t];for(const s of e)s.view&&ct(s);for(const s of e)s.view||ct(s)}function ct(t){(t!==J||t.allowRecurse)&&(t.scheduler?t.scheduler():t.run())}class at{constructor(t,{disableCache:e=!1}){this.dep=void 0,this.mightChange=!1,this._dirty=!0,this.effect=new q(t,(()=>{this._dirty||(this._dirty=!0,function(t,e){(t=$(t)).dep&&rt(t.dep)}(this))})),this.effect.view=this,this.effect.active=this._cacheable=!e}get value(){const t=$(this);return function(t){G&&J&&nt((t=$(t)).dep||(t.dep=L()))}(t),!t._dirty&&t._cacheable||(t._dirty=!1,t._value=t.effect.run()),t._value}set value(t){"development"===process.env.NODE_ENV&&j("Write operation failed: computed value is readonly")}}const lt=new Set(["__proto__"]),ht=new Set(Object.getOwnPropertyNames(Symbol).filter((t=>"arguments"!==t&&"caller"!==t)).map((t=>Symbol[t])).filter(p));function ut(t,e){const s=t.__r_state;return(s?A(s):t)[e]}const ft=_t(),pt=dt();function dt(){const t={};return["includes","indexOf","lastIndexOf"].forEach((e=>{t[e]=function(...t){const s=C(this),n=A(s);for(let e=0,o=this.length;e<o;e++)et(s,0,e+"",Reflect.get(n,e));const i=n[e](...t);return-1===i||!1===i?n[e](...t.map($)):i}})),["push","pop","shift","unshift","splice"].forEach((e=>{t[e]=function(...t){Z();const s=A(C(this))[e].apply(this,t);return tt(),s}})),t}function _t(){return function(t,e,s){const n=A(t);if("__r_isReactive"===e)return!0;if("__r_state"===e&&s===bt.get(t))return t;if(a(n)&&o(pt,e))return Reflect.get(pt,e,s);let i=Reflect.get(n,e,s);if(p(e)?ht.has(e):lt.has(e))return i;if(et(t,0,e),!o(n,e))return i;if(t.disposed||!d(i))return i;if(!R(i)){M(t);const s=t.copy[e]=wt(i,t);return C(s)&&st(s.__r_state),s}st(C(i));return i}}function yt(){return function(t,e,s,n){const i=A(t),r=ut(i,e),c=a(i)&&g(e)?Number(e)<i.length:o(i,e);if(!t.modified){const n=null==r?void 0:r.__r_state;if(n&&n.base===s)return t.copy[e]=s,t.assigned[e]=!1,!0;if(b(s,r)&&(void 0!==s||o(t.base,e)))return!0;M(t),V(t)}return b(t.copy[e],s)&&(void 0!==s||e in t.copy)||(t.copy[e]=s,t.assigned[e]=!0,t===C(n)&&(c?b(s,r)||ot(t,"set",e,s):ot(t,"add",e,s),function(t){let e=t;for(;e;)it(e),e=e.parent}(t))),!0}}const gt={get:ft,set:yt(),deleteProperty:function(t,e){const s=o(A(t),e);if(void 0!==ut(t.base,e)||e in t.base?(t.assigned[e]=!1,M(t),V(t)):delete t.assigned[e],t.copy){const n=delete t.copy[e];return n&&s&&ot(t,"delete",e,void 0),n}return!0},has:function(t,e){const s=A(t),n=Reflect.has(s,e);return p(e)&&ht.has(e)||et(t,0,e),n},ownKeys:function(t){const e=A(t);return et(t,0,a(e)?"length":Y),Reflect.ownKeys(e)},setPrototypeOf:function(t,e){"development"===process.env.NODE_ENV&&j("not allow setPrototypeOf to set prototype");const s=Reflect.setPrototypeOf(t.base,e);return s&&t.copy&&Reflect.setPrototypeOf(t.copy,e),s},getOwnPropertyDescriptor:function(t,e){const s=A(t),n=Reflect.getOwnPropertyDescriptor(s,e);return n?{writable:!0,configurable:!a(s)||"length"!==e,enumerable:n.enumerable,value:s[e]}:n}};const bt=new WeakMap;let vt=0;function wt(t,e){if(!d(t))return"development"===process.env.NODE_ENV&&console.warn(`value cannot be made reactive: ${String(t)}`),t;if(t.__r_state)return t;var s;if(0===((s=t).__r_skip||!Object.isExtensible(s)?0:function(t){switch(t){case"Object":case"Array":return 1;case"Map":case"Set":case"WeakMap":case"WeakSet":return 2;default:return 0}}(_(s))))return t;const n=Array.isArray(t);let i={id:vt++,root:null,parent:e,base:t,proxy:null,copy:null,assigned:{},modified:!1,disposed:!1,listeners:[],children:[]};if(n){const t=i;i=[],Object.keys(t).forEach((e=>{Object.defineProperty(i,e,{configurable:!0,enumerable:!0,writable:!0,value:t[e]})}))}const o=new Proxy(i,gt);return i.proxy=o,e?(i.root=e.root,e.children.push(i)):i.root=i,i.children=[],bt.set(i,o),i.proxy}function Ot(t,e){const s=function({copies:t,proxies:e}){const s={get(n,i,o){const r=Reflect.get(n,i,o);if(!d(r))return r;if(R(r)){let n=e.get(r);return n||e.set(r,n=new Proxy(t.get(r.__r_state),s)),n}return r},set:(t,e,s,n)=>Reflect.set(t,e,s,n),has:(t,e)=>Reflect.has(t,e),ownKeys:t=>Reflect.ownKeys(t)};return s}(e);if(R(t)){return new Proxy(e.copies.get(t.__r_state),s)}return new Proxy(m(t),s)}function mt(t,e){if(!d(t))return t;const s=function(t){const e=new Map,s={copies:e,proxies:new Map},n=[t.__r_state];for(;n.length;){const t=n.pop();let s;t.modified?(s=m(t.copy),St(t,s)):s=t.base,e.set(t,s);for(const e of t.children)n.push(e)}return s}(e);return Ot(t,s)}function St(t,e){t.modified=!1,t.base=e,t.assigned={}}function Et(t,e){const s=t.createView((function(){return e(this,this.$actions)})),n=function(){return s.value};return n.destory=function(){s.effect.stop();const e=t.effectScope.effects.indexOf(s.effect);e>=0&&t.effectScope.effects.splice(e,1)},n}const Nt=s({$name:t=>t.name,$rawState:t=>t.getState(),$state:t=>t.stateValue,$actions:t=>t.actions,$views:t=>t.views,$patch:t=>t.patch,$onAction:t=>t.onAction,$subscribe:t=>t.subscribe,$isolate:t=>t.isolate,$getApi:t=>t.getApi,$createView:t=>Et.bind(null,t)}),xt={get:({_:t},e)=>{const{actions:s,views:n,accessCache:i,accessContext:r,ctx:c,stateValue:a}=t;if("$"!==e[0]){const t=i[e];if(void 0!==t)switch(t){case 0:return a[e];case 2:return n[e];case 1:if(1===r)return;return s[e];case 3:return c[e]}else{if(o(a,e))return i[e]=0,a[e];if(o(n,e))return i[e]=2,n[e];if(o(s,e)){if(1===r)return;return i[e]=1,s[e]}if(o(c,e))return i[e]=3,c[e]}}const l=Nt[e];return l?l(t):o(c,e)?(i[e]=3,c[e]):void((t=>"_"===t||"$"===t)(e[0])&&o(a,e)&&j(`Property ${JSON.stringify(e)} must be accessed via $state because it starts with a reserved character ("$" or "_") and is not proxied on the render context.`))},set({_:t},e,s){const{ctx:n,actions:i,views:r,accessContext:c,stateRef:{value:a}}=t;return 1===c?("development"===process.env.NODE_ENV&&j("Cannot change state in view function",t),!1):o(a,e)?(a[e]=s,!0):"$state"===e?"bigint"==typeof s||"symbol"==typeof s?("development"===process.env.NODE_ENV&&j("'BigInt' and 'Symbol' are not assignable to the State"),!1):(t.replace(s),!0):o(i,e)?("development"===process.env.NODE_ENV&&j(`Attempting to mutate action "${e}". Actions are readonly.`,t),!1):o(r,e)?("development"===process.env.NODE_ENV&&j(`Attempting to mutate view "${e}". Views are readonly.`,t),!1):"$"===e[0]&&o(Nt,e)?("development"===process.env.NODE_ENV&&j(`Attempting to mutate public property "${e}". Properties starting with $ are reserved and readonly.`,t),!1):(n[e]=s,!0)},has({_:t},e){const{actions:s,views:n,accessCache:i,accessContext:r,ctx:c,stateValue:a}=t;return!!i[e]||o(a,e)||o(n,e)||1!==r&&o(s,e)||o(c,e)||o(Nt,e)}},jt={0:"scheduler flush. This is likely a Doura internals bug. Please open an issue at https://github.com/dourajs/doura/issues/new"};function Dt(t,e,...s){const n=jt[e],i=n?"function"==typeof n?n.apply(null,s):n:"unknown error nr: "+Dt;throw new Error(`[Doura] ${i}`)}process;let Pt=!1,Rt=!1;const $t=[];let Ct=0;const At=[];let Mt=null,Vt=0;const It=[];let kt=null,Lt=0;const Tt=Promise.resolve();let Ut=null,Ht=null;function Kt(t){const e=Ut||Tt;return t?e.then(this?t.bind(this):t):e}function Xt(t){$t.length&&$t.includes(t,Pt&&t.allowRecurse?Ct+1:Ct)||t===Ht||(null==t.id?$t.push(t):$t.splice(function(t){let e=Ct+1,s=$t.length;for(;e<s;){const n=e+s>>>1;Jt($t[n])<t?e=n+1:s=n}return e}(t.id),0,t),Pt||Rt||(Rt=!0,Ut=Tt.then(Yt)))}function Wt(t,e=null){if(At.length){for(Ht=e,Mt=[...new Set(At)],At.length=0,Vt=0;Vt<Mt.length;Vt++)Mt[Vt]();Mt=null,Vt=0,Ht=null,Wt(t,e)}}const Jt=t=>null==t.id?1/0:t.id;function Yt(e){Rt=!1,Pt=!0,Wt(e),$t.sort(((t,e)=>Jt(t)-Jt(e)));const s=t;try{for(Ct=0;Ct<$t.length;Ct++){const t=$t[Ct];if(t&&!1!==t.active){if("development"===process.env.NODE_ENV&&s(t))continue;try{t()}catch(n){console.log("err",n),Dt(0,0)}}}}finally{Ct=0,$t.length=0,function(t){if(Wt(),It.length){const t=[...new Set(It)];if(It.length=0,kt)return void kt.push(...t);for(kt=t,kt.sort(((t,e)=>Jt(t)-Jt(e))),Lt=0;Lt<kt.length;Lt++)kt[Lt]();kt=null,Lt=0}}(),Pt=!1,Ut=null,($t.length||At.length||It.length)&&Yt(e)}}var Bt;function Ft(t,e){const s=Object.keys(e);s.length&&s.forEach((s=>{o(t,s)&&y(e[s])?Ft(t[s],e[s]):t[s]=e[s]}))}!function(t){t.REPLACE="replace",t.MODIFY="modify",t.PATCH="patch"}(Bt||(Bt={}));class qt{constructor(e,{name:s,initState:n}){this.viewInstances=[],this._api=null,this._actionListeners=new Set,this._subscribers=new Set,this._depListenersHandlers=[],this._watchStateChange=!0,this._destroyed=!1,this.patch=this.patch.bind(this),this.onAction=this.onAction.bind(this),this.subscribe=this.subscribe.bind(this),this.isolate=this.isolate.bind(this),this.getApi=this.getApi.bind(this),this.options=e,this.name=s||"",this._isDispatching=!1,this._initState=n||e.state,this.stateRef=wt({value:this._initState});const i=this._update.bind(this);var o;this._draftListenerHandler=function(e,s){const n=e.__r_state;return n.disposed?t:(n.listeners.push(s),()=>{const t=n.listeners.indexOf(s);t>=0&&n.listeners.splice(t,1)})}(this.stateRef,(()=>{this._watchStateChange&&Xt(i)})),this._setState(this._initState),this.actions=Object.create(null),this.views=Object.create(null),this.accessContext=0,this.ctx={},v(this.ctx,"_",this),this.accessCache=Object.create(null),this.proxy=new Proxy(this.ctx,xt),this.effectScope=new k(o),this._initActions(),this._initViews()}patch(t){y(t)?this._currentState&&(this._watchStateChange=!1,Ft(this.proxy.$state,t),this._watchStateChange=!0,this.dispatch({type:Bt.PATCH,payload:mt(this.stateRef.value,this.stateRef.value),args:{patch:t}})):"development"===process.env.NODE_ENV&&j(`patch argument should be an object, but receive a ${Object.prototype.toString.call(t)}`)}replace(t){this._watchStateChange=!1,this.stateRef.value=t,this._watchStateChange=!0;for(const e of this.viewInstances)e.effect.scheduler();this.dispatch({type:Bt.REPLACE,payload:t})}getState(){return this._currentState}getApi(){if(null===this._api){const t=this._api=Object.assign(Object.assign({},this._currentState),this.views);for(const e of Object.keys(this.actions))v(t,e,this.actions[e])}return this._api}onAction(t){return this._actionListeners.add(t),()=>{this._actionListeners.delete(t)}}subscribe(t){return this._subscribers.add(t),()=>{this._subscribers.delete(t)}}isolate(t){Z();const e=t(this.stateValue);return tt(),e}depend(t){this._depListenersHandlers.push(t.subscribe((t=>{this._triggerListener(Object.assign(Object.assign({},t),{model:this.proxy}))})))}createView(t){let e;return this.effectScope.run((()=>{e=function(t,e={}){return new at(t,e)}((()=>{const e=this.accessContext;this.accessContext=1;try{let s=t.call(this.proxy,this.proxy);return"development"===process.env.NODE_ENV&&d(s)&&(s===this.proxy?j('detect returning "this" in view, it would cause unpected behavior'):s===this.proxy.$state&&j('detect returning "this.$state" in view, it would cause unpected behavior')),s}finally{this.accessContext=e}}))})),this.viewInstances.push(e),e}reducer(t,e){switch(e.type){case Bt.REPLACE:case Bt.MODIFY:case Bt.PATCH:return e.payload;default:return t}}dispatch(t){if(void 0===t.type)return"development"===process.env.NODE_ENV&&j('Actions may not have an undefined "type" property. You may have misspelled an action type string constant.'),t;if(this._isDispatching)return"development"===process.env.NODE_ENV&&j("Cannot dispatch action from a reducer."),t;let e;try{this._isDispatching=!0,e=this.reducer(this._currentState,t)}finally{this._isDispatching=!1}return e!==this._currentState&&(this._setState(e),this._triggerListener(Object.assign({type:t.type,model:this.proxy,target:this.proxy},t.args))),t}destroy(){this._destroyed=!0,this._api=null,this._currentState=null,this.stateRef={value:null},this._subscribers.clear(),this.effectScope.stop();for(const t of this._depListenersHandlers)t();this._draftListenerHandler()}_setState(t){this._api=null,this._currentState=t,this.stateValue=this.stateRef.value}_update(){!this._destroyed&&function(t){return t.__r_state.modified}(this.stateRef)&&this.dispatch({type:Bt.MODIFY,payload:mt(this.stateRef.value,this.stateRef)})}_triggerListener(t){for(const e of this._subscribers)e(t)}_initActions(){const t=this.options.actions;if(t){Object.keys(t).forEach((e=>{const s=t[e];Object.defineProperty(this.actions,e,{configurable:!0,enumerable:!0,writable:!1,value:(...t)=>{for(const s of this._actionListeners)s({name:e,args:t});let n;try{n=s.call(this.proxy,...t)}finally{this._update()}return n}})}))}}_initViews(){const t=this.options.views;if(t)for(const e of Object.keys(t)){const s=this.createView(t[e]),n=this;Object.defineProperty(this.views,e,{configurable:!0,enumerable:!0,get(){const t=s;let e=s.value;return s.mightChange?(s.mightChange=!1,t.__snapshot=mt(e,n.stateRef.value)):t.__pre!==e&&(t.__snapshot=mt(e,n.stateRef.value)),t.__pre=e,t.__snapshot},set:()=>("development"===process.env.NODE_ENV&&j(`cannot change view property '${String(e)}'`),!1)})}}}function zt(t,e={}){return"development"===process.env.NODE_ENV&&(t=>{w(t.hasOwnProperty("state"),"state is required"),w("bigint"!=typeof t.state&&"symbol"!=typeof t.state,"state can not be BigInt or Symbol"),D(t,"actions"),D(t,"views");const e=new Map;P("state",t,e),P("views",t,e),e.clear(),P("actions",t,e)})(t),new qt(t,e)}class Gt{constructor(t=e,s=[]){this._subscribers=new Set,this._initialState=t,this._models=(()=>{const t=new Map,e={get:e=>t.get(e),set(e,s){t.set(e,s)},each(e){for(const[s,n]of t.entries())e(n,s)},clear(){e.each((t=>t.destroy())),t.clear()}};return e})();const n=()=>{for(const t of this._subscribers)t()};this._onModelChange=()=>{Xt(n)},this._hooks=s.map((([t,e])=>t(e))),this._hooks.map((e=>{var s;return null===(s=e.onInit)||void 0===s?void 0:s.call(e,{initialState:t},{doura:this})}))}getModel(t,e){return this._getNamedModel(t,e).proxy}getDetachedModel(t){return this._getDetachedModel(t).proxy}getState(){const t={};return this._models.each(((e,s)=>{t[s]=e.getState()})),t}subscribe(t){return this._subscribers.add(t),()=>{this._subscribers.delete(t)}}destroy(){this._hooks.map((t=>{var e;return null===(e=t.onDestroy)||void 0===e?void 0:e.call(t)})),this._models.clear(),this._subscribers.clear(),this._initialState=e}_getNamedModel(t,e){let s=this._models.get(t);if(s)return s;if("function"==typeof e){const s=this._createUseContext();e=e({use:this._use.bind(this,s)});const n=this._initModel(t,e);return s.setInitiator(n),n}return this._initModel(t,e)}_createUseContext(){let t,e=[];return{add(s){t?t.depend(s):e.push(s)},setInitiator(s){if(!t){t=s;for(const s of e)t.depend(s);e.length=0}}}}_getDetachedModel(t){let e;if("function"==typeof t){const s=t,n=this._createUseContext();e=zt(s({use:this._use.bind(this,n)})),n.setInitiator(e)}else{if("object"!=typeof t)throw new Error("invalid model");e=zt(t)}return e}_use(t,e,s){let n;const i=t;if("string"==typeof e){n=this._getNamedModel(e,s)}else{n=this._getDetachedModel(e)}return i&&i.add(n),n.proxy}_initModel(t,e){this._hooks.map((s=>{var n;return null===(n=s.onModel)||void 0===n?void 0:n.call(s,t,e,{doura:this})}));const s=zt(e,{name:t,initState:this._getInitialState(t)});return s.subscribe(this._onModelChange),this._models.set(t,s),this._hooks.map((t=>{var e;null===(e=t.onModelInstance)||void 0===e||e.call(t,s.proxy,{doura:this})})),s}_getInitialState(t){const e=this._initialState[t];return e&&delete this._initialState[t],e}}function Qt({initialState:t,plugins:e=[]}={}){return function({initialState:t,plugins:e}={}){return new Gt(t,e)}({initialState:t,plugins:e})}var Zt=function(){if("undefined"==typeof window||!window.__REDUX_DEVTOOLS_EXTENSION__)return{};let t=0;const e=new Set;let s;return{onInit({},{doura:n}){if(window.__doura=n,"undefined"!=typeof window&&window.__REDUX_DEVTOOLS_EXTENSION__){s=window.__REDUX_DEVTOOLS_EXTENSION__.connect({name:`doura${0===t?"":t}`}),t+=1,s.init(n.getState());const i=t=>{switch(t.type){case"ACTION":return void w("string"==typeof t.payload,"Unsupported action format");case"DISPATCH":switch(t.payload.type){case"RESET":case"COMMIT":return s.init(n.getState());case"ROLLBACK":try{const e=JSON.parse(t.state);return s.init(e)}catch(e){console.warn("[Doura Devtool] Could not parse the received json.")}return s.init(n.getState());case"JUMP_TO_STATE":case"JUMP_TO_ACTION":return}}};e.add(s.subscribe(i))}},onModelInstance(t,{doura:e}){t.$subscribe((t=>{var{type:n,model:i}=t,o=function(t,e){var s={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(s[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(n=Object.getOwnPropertySymbols(t);i<n.length;i++)e.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(t,n[i])&&(s[n[i]]=t[n[i]])}return s}(t,["type","target","model"]);const r=e.getState();delete r._,s.send(Object.assign({type:`${i.$name||"anonymous"}@${n}`},o),r)}))},onDestroy(){window.__REDUX_DEVTOOLS_EXTENSION__.disconnect(s);for(const t of e.values())t();e.clear()}}};export{t as NOOP,s as assign,v as def,x as defineModel,Zt as devtool,Qt as doura,E as each,e as emptyObject,n as extend,o as hasOwn,w as invariant,b as is,a as isArray,u as isFunction,g as isIntegerKey,l as isMap,d as isObject,y as isPlainObject,h as isSet,f as isString,p as isSymbol,Kt as nextTick,r as objectToString,S as ownKeys,N as set,m as shallowCopy,_ as toRawType,c as toTypeString};

@@ -1,1 +0,1 @@

var Doura=function(t){"use strict";const e=()=>{},s=Object.create(null),n=Object.assign,i=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var s in e)e.hasOwnProperty(s)&&(t[s]=e[s])},o=Object.prototype.hasOwnProperty,r=(t,e)=>o.call(t,e),c=Object.prototype.toString,a=t=>c.call(t),l=Array.isArray,h=t=>"[object Map]"===a(t),u=t=>"[object Set]"===a(t),f=t=>"string"==typeof t,p=t=>"symbol"==typeof t,d=t=>null!==t&&"object"==typeof t,_=t=>a(t).slice(8,-1),y=t=>"[object Object]"===a(t),g=t=>f(t)&&"NaN"!==t&&"-"!==t[0]&&""+parseInt(t,10)===t,b=(t,e)=>Object.is(t,e),v=(t=>{const e=Object.create(null);return s=>e[s]||(e[s]=t(s))})((t=>t.charAt(0).toUpperCase()+t.slice(1))),w=(t,e,s)=>{Object.defineProperty(t,e,{configurable:!0,enumerable:!1,value:s})};function O(t,e){if(!t)throw new Error(`[Doura] ${e||""}`)}const m=Array.prototype.slice;function S(t){if(Array.isArray(t))return m.call(t);const e=Object.getOwnPropertyDescriptors(t);let s=Reflect.ownKeys(e);for(let n=0;n<s.length;n++){const i=s[n],o=e[i];!1===o.writable&&(o.writable=!0,o.configurable=!0),(o.get||o.set)&&(e[i]={configurable:!0,writable:!0,enumerable:o.enumerable,value:t[i]})}return Object.create(Object.getPrototypeOf(t),e)}const E="undefined"!=typeof Reflect&&Reflect.ownKeys?Reflect.ownKeys:void 0!==Object.getOwnPropertySymbols?t=>Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t)):Object.getOwnPropertyNames;function j(t,...e){console.warn(`[Doura warn] ${t}`,...e)}function N(t,e,s){const n=t[e];n&&O(y(n),`model.${e} should be object!`)}function x(t,e,s){if(e[t])for(const n of Object.keys(e[t]))if(s.has(n)){j(`key "${n}" in "${t}" is conflicted with the key in "${s.get(n)}"`)}else s.set(n,t)}function D(t){return!!t&&!!t.__r_state}function P(t){const e=R(t);return e?P(e.base):t}function R(t){return t&&t.__r_state}function C(t){return t.copy||t.base}function $(t){t.copy||(t.copy=S(t.base))}function A(t){t.modified||(t.modified=!0,t.parent&&A(t.parent))}let M;class V{constructor(t=!1){this.active=!0,this.effects=[],this.cleanups=[],!t&&M&&(this.parent=M,this.index=(M.scopes||(M.scopes=[])).push(this)-1)}run(t){if(this.active){const e=M;try{return M=this,t()}finally{M=e}}else"development"===process.env.NODE_ENV&&j("cannot run an inactive effect scope.")}on(){M=this}off(){M=this.parent}stop(t){if(this.active){let e,s;for(e=0,s=this.effects.length;e<s;e++)this.effects[e].stop();for(e=0,s=this.cleanups.length;e<s;e++)this.cleanups[e]();if(this.scopes)for(e=0,s=this.scopes.length;e<s;e++)this.scopes[e].stop(!0);if(this.parent&&!t){const t=this.parent.scopes.pop();t&&t!==this&&(this.parent.scopes[this.index]=t,t.index=this.index)}this.active=!1}}}const I=t=>{const e=new Set(t);return e.w=0,e.n=0,e},k=t=>(t.w&X)>0,T=t=>(t.n&X)>0,L=new WeakMap,U=new WeakMap;let K=0,X=1;let F;const H=Symbol("development"===process.env.NODE_ENV?"iterate":""),W=Symbol("development"===process.env.NODE_ENV?"Map key iterate":"");let J=0;class Y{constructor(t,e=null,s){this.fn=t,this.scheduler=e,this.id=J++,this.deps=[],this.active=!0,this.parent=void 0,function(t,e=M){e&&e.active&&e.effects.push(t)}(this,s)}run(){if(!this.active)return this.fn();let t=F,e=B;for(;t;){if(t===this)return;t=t.parent}try{return this.parent=F,F=this,B=!0,X=1<<++K,K<=30?(({deps:t})=>{if(t.length)for(let e=0;e<t.length;e++)t[e].w|=X})(this):z(this),this.fn()}finally{K<=30&&(t=>{const{deps:e}=t;if(e.length){let s=0;for(let n=0;n<e.length;n++){const i=e[n];k(i)&&!T(i)?i.delete(t):e[s++]=i,i.w&=~X,i.n&=~X}e.length=s}})(this),X=1<<--K,F=this.parent,B=e,this.parent=void 0,this.deferStop&&this.stop()}}stop(){F===this?this.deferStop=!0:this.active&&(z(this),this.onStop&&this.onStop(),this.active=!1)}}function z(t){const{deps:e}=t;if(e.length){for(let s=0;s<e.length;s++)e[s].delete(t);e.length=0}}let B=!0;const q=[];function G(){q.push(B),B=!1}function Q(){const t=q.pop();B=void 0===t||t}function Z(t,e,s,n){if(B&&F){let e=L.get(t);e||L.set(t,e=new Map);let n=e.get(s);n||e.set(s,n=I()),et(n)}}function tt(t){if(B&&F){let e=U.get(t);e||U.set(t,e=I()),et(e)}}function et(t){let e=!1;K<=30?T(t)||(t.n|=X,e=!k(t)):e=!t.has(F),e&&(t.add(F),F.deps.push(t))}function st(t){const e=U.get(t);if(e){const t=[...e];for(const e of t)e.view&&(e.view.mightChange=!0)}}function nt(t,e,s,n,i,o){var r;const c=L.get(t),a=t.base;let u=[];if(c)if("clear"===e)u=[...c.values()];else if("length"===s&&l(a))c.forEach(((t,e)=>{("length"===e||e>=n)&&u.push(t)}));else switch(void 0!==s&&u.push(c.get(s)),e){case"add":l(a)?g(s)&&u.push(c.get("length")):(u.push(c.get(H)),h(a)&&u.push(c.get(W)));break;case"delete":l(a)||(u.push(c.get(H)),h(a)&&u.push(c.get(W)));break;case"set":h(a)&&u.push(c.get(H))}if(1===u.length)u[0]&&it(u[0]);else{const t=[];for(const e of u)e&&t.push(...e);it(I(t))}const f=null===(r=t.root)||void 0===r?void 0:r.listeners;f&&f.length&&f.forEach((t=>t()))}function it(t){const e=l(t)?t:[...t];for(const s of e)s.view&&ot(s);for(const s of e)s.view||ot(s)}function ot(t){(t!==F||t.allowRecurse)&&(t.scheduler?t.scheduler():t.run())}class rt{constructor(t,{disableCache:e=!1}){this.dep=void 0,this.mightChange=!1,this._dirty=!0,this.effect=new Y(t,(()=>{this._dirty||(this._dirty=!0,function(t,e){(t=P(t)).dep&&it(t.dep)}(this))})),this.effect.view=this,this.effect.active=this._cacheable=!e}get value(){const t=P(this);return function(t){B&&F&&et((t=P(t)).dep||(t.dep=I()))}(t),!t._dirty&&t._cacheable||(t._dirty=!1,t._value=t.effect.run()),t._value}set value(t){"development"===process.env.NODE_ENV&&j("Write operation failed: computed value is readonly")}}const ct=new Set(["__proto__"]),at=new Set(Object.getOwnPropertyNames(Symbol).filter((t=>"arguments"!==t&&"caller"!==t)).map((t=>Symbol[t])).filter(p));function lt(t,e){const s=t.__r_state;return(s?C(s):t)[e]}const ht=pt(),ut=ft();function ft(){const t={};return["includes","indexOf","lastIndexOf"].forEach((e=>{t[e]=function(...t){const s=R(this),n=C(s);for(let e=0,o=this.length;e<o;e++)Z(s,0,e+"",Reflect.get(n,e));const i=n[e](...t);return-1===i||!1===i?n[e](...t.map(P)):i}})),["push","pop","shift","unshift","splice"].forEach((e=>{t[e]=function(...t){G();const s=C(R(this))[e].apply(this,t);return Q(),s}})),t}function pt(){return function(t,e,s){const n=C(t);if("__r_isReactive"===e)return!0;if("__r_state"===e&&s===yt.get(t))return t;if(l(n)&&r(ut,e))return Reflect.get(ut,e,s);let i=Reflect.get(n,e,s);if(p(e)?at.has(e):ct.has(e))return i;if(Z(t,0,e),!r(n,e))return i;if(t.disposed||!d(i))return i;if(!D(i)){$(t);const s=t.copy[e]=bt(i,t);return R(s)&&tt(s.__r_state),s}tt(R(i));return i}}function dt(){return function(t,e,s,n){const i=C(t),o=lt(i,e),c=l(i)&&g(e)?Number(e)<i.length:r(i,e);if(!t.modified){const n=null==o?void 0:o.__r_state;if(n&&n.base===s)return t.copy[e]=s,t.assigned[e]=!1,!0;if(b(s,o)&&(void 0!==s||r(t.base,e)))return!0;$(t),A(t)}return b(t.copy[e],s)&&(void 0!==s||e in t.copy)||(t.copy[e]=s,t.assigned[e]=!0,t===R(n)&&(c?b(s,o)||nt(t,"set",e,s):nt(t,"add",e,s),function(t){let e=t;for(;e;)st(e),e=e.parent}(t))),!0}}const _t={get:ht,set:dt(),deleteProperty:function(t,e){const s=r(C(t),e);if(void 0!==lt(t.base,e)||e in t.base?(t.assigned[e]=!1,$(t),A(t)):delete t.assigned[e],t.copy){const n=delete t.copy[e];return n&&s&&nt(t,"delete",e,void 0),n}return!0},has:function(t,e){const s=C(t),n=Reflect.has(s,e);return p(e)&&at.has(e)||Z(t,0,e),n},ownKeys:function(t){const e=C(t);return Z(t,0,l(e)?"length":H),Reflect.ownKeys(e)},setPrototypeOf:function(t,e){"development"===process.env.NODE_ENV&&j("not allow setPrototypeOf to set prototype");const s=Reflect.setPrototypeOf(t.base,e);return s&&t.copy&&Reflect.setPrototypeOf(t.copy,e),s},getOwnPropertyDescriptor:function(t,e){const s=C(t),n=Reflect.getOwnPropertyDescriptor(s,e);return n?{writable:!0,configurable:!l(s)||"length"!==e,enumerable:n.enumerable,value:s[e]}:n}};const yt=new WeakMap;let gt=0;function bt(t,e){if(!d(t))return"development"===process.env.NODE_ENV&&console.warn(`value cannot be made reactive: ${String(t)}`),t;if(t.__r_state)return t;var s;if(0===((s=t).__r_skip||!Object.isExtensible(s)?0:function(t){switch(t){case"Object":case"Array":return 1;case"Map":case"Set":case"WeakMap":case"WeakSet":return 2;default:return 0}}(_(s))))return t;const n=Array.isArray(t);let i={id:gt++,root:null,parent:e,base:t,proxy:null,copy:null,assigned:{},modified:!1,disposed:!1,listeners:[],children:[]};if(n){const t=i;i=[],Object.keys(t).forEach((e=>{Object.defineProperty(i,e,{configurable:!0,enumerable:!0,writable:!0,value:t[e]})}))}const o=new Proxy(i,_t);return i.proxy=o,e?(i.root=e.root,e.children.push(i)):i.root=i,i.children=[],yt.set(i,o),i.proxy}function vt(t,e){const s=function(t){const e={get(s,n,i){const o=Reflect.get(s,n,i);return d(o)&&D(o)?new Proxy(t.get(o.__r_state),e):o},set:(t,e,s,n)=>Reflect.set(t,e,s,n),has:(t,e)=>Reflect.has(t,e),ownKeys:t=>Reflect.ownKeys(t)};return e}(e);if(D(t)){return new Proxy(e.get(t.__r_state),s)}return new Proxy(S(t),s)}function wt(t,e){if(!d(t))return t;const s=function(t){const e=new Map;if(!D(t))return e;const s=[t.__r_state];for(;s.length;){const t=s.pop();let n;t.modified?(n=S(t.copy),Ot(t,n)):n=t.base,e.set(t,n);for(const e of t.children)s.push(e)}return e}(e);return vt(t,s)}function Ot(t,e){t.modified=!1,t.base=e,t.assigned={}}function mt(t,e){const s=t.createView((function(){return e(this,this.$actions)})),n=function(){return s.value};return n.destory=function(){s.effect.stop();const e=t.effectScope.effects.indexOf(s.effect);e>=0&&t.effectScope.effects.splice(e,1)},n}const St=n({$name:t=>t.name,$rawState:t=>t.getState(),$state:t=>t.isPrimitiveState?t.stateRef.value:t.stateValue,$actions:t=>t.actions,$views:t=>t.views,$patch:t=>t.patch,$onAction:t=>t.onAction,$subscribe:t=>t.subscribe,$isolate:t=>t.isolate,$getApi:t=>t.getApi,$createView:t=>mt.bind(null,t)}),Et={get:({_:t},e)=>{const{actions:s,views:n,accessCache:i,accessContext:o,ctx:c,stateValue:a}=t;if("$"!==e[0]){const t=i[e];if(void 0!==t)switch(t){case 0:return a[e];case 2:return n[e];case 1:if(1===o)return;return s[e];case 3:return c[e]}else{if(r(a,e))return i[e]=0,a[e];if(r(n,e))return i[e]=2,n[e];if(r(s,e)){if(1===o)return;return i[e]=1,s[e]}if(r(c,e))return i[e]=3,c[e]}}const l=St[e];return l?l(t):r(c,e)?(i[e]=3,c[e]):void((t=>"_"===t||"$"===t)(e[0])&&r(a,e)&&j(`Property ${JSON.stringify(e)} must be accessed via $state because it starts with a reserved character ("$" or "_") and is not proxied on the render context.`))},set({_:t},e,s){const{ctx:n,actions:i,views:o,accessContext:c,stateRef:{value:a}}=t;return 1===c?("development"===process.env.NODE_ENV&&j("Cannot change state in view function",t),!1):r(a,e)?(a[e]=s,!0):"$state"===e?"bigint"==typeof s||"symbol"==typeof s?("development"===process.env.NODE_ENV&&j("'BigInt' and 'Symbol' are not assignable to the State"),!1):(t.replace(s),!0):r(i,e)?("development"===process.env.NODE_ENV&&j(`Attempting to mutate action "${e}". Actions are readonly.`,t),!1):r(o,e)?("development"===process.env.NODE_ENV&&j(`Attempting to mutate view "${e}". Views are readonly.`,t),!1):"$"===e[0]&&r(St,e)?("development"===process.env.NODE_ENV&&j(`Attempting to mutate public property "${e}". Properties starting with $ are reserved and readonly.`,t),!1):(n[e]=s,!0)},has({_:t},e){const{actions:s,views:n,accessCache:i,accessContext:o,ctx:c,stateValue:a}=t;return!!i[e]||r(a,e)||r(n,e)||1!==o&&r(s,e)||r(c,e)||r(St,e)}},jt={0:"scheduler flush. This is likely a Doura internals bug. Please open an issue at https://github.com/dourajs/doura/issues/new"};function Nt(t,e,...s){const n=jt[e],i=n?"function"==typeof n?n.apply(null,s):n:"unknown error nr: "+Nt;throw new Error(`[Doura] ${i}`)}process;let xt=!1,Dt=!1;const Pt=[];let Rt=0;const Ct=[];let $t=null,At=0;const Mt=[];let Vt=null,It=0;const kt=Promise.resolve();let Tt=null,Lt=null;function Ut(t){Pt.length&&Pt.includes(t,xt&&t.allowRecurse?Rt+1:Rt)||t===Lt||(null==t.id?Pt.push(t):Pt.splice(function(t){let e=Rt+1,s=Pt.length;for(;e<s;){const n=e+s>>>1;Xt(Pt[n])<t?e=n+1:s=n}return e}(t.id),0,t),xt||Dt||(Dt=!0,Tt=kt.then(Ft)))}function Kt(t,e=null){if(Ct.length){for(Lt=e,$t=[...new Set(Ct)],Ct.length=0,At=0;At<$t.length;At++)$t[At]();$t=null,At=0,Lt=null,Kt(t,e)}}const Xt=t=>null==t.id?1/0:t.id;function Ft(t){Dt=!1,xt=!0,Kt(t),Pt.sort(((t,e)=>Xt(t)-Xt(e)));const s=e;try{for(Rt=0;Rt<Pt.length;Rt++){const t=Pt[Rt];if(t&&!1!==t.active){if("development"===process.env.NODE_ENV&&s(t))continue;try{t()}catch(n){console.log("err",n),Nt(0,0)}}}}finally{Rt=0,Pt.length=0,function(t){if(Kt(),Mt.length){const t=[...new Set(Mt)];if(Mt.length=0,Vt)return void Vt.push(...t);for(Vt=t,Vt.sort(((t,e)=>Xt(t)-Xt(e))),It=0;It<Vt.length;It++)Vt[It]();Vt=null,It=0}}(),xt=!1,Tt=null,(Pt.length||Ct.length||Mt.length)&&Ft(t)}}var Ht;function Wt(t,e){const s=Object.keys(e);s.length&&s.forEach((s=>{r(t,s)&&y(e[s])?Wt(t[s],e[s]):t[s]=e[s]}))}!function(t){t.REPLACE="replace",t.MODIFY="modify",t.PATCH="patch"}(Ht||(Ht={}));class Jt{constructor(t,{name:s,initState:n}){this.viewInstances=[],this._api=null,this._actionListeners=new Set,this._subscribers=new Set,this._watchStateChange=!0,this._destroyed=!1,this.patch=this.patch.bind(this),this.onAction=this.onAction.bind(this),this.subscribe=this.subscribe.bind(this),this.isolate=this.isolate.bind(this),this.getApi=this.getApi.bind(this),this.options=t,this.name=s||"",this._isDispatching=!1,this._initState=n||t.state,this.stateRef=bt({value:this._initState});const i=this._update.bind(this);var o;this._draftListenerHandler=function(t,s){const n=t.__r_state;return n.disposed?e:(n.listeners.push(s),()=>{const t=n.listeners.indexOf(s);t>=0&&n.listeners.splice(t,1)})}(this.stateRef,(()=>{this._watchStateChange&&Ut(i)})),this._setState(this._initState),this.actions=Object.create(null),this.views=Object.create(null),this.accessContext=0,this.ctx={},w(this.ctx,"_",this),this.accessCache=Object.create(null),this.proxy=new Proxy(this.ctx,Et),this.effectScope=new V(o),this._initActions(),this._initViews()}patch(t){y(t)?this._currentState&&(this._watchStateChange=!1,Wt(this.proxy.$state,t),this._watchStateChange=!0,this.dispatch({type:Ht.PATCH,payload:wt(this.stateRef.value,this.stateRef.value),args:{patch:t}})):"development"===process.env.NODE_ENV&&j(`patch argument should be an object, but receive a ${Object.prototype.toString.call(t)}`)}replace(t){this._watchStateChange=!1,this.stateRef.value=t,this._watchStateChange=!0;for(const e of this.viewInstances)e.effect.scheduler();this.dispatch({type:Ht.REPLACE,payload:t})}getState(){return this._currentState}getApi(){if(null===this._api){const t=this._api=Object.assign(Object.assign({},this._currentState),this.views);w(t,"$state",this._currentState);for(const e of Object.keys(this.actions))w(t,e,this.actions[e])}return this._api}onAction(t){return this._actionListeners.add(t),()=>{this._actionListeners.delete(t)}}subscribe(t){return this._subscribers.add(t),()=>{this._subscribers.delete(t)}}isolate(t){G();const e=t(this.stateValue);return Q(),e}depend(t){t.subscribe((t=>{this._triggerListener(Object.assign(Object.assign({},t),{model:this.proxy}))}))}createView(t){let e;return this.effectScope.run((()=>{e=function(t,e={}){return new rt(t,e)}((()=>{const e=this.accessContext;this.accessContext=1;try{let s=t.call(this.proxy,this.proxy);return"development"===process.env.NODE_ENV&&d(s)&&(s===this.proxy?j('detect returning "this" in view, it would cause unpected behavior'):s===this.proxy.$state&&j('detect returning "this.$state" in view, it would cause unpected behavior')),s}finally{this.accessContext=e}}))})),this.viewInstances.push(e),e}reducer(t,e){switch(e.type){case Ht.REPLACE:case Ht.MODIFY:case Ht.PATCH:return e.payload;default:return t}}dispatch(t){if(void 0===t.type)return"development"===process.env.NODE_ENV&&j('Actions may not have an undefined "type" property. You may have misspelled an action type string constant.'),t;if(this._isDispatching)return"development"===process.env.NODE_ENV&&j("Cannot dispatch action from a reducer."),t;let e;try{this._isDispatching=!0,e=this.reducer(this._currentState,t)}finally{this._isDispatching=!1}return e!==this._currentState&&(this._setState(e),this._triggerListener(Object.assign({type:t.type,model:this.proxy,target:this.proxy},t.args))),t}destroy(){this._destroyed=!0,this._api=null,this._currentState=null,this.stateRef={value:null},this._subscribers.clear(),this.effectScope.stop(),this._draftListenerHandler()}_setState(t){this._api=null,this._currentState=t,this.isPrimitiveState=!d(t),this.stateValue=this.stateRef.value}_update(){!this._destroyed&&function(t){return t.__r_state.modified}(this.stateRef)&&this.dispatch({type:Ht.MODIFY,payload:wt(this.stateRef.value,this.stateRef)})}_triggerListener(t){for(const e of this._subscribers)e(t)}_initActions(){const t=this.options.actions;if(t){Object.keys(t).forEach((e=>{const s=t[e];Object.defineProperty(this.actions,e,{configurable:!0,enumerable:!0,writable:!1,value:(...t)=>{for(const s of this._actionListeners)s({name:e,args:t});let n;try{n=s.call(this.proxy,...t)}finally{this._update()}return n}})}))}}_initViews(){const t=this.options.views;if(t)for(const e of Object.keys(t)){const s=this.createView(t[e]),n=this;Object.defineProperty(this.views,e,{configurable:!0,enumerable:!0,get(){const t=s;let e=s.value;return s.mightChange?(s.mightChange=!1,t.__snapshot=wt(e,n.stateRef.value)):t.__pre!==e&&(t.__snapshot=wt(e,n.stateRef.value)),t.__pre=e,t.__snapshot},set:()=>("development"===process.env.NODE_ENV&&j(`cannot change view property '${String(e)}'`),!1)})}}}function Yt(t,e={}){return"development"===process.env.NODE_ENV&&(t=>{O(t.hasOwnProperty("state"),"state is required"),O("bigint"!=typeof t.state&&"symbol"!=typeof t.state,"state can not be BigInt or Symbol"),N(t,"actions"),N(t,"views");const e=new Map;x("state",t,e),x("views",t,e),e.clear(),x("actions",t,e)})(t),new Jt(t,e)}class zt{constructor(t=s,e=[]){this._subscribers=new Set,this._initialState=t,this._models=(()=>{const t=new Map,e={get:e=>t.get(e),set(e,s){t.set(e,s)},each(e){for(const[s,n]of t.entries())e(n,s)},clear(){e.each((t=>t.destroy())),t.clear()}};return e})();const n=()=>{for(const t of this._subscribers)t()};this._onModelChange=()=>{Ut(n)},this._hooks=e.map((([t,e])=>t(e))),this._hooks.map((e=>{var s;return null===(s=e.onInit)||void 0===s?void 0:s.call(e,{initialState:t},{doura:this})}))}getModel(t,e){return this._getNamedModel(t,e).proxy}getDetachedModel(t){return this._getDetachedModel(t).proxy}getState(){const t={};return this._models.each(((e,s)=>{t[s]=e.getState()})),t}subscribe(t){return this._subscribers.add(t),()=>{this._subscribers.delete(t)}}destroy(){this._hooks.map((t=>{var e;return null===(e=t.onDestroy)||void 0===e?void 0:e.call(t)})),this._models.clear(),this._subscribers.clear(),this._initialState=s}_getNamedModel(t,e){let s=this._models.get(t);if(s)return s;if("function"==typeof e){const s=this._createUseContext();e=e({use:this._use.bind(this,s)});const n=this._initModel(t,e);return s.setInitiator(n),n}return this._initModel(t,e)}_createUseContext(){let t,e=[];return{add(s){t?t.depend(s):e.push(s)},setInitiator(s){if(!t){t=s;for(const s of e)t.depend(s);e.length=0}}}}_getDetachedModel(t){let e;if("function"==typeof t){const s=t,n=this._createUseContext();e=Yt(s({use:this._use.bind(this,n)})),n.setInitiator(e)}else{if("object"!=typeof t)throw new Error("invalid model");e=Yt(t)}return e}_use(t,e,s){let n;const i=t;if("string"==typeof e){n=this._getNamedModel(e,s)}else{n=this._getDetachedModel(e)}return i&&i.add(n),n.proxy}_initModel(t,e){this._hooks.map((s=>{var n;return null===(n=s.onModel)||void 0===n?void 0:n.call(s,t,e,{doura:this})}));const s=Yt(e,{name:t,initState:this._getInitialState(t)});return s.subscribe(this._onModelChange),this._models.set(t,s),this._hooks.map((t=>{var e;null===(e=t.onModelInstance)||void 0===e||e.call(t,s.proxy,{doura:this})})),s}_getInitialState(t){const e=this._initialState[t];return e&&delete this._initialState[t],e}}var Bt=function(){if("undefined"==typeof window||!window.__REDUX_DEVTOOLS_EXTENSION__)return{};let t=0;const e=new Set;let s;return{onInit({},{doura:n}){if(window.__doura=n,"undefined"!=typeof window&&window.__REDUX_DEVTOOLS_EXTENSION__){s=window.__REDUX_DEVTOOLS_EXTENSION__.connect({name:`doura${0===t?"":t}`}),t+=1,s.init(n.getState());const i=t=>{switch(t.type){case"ACTION":return void O("string"==typeof t.payload,"Unsupported action format");case"DISPATCH":switch(t.payload.type){case"RESET":case"COMMIT":return s.init(n.getState());case"ROLLBACK":try{const e=JSON.parse(t.state);return s.init(e)}catch(e){console.warn("[Doura Devtool] Could not parse the received json.")}return s.init(n.getState());case"JUMP_TO_STATE":case"JUMP_TO_ACTION":return}}};e.add(s.subscribe(i))}},onModelInstance(t,{doura:e}){t.$subscribe((t=>{var{type:n,model:i}=t,o=function(t,e){var s={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(s[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(n=Object.getOwnPropertySymbols(t);i<n.length;i++)e.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(t,n[i])&&(s[n[i]]=t[n[i]])}return s}(t,["type","target","model"]);const r=e.getState();delete r._,s.send(Object.assign({type:`${i.$name||"anonymous"}@${n}`},o),r)}))},onDestroy(){window.__REDUX_DEVTOOLS_EXTENSION__.disconnect(s);for(const t of e.values())t();e.clear()}}};return t.NOOP=e,t.assign=n,t.capitalize=v,t.def=w,t.defineModel=t=>t,t.devtool=Bt,t.doura=function({initialState:t,plugins:e=[]}={}){return function({initialState:t,plugins:e}={}){return new zt(t,e)}({initialState:t,plugins:e})},t.each=function(t,e,s=!1){y(t)?(s?Object.keys:E)(t).forEach((n=>{s&&"symbol"==typeof n||e(n,t[n],t)})):t.forEach(((s,n)=>e(n,s,t)))},t.emptyObject=s,t.extend=i,t.hasOwn=r,t.invariant=O,t.is=b,t.isArray=l,t.isFrozen=function(t){return null==t||"object"!=typeof t||Object.isFrozen(t)},t.isFunction=t=>"function"==typeof t,t.isIntegerKey=g,t.isMap=h,t.isObject=d,t.isPlainObject=y,t.isSet=u,t.isString=f,t.isSymbol=p,t.nextTick=function(t){const e=Tt||kt;return t?e.then(this?t.bind(this):t):e},t.objectToString=c,t.ownKeys=E,t.patchObj=function t(e,s){Object.keys(s).forEach((function(n){e.hasOwnProperty(n)&&d(s[n])?t(e[n],s[n]):e[n]=s[n]}))},t.set=function(t,e,s){h(t)?t.set(e,s):u(t)?(t.delete(e),t.add(s)):t[e]=s},t.shallowCopy=S,t.toRawType=_,t.toTypeString=a,t}({});
var Doura=function(t){"use strict";const e=()=>{},s=Object.create(null),n=Object.assign,i=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var s in e)e.hasOwnProperty(s)&&(t[s]=e[s])},o=Object.prototype.hasOwnProperty,r=(t,e)=>o.call(t,e),c=Object.prototype.toString,a=t=>c.call(t),l=Array.isArray,h=t=>"[object Map]"===a(t),u=t=>"[object Set]"===a(t),f=t=>"string"==typeof t,p=t=>"symbol"==typeof t,d=t=>null!==t&&"object"==typeof t,_=t=>a(t).slice(8,-1),y=t=>"[object Object]"===a(t),g=t=>f(t)&&"NaN"!==t&&"-"!==t[0]&&""+parseInt(t,10)===t,b=(t,e)=>Object.is(t,e),v=(t,e,s)=>{Object.defineProperty(t,e,{configurable:!0,enumerable:!1,value:s})};function w(t,e){if(!t)throw new Error(`[Doura] ${e||""}`)}const O=Array.prototype.slice;function m(t){if(Array.isArray(t))return O.call(t);const e=Object.getOwnPropertyDescriptors(t);let s=Reflect.ownKeys(e);for(let n=0;n<s.length;n++){const i=s[n],o=e[i];!1===o.writable&&(o.writable=!0,o.configurable=!0),(o.get||o.set)&&(e[i]={configurable:!0,writable:!0,enumerable:o.enumerable,value:t[i]})}return Object.create(Object.getPrototypeOf(t),e)}const S="undefined"!=typeof Reflect&&Reflect.ownKeys?Reflect.ownKeys:void 0!==Object.getOwnPropertySymbols?t=>Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t)):Object.getOwnPropertyNames;function E(t,...e){console.warn(`[Doura warn] ${t}`,...e)}function N(t,e,s){const n=t[e];n&&w(y(n),`model.${e} should be object!`)}function j(t,e,s){if(e[t])for(const n of Object.keys(e[t]))if(s.has(n)){E(`key "${n}" in "${t}" is conflicted with the key in "${s.get(n)}"`)}else s.set(n,t)}function x(t){return!!t&&!!t.__r_state}function D(t){const e=P(t);return e?D(e.base):t}function P(t){return t&&t.__r_state}function R(t){return t.copy||t.base}function C(t){t.copy||(t.copy=m(t.base))}function $(t){t.modified||(t.modified=!0,t.parent&&$(t.parent))}let A;class M{constructor(t=!1){this.active=!0,this.effects=[],this.cleanups=[],!t&&A&&(this.parent=A,this.index=(A.scopes||(A.scopes=[])).push(this)-1)}run(t){if(this.active){const e=A;try{return A=this,t()}finally{A=e}}else"development"===process.env.NODE_ENV&&E("cannot run an inactive effect scope.")}on(){A=this}off(){A=this.parent}stop(t){if(this.active){let e,s;for(e=0,s=this.effects.length;e<s;e++)this.effects[e].stop();for(e=0,s=this.cleanups.length;e<s;e++)this.cleanups[e]();if(this.scopes)for(e=0,s=this.scopes.length;e<s;e++)this.scopes[e].stop(!0);if(this.parent&&!t){const t=this.parent.scopes.pop();t&&t!==this&&(this.parent.scopes[this.index]=t,t.index=this.index)}this.active=!1}}}const V=t=>{const e=new Set(t);return e.w=0,e.n=0,e},I=t=>(t.w&U)>0,k=t=>(t.n&U)>0,T=new WeakMap,L=new WeakMap;let K=0,U=1;let H;const X=Symbol("development"===process.env.NODE_ENV?"iterate":""),W=Symbol("development"===process.env.NODE_ENV?"Map key iterate":"");let F=0;class J{constructor(t,e=null,s){this.fn=t,this.scheduler=e,this.id=F++,this.deps=[],this.active=!0,this.parent=void 0,function(t,e=A){e&&e.active&&e.effects.push(t)}(this,s)}run(){if(!this.active)return this.fn();let t=H,e=B;for(;t;){if(t===this)return;t=t.parent}try{return this.parent=H,H=this,B=!0,U=1<<++K,K<=30?(({deps:t})=>{if(t.length)for(let e=0;e<t.length;e++)t[e].w|=U})(this):Y(this),this.fn()}finally{K<=30&&(t=>{const{deps:e}=t;if(e.length){let s=0;for(let n=0;n<e.length;n++){const i=e[n];I(i)&&!k(i)?i.delete(t):e[s++]=i,i.w&=~U,i.n&=~U}e.length=s}})(this),U=1<<--K,H=this.parent,B=e,this.parent=void 0,this.deferStop&&this.stop()}}stop(){H===this?this.deferStop=!0:this.active&&(Y(this),this.onStop&&this.onStop(),this.active=!1)}}function Y(t){const{deps:e}=t;if(e.length){for(let s=0;s<e.length;s++)e[s].delete(t);e.length=0}}let B=!0;const q=[];function z(){q.push(B),B=!1}function G(){const t=q.pop();B=void 0===t||t}function Q(t,e,s,n){if(B&&H){let e=T.get(t);e||T.set(t,e=new Map);let n=e.get(s);n||e.set(s,n=V()),tt(n)}}function Z(t){if(B&&H){let e=L.get(t);e||L.set(t,e=V()),tt(e)}}function tt(t){let e=!1;K<=30?k(t)||(t.n|=U,e=!I(t)):e=!t.has(H),e&&(t.add(H),H.deps.push(t))}function et(t){const e=L.get(t);if(e){const t=[...e];for(const e of t)e.view&&(e.view.mightChange=!0)}}function st(t,e,s,n,i,o){var r;const c=T.get(t),a=t.base;let u=[];if(c)if("clear"===e)u=[...c.values()];else if("length"===s&&l(a))c.forEach(((t,e)=>{("length"===e||e>=n)&&u.push(t)}));else switch(void 0!==s&&u.push(c.get(s)),e){case"add":l(a)?g(s)&&u.push(c.get("length")):(u.push(c.get(X)),h(a)&&u.push(c.get(W)));break;case"delete":l(a)||(u.push(c.get(X)),h(a)&&u.push(c.get(W)));break;case"set":h(a)&&u.push(c.get(X))}if(1===u.length)u[0]&&nt(u[0]);else{const t=[];for(const e of u)e&&t.push(...e);nt(V(t))}const f=null===(r=t.root)||void 0===r?void 0:r.listeners;f&&f.length&&f.forEach((t=>t()))}function nt(t){const e=l(t)?t:[...t];for(const s of e)s.view&&it(s);for(const s of e)s.view||it(s)}function it(t){(t!==H||t.allowRecurse)&&(t.scheduler?t.scheduler():t.run())}class ot{constructor(t,{disableCache:e=!1}){this.dep=void 0,this.mightChange=!1,this._dirty=!0,this.effect=new J(t,(()=>{this._dirty||(this._dirty=!0,function(t,e){(t=D(t)).dep&&nt(t.dep)}(this))})),this.effect.view=this,this.effect.active=this._cacheable=!e}get value(){const t=D(this);return function(t){B&&H&&tt((t=D(t)).dep||(t.dep=V()))}(t),!t._dirty&&t._cacheable||(t._dirty=!1,t._value=t.effect.run()),t._value}set value(t){"development"===process.env.NODE_ENV&&E("Write operation failed: computed value is readonly")}}const rt=new Set(["__proto__"]),ct=new Set(Object.getOwnPropertyNames(Symbol).filter((t=>"arguments"!==t&&"caller"!==t)).map((t=>Symbol[t])).filter(p));function at(t,e){const s=t.__r_state;return(s?R(s):t)[e]}const lt=ft(),ht=ut();function ut(){const t={};return["includes","indexOf","lastIndexOf"].forEach((e=>{t[e]=function(...t){const s=P(this),n=R(s);for(let e=0,o=this.length;e<o;e++)Q(s,0,e+"",Reflect.get(n,e));const i=n[e](...t);return-1===i||!1===i?n[e](...t.map(D)):i}})),["push","pop","shift","unshift","splice"].forEach((e=>{t[e]=function(...t){z();const s=R(P(this))[e].apply(this,t);return G(),s}})),t}function ft(){return function(t,e,s){const n=R(t);if("__r_isReactive"===e)return!0;if("__r_state"===e&&s===_t.get(t))return t;if(l(n)&&r(ht,e))return Reflect.get(ht,e,s);let i=Reflect.get(n,e,s);if(p(e)?ct.has(e):rt.has(e))return i;if(Q(t,0,e),!r(n,e))return i;if(t.disposed||!d(i))return i;if(!x(i)){C(t);const s=t.copy[e]=gt(i,t);return P(s)&&Z(s.__r_state),s}Z(P(i));return i}}function pt(){return function(t,e,s,n){const i=R(t),o=at(i,e),c=l(i)&&g(e)?Number(e)<i.length:r(i,e);if(!t.modified){const n=null==o?void 0:o.__r_state;if(n&&n.base===s)return t.copy[e]=s,t.assigned[e]=!1,!0;if(b(s,o)&&(void 0!==s||r(t.base,e)))return!0;C(t),$(t)}return b(t.copy[e],s)&&(void 0!==s||e in t.copy)||(t.copy[e]=s,t.assigned[e]=!0,t===P(n)&&(c?b(s,o)||st(t,"set",e,s):st(t,"add",e,s),function(t){let e=t;for(;e;)et(e),e=e.parent}(t))),!0}}const dt={get:lt,set:pt(),deleteProperty:function(t,e){const s=r(R(t),e);if(void 0!==at(t.base,e)||e in t.base?(t.assigned[e]=!1,C(t),$(t)):delete t.assigned[e],t.copy){const n=delete t.copy[e];return n&&s&&st(t,"delete",e,void 0),n}return!0},has:function(t,e){const s=R(t),n=Reflect.has(s,e);return p(e)&&ct.has(e)||Q(t,0,e),n},ownKeys:function(t){const e=R(t);return Q(t,0,l(e)?"length":X),Reflect.ownKeys(e)},setPrototypeOf:function(t,e){"development"===process.env.NODE_ENV&&E("not allow setPrototypeOf to set prototype");const s=Reflect.setPrototypeOf(t.base,e);return s&&t.copy&&Reflect.setPrototypeOf(t.copy,e),s},getOwnPropertyDescriptor:function(t,e){const s=R(t),n=Reflect.getOwnPropertyDescriptor(s,e);return n?{writable:!0,configurable:!l(s)||"length"!==e,enumerable:n.enumerable,value:s[e]}:n}};const _t=new WeakMap;let yt=0;function gt(t,e){if(!d(t))return"development"===process.env.NODE_ENV&&console.warn(`value cannot be made reactive: ${String(t)}`),t;if(t.__r_state)return t;var s;if(0===((s=t).__r_skip||!Object.isExtensible(s)?0:function(t){switch(t){case"Object":case"Array":return 1;case"Map":case"Set":case"WeakMap":case"WeakSet":return 2;default:return 0}}(_(s))))return t;const n=Array.isArray(t);let i={id:yt++,root:null,parent:e,base:t,proxy:null,copy:null,assigned:{},modified:!1,disposed:!1,listeners:[],children:[]};if(n){const t=i;i=[],Object.keys(t).forEach((e=>{Object.defineProperty(i,e,{configurable:!0,enumerable:!0,writable:!0,value:t[e]})}))}const o=new Proxy(i,dt);return i.proxy=o,e?(i.root=e.root,e.children.push(i)):i.root=i,i.children=[],_t.set(i,o),i.proxy}function bt(t,e){const s=function({copies:t,proxies:e}){const s={get(n,i,o){const r=Reflect.get(n,i,o);if(!d(r))return r;if(x(r)){let n=e.get(r);return n||e.set(r,n=new Proxy(t.get(r.__r_state),s)),n}return r},set:(t,e,s,n)=>Reflect.set(t,e,s,n),has:(t,e)=>Reflect.has(t,e),ownKeys:t=>Reflect.ownKeys(t)};return s}(e);if(x(t)){return new Proxy(e.copies.get(t.__r_state),s)}return new Proxy(m(t),s)}function vt(t,e){if(!d(t))return t;const s=function(t){const e=new Map,s={copies:e,proxies:new Map},n=[t.__r_state];for(;n.length;){const t=n.pop();let s;t.modified?(s=m(t.copy),wt(t,s)):s=t.base,e.set(t,s);for(const e of t.children)n.push(e)}return s}(e);return bt(t,s)}function wt(t,e){t.modified=!1,t.base=e,t.assigned={}}function Ot(t,e){const s=t.createView((function(){return e(this,this.$actions)})),n=function(){return s.value};return n.destory=function(){s.effect.stop();const e=t.effectScope.effects.indexOf(s.effect);e>=0&&t.effectScope.effects.splice(e,1)},n}const mt=n({$name:t=>t.name,$rawState:t=>t.getState(),$state:t=>t.stateValue,$actions:t=>t.actions,$views:t=>t.views,$patch:t=>t.patch,$onAction:t=>t.onAction,$subscribe:t=>t.subscribe,$isolate:t=>t.isolate,$getApi:t=>t.getApi,$createView:t=>Ot.bind(null,t)}),St={get:({_:t},e)=>{const{actions:s,views:n,accessCache:i,accessContext:o,ctx:c,stateValue:a}=t;if("$"!==e[0]){const t=i[e];if(void 0!==t)switch(t){case 0:return a[e];case 2:return n[e];case 1:if(1===o)return;return s[e];case 3:return c[e]}else{if(r(a,e))return i[e]=0,a[e];if(r(n,e))return i[e]=2,n[e];if(r(s,e)){if(1===o)return;return i[e]=1,s[e]}if(r(c,e))return i[e]=3,c[e]}}const l=mt[e];return l?l(t):r(c,e)?(i[e]=3,c[e]):void((t=>"_"===t||"$"===t)(e[0])&&r(a,e)&&E(`Property ${JSON.stringify(e)} must be accessed via $state because it starts with a reserved character ("$" or "_") and is not proxied on the render context.`))},set({_:t},e,s){const{ctx:n,actions:i,views:o,accessContext:c,stateRef:{value:a}}=t;return 1===c?("development"===process.env.NODE_ENV&&E("Cannot change state in view function",t),!1):r(a,e)?(a[e]=s,!0):"$state"===e?"bigint"==typeof s||"symbol"==typeof s?("development"===process.env.NODE_ENV&&E("'BigInt' and 'Symbol' are not assignable to the State"),!1):(t.replace(s),!0):r(i,e)?("development"===process.env.NODE_ENV&&E(`Attempting to mutate action "${e}". Actions are readonly.`,t),!1):r(o,e)?("development"===process.env.NODE_ENV&&E(`Attempting to mutate view "${e}". Views are readonly.`,t),!1):"$"===e[0]&&r(mt,e)?("development"===process.env.NODE_ENV&&E(`Attempting to mutate public property "${e}". Properties starting with $ are reserved and readonly.`,t),!1):(n[e]=s,!0)},has({_:t},e){const{actions:s,views:n,accessCache:i,accessContext:o,ctx:c,stateValue:a}=t;return!!i[e]||r(a,e)||r(n,e)||1!==o&&r(s,e)||r(c,e)||r(mt,e)}},Et={0:"scheduler flush. This is likely a Doura internals bug. Please open an issue at https://github.com/dourajs/doura/issues/new"};function Nt(t,e,...s){const n=Et[e],i=n?"function"==typeof n?n.apply(null,s):n:"unknown error nr: "+Nt;throw new Error(`[Doura] ${i}`)}process;let jt=!1,xt=!1;const Dt=[];let Pt=0;const Rt=[];let Ct=null,$t=0;const At=[];let Mt=null,Vt=0;const It=Promise.resolve();let kt=null,Tt=null;function Lt(t){Dt.length&&Dt.includes(t,jt&&t.allowRecurse?Pt+1:Pt)||t===Tt||(null==t.id?Dt.push(t):Dt.splice(function(t){let e=Pt+1,s=Dt.length;for(;e<s;){const n=e+s>>>1;Ut(Dt[n])<t?e=n+1:s=n}return e}(t.id),0,t),jt||xt||(xt=!0,kt=It.then(Ht)))}function Kt(t,e=null){if(Rt.length){for(Tt=e,Ct=[...new Set(Rt)],Rt.length=0,$t=0;$t<Ct.length;$t++)Ct[$t]();Ct=null,$t=0,Tt=null,Kt(t,e)}}const Ut=t=>null==t.id?1/0:t.id;function Ht(t){xt=!1,jt=!0,Kt(t),Dt.sort(((t,e)=>Ut(t)-Ut(e)));const s=e;try{for(Pt=0;Pt<Dt.length;Pt++){const t=Dt[Pt];if(t&&!1!==t.active){if("development"===process.env.NODE_ENV&&s(t))continue;try{t()}catch(n){console.log("err",n),Nt(0,0)}}}}finally{Pt=0,Dt.length=0,function(t){if(Kt(),At.length){const t=[...new Set(At)];if(At.length=0,Mt)return void Mt.push(...t);for(Mt=t,Mt.sort(((t,e)=>Ut(t)-Ut(e))),Vt=0;Vt<Mt.length;Vt++)Mt[Vt]();Mt=null,Vt=0}}(),jt=!1,kt=null,(Dt.length||Rt.length||At.length)&&Ht(t)}}var Xt;function Wt(t,e){const s=Object.keys(e);s.length&&s.forEach((s=>{r(t,s)&&y(e[s])?Wt(t[s],e[s]):t[s]=e[s]}))}!function(t){t.REPLACE="replace",t.MODIFY="modify",t.PATCH="patch"}(Xt||(Xt={}));class Ft{constructor(t,{name:s,initState:n}){this.viewInstances=[],this._api=null,this._actionListeners=new Set,this._subscribers=new Set,this._depListenersHandlers=[],this._watchStateChange=!0,this._destroyed=!1,this.patch=this.patch.bind(this),this.onAction=this.onAction.bind(this),this.subscribe=this.subscribe.bind(this),this.isolate=this.isolate.bind(this),this.getApi=this.getApi.bind(this),this.options=t,this.name=s||"",this._isDispatching=!1,this._initState=n||t.state,this.stateRef=gt({value:this._initState});const i=this._update.bind(this);var o;this._draftListenerHandler=function(t,s){const n=t.__r_state;return n.disposed?e:(n.listeners.push(s),()=>{const t=n.listeners.indexOf(s);t>=0&&n.listeners.splice(t,1)})}(this.stateRef,(()=>{this._watchStateChange&&Lt(i)})),this._setState(this._initState),this.actions=Object.create(null),this.views=Object.create(null),this.accessContext=0,this.ctx={},v(this.ctx,"_",this),this.accessCache=Object.create(null),this.proxy=new Proxy(this.ctx,St),this.effectScope=new M(o),this._initActions(),this._initViews()}patch(t){y(t)?this._currentState&&(this._watchStateChange=!1,Wt(this.proxy.$state,t),this._watchStateChange=!0,this.dispatch({type:Xt.PATCH,payload:vt(this.stateRef.value,this.stateRef.value),args:{patch:t}})):"development"===process.env.NODE_ENV&&E(`patch argument should be an object, but receive a ${Object.prototype.toString.call(t)}`)}replace(t){this._watchStateChange=!1,this.stateRef.value=t,this._watchStateChange=!0;for(const e of this.viewInstances)e.effect.scheduler();this.dispatch({type:Xt.REPLACE,payload:t})}getState(){return this._currentState}getApi(){if(null===this._api){const t=this._api=Object.assign(Object.assign({},this._currentState),this.views);for(const e of Object.keys(this.actions))v(t,e,this.actions[e])}return this._api}onAction(t){return this._actionListeners.add(t),()=>{this._actionListeners.delete(t)}}subscribe(t){return this._subscribers.add(t),()=>{this._subscribers.delete(t)}}isolate(t){z();const e=t(this.stateValue);return G(),e}depend(t){this._depListenersHandlers.push(t.subscribe((t=>{this._triggerListener(Object.assign(Object.assign({},t),{model:this.proxy}))})))}createView(t){let e;return this.effectScope.run((()=>{e=function(t,e={}){return new ot(t,e)}((()=>{const e=this.accessContext;this.accessContext=1;try{let s=t.call(this.proxy,this.proxy);return"development"===process.env.NODE_ENV&&d(s)&&(s===this.proxy?E('detect returning "this" in view, it would cause unpected behavior'):s===this.proxy.$state&&E('detect returning "this.$state" in view, it would cause unpected behavior')),s}finally{this.accessContext=e}}))})),this.viewInstances.push(e),e}reducer(t,e){switch(e.type){case Xt.REPLACE:case Xt.MODIFY:case Xt.PATCH:return e.payload;default:return t}}dispatch(t){if(void 0===t.type)return"development"===process.env.NODE_ENV&&E('Actions may not have an undefined "type" property. You may have misspelled an action type string constant.'),t;if(this._isDispatching)return"development"===process.env.NODE_ENV&&E("Cannot dispatch action from a reducer."),t;let e;try{this._isDispatching=!0,e=this.reducer(this._currentState,t)}finally{this._isDispatching=!1}return e!==this._currentState&&(this._setState(e),this._triggerListener(Object.assign({type:t.type,model:this.proxy,target:this.proxy},t.args))),t}destroy(){this._destroyed=!0,this._api=null,this._currentState=null,this.stateRef={value:null},this._subscribers.clear(),this.effectScope.stop();for(const t of this._depListenersHandlers)t();this._draftListenerHandler()}_setState(t){this._api=null,this._currentState=t,this.stateValue=this.stateRef.value}_update(){!this._destroyed&&function(t){return t.__r_state.modified}(this.stateRef)&&this.dispatch({type:Xt.MODIFY,payload:vt(this.stateRef.value,this.stateRef)})}_triggerListener(t){for(const e of this._subscribers)e(t)}_initActions(){const t=this.options.actions;if(t){Object.keys(t).forEach((e=>{const s=t[e];Object.defineProperty(this.actions,e,{configurable:!0,enumerable:!0,writable:!1,value:(...t)=>{for(const s of this._actionListeners)s({name:e,args:t});let n;try{n=s.call(this.proxy,...t)}finally{this._update()}return n}})}))}}_initViews(){const t=this.options.views;if(t)for(const e of Object.keys(t)){const s=this.createView(t[e]),n=this;Object.defineProperty(this.views,e,{configurable:!0,enumerable:!0,get(){const t=s;let e=s.value;return s.mightChange?(s.mightChange=!1,t.__snapshot=vt(e,n.stateRef.value)):t.__pre!==e&&(t.__snapshot=vt(e,n.stateRef.value)),t.__pre=e,t.__snapshot},set:()=>("development"===process.env.NODE_ENV&&E(`cannot change view property '${String(e)}'`),!1)})}}}function Jt(t,e={}){return"development"===process.env.NODE_ENV&&(t=>{w(t.hasOwnProperty("state"),"state is required"),w("bigint"!=typeof t.state&&"symbol"!=typeof t.state,"state can not be BigInt or Symbol"),N(t,"actions"),N(t,"views");const e=new Map;j("state",t,e),j("views",t,e),e.clear(),j("actions",t,e)})(t),new Ft(t,e)}class Yt{constructor(t=s,e=[]){this._subscribers=new Set,this._initialState=t,this._models=(()=>{const t=new Map,e={get:e=>t.get(e),set(e,s){t.set(e,s)},each(e){for(const[s,n]of t.entries())e(n,s)},clear(){e.each((t=>t.destroy())),t.clear()}};return e})();const n=()=>{for(const t of this._subscribers)t()};this._onModelChange=()=>{Lt(n)},this._hooks=e.map((([t,e])=>t(e))),this._hooks.map((e=>{var s;return null===(s=e.onInit)||void 0===s?void 0:s.call(e,{initialState:t},{doura:this})}))}getModel(t,e){return this._getNamedModel(t,e).proxy}getDetachedModel(t){return this._getDetachedModel(t).proxy}getState(){const t={};return this._models.each(((e,s)=>{t[s]=e.getState()})),t}subscribe(t){return this._subscribers.add(t),()=>{this._subscribers.delete(t)}}destroy(){this._hooks.map((t=>{var e;return null===(e=t.onDestroy)||void 0===e?void 0:e.call(t)})),this._models.clear(),this._subscribers.clear(),this._initialState=s}_getNamedModel(t,e){let s=this._models.get(t);if(s)return s;if("function"==typeof e){const s=this._createUseContext();e=e({use:this._use.bind(this,s)});const n=this._initModel(t,e);return s.setInitiator(n),n}return this._initModel(t,e)}_createUseContext(){let t,e=[];return{add(s){t?t.depend(s):e.push(s)},setInitiator(s){if(!t){t=s;for(const s of e)t.depend(s);e.length=0}}}}_getDetachedModel(t){let e;if("function"==typeof t){const s=t,n=this._createUseContext();e=Jt(s({use:this._use.bind(this,n)})),n.setInitiator(e)}else{if("object"!=typeof t)throw new Error("invalid model");e=Jt(t)}return e}_use(t,e,s){let n;const i=t;if("string"==typeof e){n=this._getNamedModel(e,s)}else{n=this._getDetachedModel(e)}return i&&i.add(n),n.proxy}_initModel(t,e){this._hooks.map((s=>{var n;return null===(n=s.onModel)||void 0===n?void 0:n.call(s,t,e,{doura:this})}));const s=Jt(e,{name:t,initState:this._getInitialState(t)});return s.subscribe(this._onModelChange),this._models.set(t,s),this._hooks.map((t=>{var e;null===(e=t.onModelInstance)||void 0===e||e.call(t,s.proxy,{doura:this})})),s}_getInitialState(t){const e=this._initialState[t];return e&&delete this._initialState[t],e}}var Bt=function(){if("undefined"==typeof window||!window.__REDUX_DEVTOOLS_EXTENSION__)return{};let t=0;const e=new Set;let s;return{onInit({},{doura:n}){if(window.__doura=n,"undefined"!=typeof window&&window.__REDUX_DEVTOOLS_EXTENSION__){s=window.__REDUX_DEVTOOLS_EXTENSION__.connect({name:`doura${0===t?"":t}`}),t+=1,s.init(n.getState());const i=t=>{switch(t.type){case"ACTION":return void w("string"==typeof t.payload,"Unsupported action format");case"DISPATCH":switch(t.payload.type){case"RESET":case"COMMIT":return s.init(n.getState());case"ROLLBACK":try{const e=JSON.parse(t.state);return s.init(e)}catch(e){console.warn("[Doura Devtool] Could not parse the received json.")}return s.init(n.getState());case"JUMP_TO_STATE":case"JUMP_TO_ACTION":return}}};e.add(s.subscribe(i))}},onModelInstance(t,{doura:e}){t.$subscribe((t=>{var{type:n,model:i}=t,o=function(t,e){var s={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(s[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(n=Object.getOwnPropertySymbols(t);i<n.length;i++)e.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(t,n[i])&&(s[n[i]]=t[n[i]])}return s}(t,["type","target","model"]);const r=e.getState();delete r._,s.send(Object.assign({type:`${i.$name||"anonymous"}@${n}`},o),r)}))},onDestroy(){window.__REDUX_DEVTOOLS_EXTENSION__.disconnect(s);for(const t of e.values())t();e.clear()}}};return t.NOOP=e,t.assign=n,t.def=v,t.defineModel=t=>t,t.devtool=Bt,t.doura=function({initialState:t,plugins:e=[]}={}){return function({initialState:t,plugins:e}={}){return new Yt(t,e)}({initialState:t,plugins:e})},t.each=function(t,e,s=!1){y(t)?(s?Object.keys:S)(t).forEach((n=>{s&&"symbol"==typeof n||e(n,t[n],t)})):t.forEach(((s,n)=>e(n,s,t)))},t.emptyObject=s,t.extend=i,t.hasOwn=r,t.invariant=w,t.is=b,t.isArray=l,t.isFunction=t=>"function"==typeof t,t.isIntegerKey=g,t.isMap=h,t.isObject=d,t.isPlainObject=y,t.isSet=u,t.isString=f,t.isSymbol=p,t.nextTick=function(t){const e=kt||It;return t?e.then(this?t.bind(this):t):e},t.objectToString=c,t.ownKeys=S,t.set=function(t,e,s){h(t)?t.set(e,s):u(t)?(t.delete(e),t.add(s)):t[e]=s},t.shallowCopy=m,t.toRawType=_,t.toTypeString=a,t}({});
{
"name": "doura",
"version": "0.0.0-rc.8",
"version": "0.0.1",
"description": "Reactive and intuitive state management",

@@ -5,0 +5,0 @@ "main": "index.js",

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc