@estjs/signals 0.0.16-beta.8 → 0.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/signals.cjs
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
'use strict';var shared=require('@estjs/shared');var Ze=Object.defineProperty;var Se=Object.getOwnPropertySymbols;var et=Object.prototype.hasOwnProperty,tt=Object.prototype.propertyIsEnumerable;var Ee=(e,t,n)=>t in e?Ze(e,t,{enumerable:true,configurable:true,writable:true,value:n}):e[t]=n,ge=(e,t)=>{for(var n in t||(t={}))et.call(t,n)&&Ee(e,n,t[n]);if(Se)for(var n of Se(t))tt.call(t,n)&&Ee(e,n,t[n]);return e};var T={SET:"SET",ADD:"ADD",DELETE:"DELETE",CLEAR:"CLEAR"};var P=Symbol(""),g=Symbol(""),N=Symbol(""),ve=Symbol("");var L=Symbol("");var K=0,_,G=false,ie=class{constructor(t,n){this.map=t;this.key=n;this.isDep=true;this.flag=0;}get subLink(){return this._subLink}set subLink(t){this._subLink=t,t===void 0&&this.map.delete(this.key);}};function re(e){e.notify();}function D(e,t){if(G)return;let n=t.depLinkTail;if(n&&n.depNode===e)return n;let i=n?n.nextDepLink:t.depLink;if(i&&i.depNode===e)return i.version=K,t.depLinkTail=i,i;let r=e.subLinkTail;if(r&&r.version===K&&r.subNode===t)return t.depLinkTail=r,r;let o={version:K,depNode:e,subNode:t,prevSubLink:r,nextSubLink:void 0,prevDepLink:n,nextDepLink:i};return i&&(i.prevDepLink=o),n?n.nextDepLink=o:t.depLink=o,r?r.nextSubLink=o:e.subLink=o,e.subLinkTail=o,t.depLinkTail=o,o}function R(e,t=e.subNode){let n=e.depNode,i=e.prevSubLink,r=e.nextSubLink,o=e.prevDepLink,s=e.nextDepLink;if(s?s.prevDepLink=o:t.depLinkTail=o,o?o.nextDepLink=s:t.depLink=s,r?r.prevSubLink=i:n.subLinkTail=i,i)i.nextSubLink=r;else if(n.subLink=r,r===void 0){let c=n.depLink;for(;c;)c=R(c,n);n.depLinkTail=void 0,n.isDep||(n.flag|=16);}return s}function U(e,t){let n,i=0,r=false;e:do{let o=false;if(t.flag&16)o=true;else {let s=e.depNode,c=s.flag;if((c&17)===17){let u=s.subLink;u&&u.nextSubLink&&O(u),o=true;}else if((c&33)===33)if(s.depLink){n={link:e,prev:n},e=s.depLink,t=s,++i;continue e}else s.flag&=-33;else c&32&&(s.flag&=-33);}if(!o&&e.nextDepLink!==void 0){e=e.nextDepLink;continue e}for(r=o;i--;){e=n.link,n=n.prev,t=e.subNode;let s=e.depNode;if(r?s.flag=s.flag&-33|16:s.flag&=-33,s.flag&16&&(r=true),!r&&e.nextDepLink!==void 0){e=e.nextDepLink;continue e}}return r?t.flag=t.flag&-33|16:t.flag&=-33,r}while(true)}function O(e){for(;e;){let t=e.subNode,n=t.flag;(n&48)===32&&(t.flag=n|16,(n&6)===2&&re(t)),e=e.nextSubLink;}}function j(e){let t=e.nextSubLink,n;e:do{let i=e.subNode,r=i.flag&2,o=i.flag;if(o&60?o&12?o&4?!(o&48)&&rt(e,i)?(i.flag=o|40,r&&re(i),o&=1):o=0:i.flag=o&-9|32:o=0:(i.flag=o|32,r&&re(i)),o&1){let s=i.subLink;if(s!==void 0){let c=s.nextSubLink;c!==void 0&&(n={value:t,prev:n},t=c),e=s;continue}}if((e=t)!==void 0){t=e.nextSubLink;continue}for(;n!==void 0;)if(e=n.value,n=n.prev,e!==void 0){t=e.nextSubLink;continue e}break}while(true)}function oe(e){let t=_;return _=e,t}function W(e){return K++,e.depLinkTail=void 0,e.flag=e.flag&-57|4,oe(e)}function H(e,t){_=t;let n=e.depLinkTail,i=n?n.nextDepLink:e.depLink;for(;i;)i=R(i,e);e.flag&=-5;}function it(e){let t=oe(void 0),n=G;G=true;try{return e()}finally{G=n,oe(t);}}function rt(e,t){let n=t.depLinkTail;for(;n;){if(n===e)return true;n=n.prevDepLink;}return false}var se=new WeakMap,ot=0;function ne(e,t,n){if(e)for(let i=e.subLink;i;i=i.nextSubLink){let r=i.subNode;r._triggerVersion!==n&&(r._triggerVersion=n,t.push(r));}}function l(e,t){if(!_||G)return;let n=se.get(e);n||(n=new Map,se.set(e,n));let i=n.get(t);i||(i=new ie(n,t),n.set(t,i)),D(i,_);}function S(e,t,n,i){var c;let r=se.get(e);if(!r)return;let o=[],s=++ot;if(n!==void 0)if(Array.isArray(n))for(let u of n)ne(r.get(u),o,s);else ne(r.get(n),o,s);if(t==="ADD"||t==="DELETE"||t==="CLEAR"){let u=Array.isArray(e)?L:ve;ne(r.get(u),o,s);}for(let u of o)u.flag&2?(c=u.notify)==null||c.call(u):u.flag&1&&(u.flag|=16,u.subLink&&j(u.subLink));}var lt=new WeakMap,pt=new WeakMap;function a(e){if(!e||!shared.isObject(e))return e;let t=e._RAW;return t?a(t):h(e)?a(e.peek()):e}var be=dt();function dt(){let e={};return ["includes","indexOf","lastIndexOf"].forEach(t=>{e[t]=function(...n){let i=a(this);l(i,L);let r=i[t](...n);if((r===-1||r===false)&&n.length>0){let o=n.map(s=>a(s));r=i[t](...o);}return r};}),["find","findIndex","findLast","findLastIndex"].forEach(t=>{e[t]=function(...n){let i=a(this),r=y(this);l(i,L);let o=i[t](...n);return (t==="find"||t==="findLast")&&shared.isObject(o)&&!r?d(o):o};}),["push","pop","shift","unshift","splice","sort","reverse","fill","copyWithin"].forEach(t=>{e[t]=function(...n){let i=a(this),r=Array.prototype[t].apply(i,n);return S(i,T.SET,[P,L]),r};}),["toReversed","toSorted","toSpliced"].forEach(t=>{e[t]=function(...n){let i=a(this),r=y(this);if(l(i,L),t==="toSpliced")for(let s=0,c=i.length;s<c;s++)l(i,`${s}`);let o=Array.prototype[t].apply(i,n);return Array.isArray(o)?o.map(s=>shared.isObject(s)?d(s,r):s):o};}),["concat","slice","filter","map","flatMap","flat"].forEach(t=>{e[t]=function(...n){let i=a(this);return l(i,L),Array.prototype[t].apply(this,n)};}),["join","toString","toLocaleString"].forEach(t=>{e[t]=function(...n){let i=a(this);return l(i,L),Array.prototype[t].apply(i,n)};}),["values","keys","entries",Symbol.iterator].forEach(t=>{e[t]=function(){let n=a(this),i=y(this);l(n,P);let r=t===Symbol.iterator?n[Symbol.iterator]():n[t]();return {next(){let{value:o,done:s}=r.next();return s?{value:o,done:s}:Array.isArray(o)?{value:o.map(c=>shared.isObject(c)?d(c,i):c),done:s}:{value:shared.isObject(o)?d(o,i):o,done:s}},[Symbol.iterator](){return this}}};}),e}function Le(e,t){let n=h(t)?t:a(t);return shared.hasChanged(e,n)}var we=e=>({get:(t,n,i)=>{if(n==="_RAW")return t;if(n==="_IS_REACTIVE")return true;if(n==="_IS_SHALLOW")return e;if(shared.hasOwn(be,n))return be[n];let r=Reflect.get(t,n,i);return shared.isStringNumber(n)&&l(t,n),l(t,P),shared.isObject(r)&&!e?d(r):r},set:(t,n,i,r)=>{let o=Reflect.get(t,n,r),s=a(i),c=Reflect.set(t,n,s,r);return Le(s,o)&&(shared.isStringNumber(n)?S(t,T.SET,[n,L,P]):S(t,T.SET,n)),c}}),ht=we(true),Tt=we(false),Re=e=>({get(t,n){return n==="_IS_REACTIVE"?true:n==="_RAW"?t:n==="_IS_SHALLOW"?e:Reflect.get(shared.hasOwn(me,n)?me:t,n,t)}}),xe=e=>({get(t,n){return n==="_IS_REACTIVE"?true:n==="_RAW"?t:n==="_IS_SHALLOW"?e:Reflect.get(shared.hasOwn(ke,n)&&n in t?ke:t,n,t)}}),St=Re(true),Et=Re(false),gt=xe(true),vt=xe(false),me={get(e){let t=a(this);l(t,g);let n=t.get(e);return shared.isUndefined(n)&&!t.has(e)&&b(e)&&(n=t.get(a(e))),shared.isObject(n)&&!y(this)?d(n):n},set(e,t){let n=a(this),i=a(e),r=n.has(i),o=n.get(i),s=a(t);return n.set(i,s),(!r||shared.hasChanged(o,s))&&S(n,T.SET,g),this},add(e){let t=a(this),n=a(e),i=t.has(n);return t.add(n),i||S(t,T.ADD,g),this},has(e){let t=a(this);l(t,g);let n=t.has(e);return !n&&shared.isObject(e)?t.has(a(e)):n},delete(e){let t=a(this),n=t.has(e),i=t.delete(e);return !i&&shared.isObject(e)&&(i=t.delete(a(e))),(n||i)&&S(t,T.DELETE,g),i},clear(){let e=a(this),t=e.size>0,n=e.clear();return t&&S(e,T.CLEAR,g),n},forEach(e,t){let n=a(this),i=y(this);l(n,g),n.forEach((r,o)=>{let s=i||!shared.isObject(r)?r:d(r),c=i||!shared.isObject(o)?o:d(o);e.call(t,s,c,this);});},[Symbol.iterator](){let e=a(this),t=y(this);l(e,g);let n=e[Symbol.iterator]();return {next(){let{value:i,done:r}=n.next();return r?{value:i,done:r}:t?{value:i,done:r}:Array.isArray(i)?{value:i.map(o=>shared.isObject(o)?d(o):o),done:r}:{value:shared.isObject(i)?d(i):i,done:r}},[Symbol.iterator](){return this}}},get size(){let e=a(this);return l(e,g),e.size},keys(){let e=a(this),t=y(this);l(e,g);let n=e.keys();return {next(){let{value:i,done:r}=n.next();return r?{value:i,done:r}:{value:t||!shared.isObject(i)?i:d(i),done:r}},[Symbol.iterator](){return this}}},values(){let e=a(this),t=y(this);l(e,g);let n=e.values();return {next(){let{value:i,done:r}=n.next();return r?{value:i,done:r}:{value:t||!shared.isObject(i)?i:d(i),done:r}},[Symbol.iterator](){return this}}},entries(){let e=a(this),t=y(this);l(e,g);let n=e.entries();return {next(){let{value:i,done:r}=n.next();return r?{value:i,done:r}:t?{value:i,done:r}:{value:i.map(o=>shared.isObject(o)?d(o):o),done:r}},[Symbol.iterator](){return this}}}},ke={get(e){let t=a(this);l(t,N);let n=t.get(e);return shared.isUndefined(n)&&!t.has(e)&&b(e)&&(n=t.get(a(e))),shared.isObject(n)&&!y(this)?d(n):n},set(e,t){let n=a(this),i=a(e),r=n.has(i),o=n.get(i),s=a(t);return n.set(i,s),(!r||shared.hasChanged(o,s))&&S(n,T.SET,N),this},add(e){let t=a(this),n=a(e),i=t.has(n);return t.add(n),i||S(t,T.ADD,N),this},has(e){let t=a(this);l(t,N);let n=t.has(e);return !n&&b(e)&&(n=t.has(a(e))),n},delete(e){let t=a(this),n=a(e),i=t.has(n),r=t.delete(n);return (i||r)&&S(t,T.DELETE,N),r}},De=e=>({get(t,n,i){if(n==="_RAW")return t;if(n==="_IS_REACTIVE")return true;if(n==="_IS_SHALLOW")return e;let r=Reflect.get(t,n,i),o=h(r)?r.value:r;return l(t,n),shared.isObject(o)&&!e?d(o):o},set:(t,n,i,r)=>{let o=Reflect.get(t,n,r),s=a(i),c=Reflect.set(t,n,s,r);return Le(s,o)&&S(t,T.SET,n),c},deleteProperty:(t,n)=>{let i=shared.hasOwn(t,n),r=Reflect.deleteProperty(t,n);return i&&r&&S(t,T.DELETE,n),r}}),_t=De(true),bt=De(false);function d(e,t=false){if(!shared.isObject(e)||b(e))return e;let n=t?pt:lt,i=n.get(e);if(i)return i;let r;shared.isArray(e)?r=t?ht:Tt:shared.isSet(e)||shared.isMap(e)?r=t?St:Et:shared.isWeakMap(e)||shared.isWeakSet(e)?r=t?gt:vt:r=t?_t:bt;let o=new Proxy(e,r);return n.set(e,o),o}function b(e){return !!(e&&e._IS_REACTIVE)}function I(e){return b(e)||h(e)?e:d(e)}function q(e){return b(e)||h(e)?e:d(e,true)}function y(e){return !!(e&&e._IS_SHALLOW)}var mt=e=>shared.isObject(e)?I(e):e;var Ae;Ae="_IS_SIGNAL";var V=class{constructor(t,n=false){this.flag=1;this[Ae]=true;let i=a(t);this._rawValue=i,this._IS_SHALLOW=n,Ce(i)?b(t)?this._value=t:this._value=n?q(i):I(i):this._value=i;}get dep(){return this}get value(){let t=_;if(t&&D(this,t),this.flag&16&&this.shouldUpdate()){let i=this.subLink;i&&O(i);}return this._value}set value(t){h(t)&&(t=t.peek());let n=t,i=a(t);if(!shared.hasChanged(this._rawValue,i))return;if(this._oldValue=this._rawValue,this._rawValue=i,this.flag|=16,!Ce(i))this._value=i;else if(b(n))this._value=n;else {let o=this._IS_SHALLOW;this._value=o?q(i):I(i);}let r=this.subLink;r&&j(r);}shouldUpdate(){if(this.flag&=-17,!("_oldValue"in this))return true;let t=shared.hasChanged(this._oldValue,this._rawValue);return this._oldValue=this._rawValue,t}peek(){return this._value}set(t){this.value=t;}update(t){let n=t(this.peek());h(n)?this.value=n.peek():this.value=n;}};function Ce(e){return shared.isObject(e)?shared.isArray(e)||shared.isMap(e)||shared.isSet(e)||shared.isWeakMap(e)||shared.isWeakSet(e)||shared.isPlainObject(e):false}function It(e){return h(e)?e:new V(e)}function Ct(e){return h(e)&&(e=e.peek()),new V(e,true)}function h(e){return !!e&&!!e._IS_SIGNAL}var B=new Set,ce=new Set,Ne=Promise.resolve(),ue=false;function Ve(e){return e?Ne.then(e):Ne}function C(e){B.add(e),Pe();}function Pe(){ue||(ue=true,Ve(fe));}function Ge(e){ce.add(e),Pe();}function fe(){for(ue=false,At();B.size>0;){for(let e of B)try{e();}catch(t){}B.clear();}}function At(){let e=Array.from(ce);ce.clear();for(let t of e)try{t();}catch(n){}}function Oe(e,t){switch(t){case "sync":return ()=>e();case "pre":return ()=>Ge(e);case "post":return ()=>C(e);default:return ()=>C(e)}}var Y=0;function $(e){je();try{return e()}finally{Ye();}}function je(){Y++;}function Ye(){Y--,Y===0&&fe();}function le(){return Y>0}function Nt(){return Y}var m,J=class{constructor(t=false,n=void 0){this.detached=t;this.parent=n;this._active=true;this.effects=[];this.scopes=[];this.cleanups=[];!t&&m&&(this.parent=m,m.scopes.push(this));}get active(){return this._active}pause(){var t,n;if(this._active){for(let i=0;i<this.scopes.length;i++)this.scopes[i].pause();for(let i=0;i<this.effects.length;i++)(n=(t=this.effects[i]).pause)==null||n.call(t);}}resume(){var t,n;if(this._active){for(let i=0;i<this.scopes.length;i++)this.scopes[i].resume();for(let i=0;i<this.effects.length;i++)(n=(t=this.effects[i]).resume)==null||n.call(t);}}run(t){if(!this._active)return;let n=m;m=this;try{return t()}finally{m=n;}}stop(t=false){if(!this._active)return;this._active=false;for(let i=0;i<this.scopes.length;i++)this.scopes[i].stop(true);this.scopes.length=0;let n=this.effects.slice();this.effects.length=0;for(let i of n)i.stop();for(let i=0;i<this.cleanups.length;i++)this.cleanups[i]();if(this.cleanups.length=0,!t&&this.parent){let i=this.parent.scopes.indexOf(this);i>=0&&this.parent.scopes.splice(i,1);}this.parent=void 0;}_record(t){this.effects.push(t),t.scope=this;}_remove(t){let n=this.effects.indexOf(t);n>=0&&this.effects.splice(n,1);}_pushCleanup(t){this.cleanups.push(t);}};function Vt(e=false){return new J(e)}function Pt(){return m}function Gt(e){let t=m;return m=e,t}function Ot(e,t=false){m&&m._pushCleanup(e);}function z(e,t=m){t&&t.active&&t._record(e);}function Q(e){let t=e.scope;t&&(e.scope=void 0,t._remove(e));}var Ke;Ke="_IS_EFFECT";var pe=class{constructor(t,n){this.flag=18;this[Ke]=true;this._active=true;if(this.fn=t,n){this.options=n;let i=n.flush||n.scheduler;i&&!shared.isFunction(i)&&(this._flushScheduler=Oe(()=>this.run(),i));}z(this);}get active(){return this._active}get dirty(){let t=this.flag;if(t&16)return true;if(t&32){if(this.depLink&&U(this.depLink,this))return this.flag=t&-33|16,true;this.flag=t&-33;}return false}pause(){this.flag|=256;}resume(){let n=this.flag&-257;this.flag=n;let i=(n&16)!==0,r=(n&32)!==0;(i||r)&&this.notify();}run(){if(!this._active)return this.fn();let t=this.flag;this.flag=t&-49|512;let n=W(this);try{return this.fn()}catch(i){throw this.flag|=16,i}finally{this.flag&=-513,H(this,n);}}getJob(){return this._job||(this._job=()=>this.run()),this._job}notify(){var r,o,s;let t=this.flag;if(!this._active||t&784)return;this.flag=t|16;let n=((r=this.options)==null?void 0:r.flush)||((o=this.options)==null?void 0:o.scheduler);n?shared.isFunction(n)?n(this):(s=this._flushScheduler)==null||s.call(this):le()?C(this.getJob()):this.run();}stop(){var i;if(!this._active)return;this._active=false,Q(this);let t=this.depLink;for(;t;)t=R(t,this);let n=this.subLink;for(;n;)n=R(n);this._job=void 0,this._flushScheduler=void 0,this.depLinkTail=void 0,this.subLinkTail=void 0,(i=this.options)!=null&&i.onStop&&this.options.onStop();}};function X(e,t){let n=new pe(e,t);try{n.run();}catch(r){throw n.stop(),r}let i=()=>n.run();return i.effect=n,i.stop=()=>n.stop(),i}function jt(e){e.effect.stop();}function Yt(e){return !!(e&&e._IS_EFFECT)}function Mt(e,t,n){let i=t;return X(()=>{i=e(i);},n)}var w=Symbol("computed-no-value"),He;He="_IS_COMPUTED";var Z=class{constructor(t,n,i,r){this.flag=17;this[He]=true;this._value=w;this._active=true;this.getter=t,this.setter=n,this.onTrack=i,this.onTrigger=r,this.flag|=16,z(this);}get value(){if(!this.active)return this._value===w?this.getter():this._value;_&&D(this,_);let t=this.flag,n=this._value!==w;return n&&!(t&48)?this._value:!n||t&16?(this.recompute(),this._value):(t&32&&(this.depLink&&U(this.depLink,this)?this.recompute():this.flag=t&-33),this._value)}set value(t){this.setter&&this.setter(t);}peek(){return this.active?(this._value===w&&this.recompute(),this._value):this._value===w?this.getter():this._value}get active(){return this._active}recompute(){if(!this._active){this._value===w&&(this._value=this.getter());return}let t=this._value,n=t!==w,i=W(this);try{let r=this.getter(),o=this.flag,s=this.subLink,c=-49;!n||shared.hasChanged(t,r)?(this._value=r,this.flag=o&c,s&&O(s)):this.flag=o&c;}catch(r){let o=-49;throw this.flag&=o,this._value=w,r}finally{H(this,i);}}shouldUpdate(){let t=this._value!==w,n=this._value;return this.recompute(),t?shared.hasChanged(this._value,n):true}stop(){if(!this._active)return;this._active=false,Q(this);let t=this.depLink;for(;t;)t=R(t,this);let n=this.subLink;for(;n;)n=R(n);this.depLinkTail=void 0,this.subLinkTail=void 0,this.flag&=-49;}};function de(e){if(M(e))return e;if(!e)throw new Error("[Computed] Invalid argument: computed() requires a getter function or options object.");if(shared.isFunction(e))return new Z(e);if(shared.isPlainObject(e)){let{get:t,set:n,onTrack:i,onTrigger:r}=e;if(!t)throw new Error(`[Computed] Invalid options: getter function is required.
|
|
2
|
+
Usage: computed({ get: () => value, set: (v) => { ... } })`);if(!shared.isFunction(t))throw new TypeError(`[Computed] Invalid options: getter must be a function.
|
|
3
|
+
Received: ${typeof t}`);return new Z(t,n,i,r)}throw new Error(`[Computed] Invalid argument: expected a function or options object.
|
|
4
|
+
Received: ${typeof e}`)}function M(e){return !!e&&!!e._IS_COMPUTED}function Ut(e){let{state:t,getters:n,actions:i}=e,r=ge({},t),o=I(t),s=new Set,c=new Set,u=f=>{s.forEach(k=>k(f)),c.forEach(k=>k(f));},x={patch$(f){$(()=>{Object.assign(o,f);}),u(o);},subscribe$(f){s.add(f);},unsubscribe$(f){s.delete(f);},onAction$(f){c.add(f);},offAction$(f){c.delete(f);},reset$(){$(()=>{Object.assign(o,r);}),u(o);}},E={};for(let f of Object.keys(r))Object.defineProperty(E,f,{get:()=>o[f],set:k=>{o[f]=k;},enumerable:true,configurable:true});if(Object.defineProperty(E,"state",{value:o,enumerable:true,configurable:true,writable:true}),Object.assign(E,x),n)for(let f in n){let k=n[f];if(!k)continue;let te=de(()=>k.call(E,o));Object.defineProperty(E,f,{get:()=>te.value,enumerable:true,configurable:true});}if(i)for(let f in i){let k=i[f];k&&(E[f]=(...te)=>{let Qe=k.apply(E,te);return c.forEach(Xe=>Xe(o)),Qe});}return E}function Wt(e){let t=new e,n=Object.create(null),i={},r={};return Object.getOwnPropertyNames(t).forEach(o=>{n[o]=t[o];}),Object.getOwnPropertyNames(e.prototype).forEach(o=>{let s=Object.getOwnPropertyDescriptor(e.prototype,o);s&&(shared.isFunction(s.get)?i[o]=function(){return s.get.call(this)}:shared.isFunction(s.value)&&o!=="constructor"&&(r[o]=function(...c){return s.value.apply(this,c)}));}),{state:n,getters:i,actions:r}}function Ht(e){return ()=>{let t;return shared.isFunction(e)?t=Wt(e):t=e,Ut(t)}}var Fe,qe,ee=class extends(qe=V,Fe="_IS_REF",qe){constructor(n){super(n,true);this[Fe]=true;}get value(){let n=_;return n&&D(this,n),this._value}set value(n){h(n)&&(n=n.peek()),Te(n)&&(n=n.value),shared.hasChanged(this._value,n)&&(this._rawValue=n,this._value=n,this.flag|=16,this.subLink&&j(this.subLink));}};function qt(e=void 0){return Te(e)?e:h(e)?new ee(e.peek()):new ee(e)}function Te(e){return !!e&&!!e._IS_REF}var Be={},$e=new Set;function A(e,t){if(t||($e.clear(),t=$e),!shared.isObject(e)||t.has(e))return e;if(t.add(e),h(e)||M(e))return A(e.value,t);if(Array.isArray(e))for(let n of e)A(n,t);else shared.isMap(e)?(e.forEach(n=>{A(n,t);}),e.keys(),e.values()):shared.isSet(e)?(e.forEach(n=>{A(n,t);}),e.values()):Object.keys(e).forEach(n=>{A(e[n],t);});return e}function Je(e){return shared.isFunction(e)?e:h(e)||M(e)?()=>e.value:b(e)?()=>A(e):()=>e}function Qt(e){if(Array.isArray(e)){let t=e.map(n=>Je(n));return ()=>t.map(n=>n())}return Je(e)}function Xt(e,t,n={}){let{immediate:i=false,deep:r=false}=n,o=Be,s=Qt(e),c=()=>{let x=u.effect;if(!x.run)return;let E=x.run();(r||shared.isObject(E)||shared.hasChanged(E,o))&&(t(E,o===Be?void 0:o),o=E);},u=X(()=>{let x=s();return r&&A(x),x},{scheduler:()=>C(c)});return i?c():o=u.effect.run(),()=>{u.stop();}}exports.EffectScope=J;exports.TriggerOpTypes=T;exports.batch=$;exports.computed=de;exports.createStore=Ht;exports.effect=X;exports.effectScope=Vt;exports.endBatch=Ye;exports.getBatchDepth=Nt;exports.getCurrentScope=Pt;exports.isBatching=le;exports.isComputed=M;exports.isEffect=Yt;exports.isReactive=b;exports.isRef=Te;exports.isShallow=y;exports.isSignal=h;exports.memoEffect=Mt;exports.nextTick=Ve;exports.onScopeDispose=Ot;exports.queueJob=C;exports.queuePreFlushCb=Ge;exports.reactive=I;exports.ref=qt;exports.setCurrentScope=Gt;exports.shallowReactive=q;exports.shallowSignal=Ct;exports.signal=It;exports.startBatch=je;exports.stop=jt;exports.toRaw=a;exports.toReactive=mt;exports.trigger=S;exports.untrack=it;exports.watch=Xt;
|
|
@@ -54,8 +54,7 @@ var Dep = class {
|
|
|
54
54
|
}
|
|
55
55
|
};
|
|
56
56
|
function enqueueEffect(effect2) {
|
|
57
|
-
|
|
58
|
-
(_a5 = effect2 == null ? void 0 : effect2.notify) == null ? void 0 : _a5.call(effect2);
|
|
57
|
+
effect2.notify();
|
|
59
58
|
}
|
|
60
59
|
function linkReactiveNode(depNode, subNode) {
|
|
61
60
|
if (isUntracking) {
|
|
@@ -52,8 +52,7 @@ var Dep = class {
|
|
|
52
52
|
}
|
|
53
53
|
};
|
|
54
54
|
function enqueueEffect(effect2) {
|
|
55
|
-
|
|
56
|
-
(_a5 = effect2 == null ? void 0 : effect2.notify) == null ? void 0 : _a5.call(effect2);
|
|
55
|
+
effect2.notify();
|
|
57
56
|
}
|
|
58
57
|
function linkReactiveNode(depNode, subNode) {
|
|
59
58
|
if (isUntracking) {
|
package/dist/signals.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import {isObject,isFunction,isPlainObject,hasChanged,isArray,isSet,isMap,isWeakMap,isWeakSet,isStringNumber,hasOwn,isUndefined}from'@estjs/shared';var et=Object.defineProperty;var Ee=Object.getOwnPropertySymbols;var tt=Object.prototype.hasOwnProperty,nt=Object.prototype.propertyIsEnumerable;var ge=(e,t,n)=>t in e?et(e,t,{enumerable:true,configurable:true,writable:true,value:n}):e[t]=n,ve=(e,t)=>{for(var n in t||(t={}))tt.call(t,n)&&ge(e,n,t[n]);if(Ee)for(var n of Ee(t))nt.call(t,n)&&ge(e,n,t[n]);return e};var T={SET:"SET",ADD:"ADD",DELETE:"DELETE",CLEAR:"CLEAR"};var G=Symbol(""),g=Symbol(""),V=Symbol(""),_e=Symbol("");var w=Symbol("");var U=0,b,O=false,re=class{constructor(t,n){this.map=t;this.key=n;this.isDep=true;this.flag=0;}get subLink(){return this._subLink}set subLink(t){this._subLink=t,t===void 0&&this.map.delete(this.key);}};function oe(e){e.notify();}function I(e,t){if(O)return;let n=t.depLinkTail;if(n&&n.depNode===e)return n;let i=n?n.nextDepLink:t.depLink;if(i&&i.depNode===e)return i.version=U,t.depLinkTail=i,i;let r=e.subLinkTail;if(r&&r.version===U&&r.subNode===t)return t.depLinkTail=r,r;let o={version:U,depNode:e,subNode:t,prevSubLink:r,nextSubLink:void 0,prevDepLink:n,nextDepLink:i};return i&&(i.prevDepLink=o),n?n.nextDepLink=o:t.depLink=o,r?r.nextSubLink=o:e.subLink=o,e.subLinkTail=o,t.depLinkTail=o,o}function x(e,t=e.subNode){let n=e.depNode,i=e.prevSubLink,r=e.nextSubLink,o=e.prevDepLink,s=e.nextDepLink;if(s?s.prevDepLink=o:t.depLinkTail=o,o?o.nextDepLink=s:t.depLink=s,r?r.prevSubLink=i:n.subLinkTail=i,i)i.nextSubLink=r;else if(n.subLink=r,r===void 0){let c=n.depLink;for(;c;)c=x(c,n);n.depLinkTail=void 0,n.isDep||(n.flag|=16);}return s}function W(e,t){let n,i=0,r=false;e:do{let o=false;if(t.flag&16)o=true;else {let s=e.depNode,c=s.flag;if((c&17)===17){let u=s.subLink;u&&u.nextSubLink&&j(u),o=true;}else if((c&33)===33)if(s.depLink){n={link:e,prev:n},e=s.depLink,t=s,++i;continue e}else s.flag&=-33;else c&32&&(s.flag&=-33);}if(!o&&e.nextDepLink!==void 0){e=e.nextDepLink;continue e}for(r=o;i--;){e=n.link,n=n.prev,t=e.subNode;let s=e.depNode;if(r?s.flag=s.flag&-33|16:s.flag&=-33,s.flag&16&&(r=true),!r&&e.nextDepLink!==void 0){e=e.nextDepLink;continue e}}return r?t.flag=t.flag&-33|16:t.flag&=-33,r}while(true)}function j(e){for(;e;){let t=e.subNode,n=t.flag;(n&48)===32&&(t.flag=n|16,(n&6)===2&&oe(t)),e=e.nextSubLink;}}function Y(e){let t=e.nextSubLink,n;e:do{let i=e.subNode,r=i.flag&2,o=i.flag;if(o&60?o&12?o&4?!(o&48)&&ot(e,i)?(i.flag=o|40,r&&oe(i),o&=1):o=0:i.flag=o&-9|32:o=0:(i.flag=o|32,r&&oe(i)),o&1){let s=i.subLink;if(s!==void 0){let c=s.nextSubLink;c!==void 0&&(n={value:t,prev:n},t=c),e=s;continue}}if((e=t)!==void 0){t=e.nextSubLink;continue}for(;n!==void 0;)if(e=n.value,n=n.prev,e!==void 0){t=e.nextSubLink;continue e}break}while(true)}function se(e){let t=b;return b=e,t}function H(e){return U++,e.depLinkTail=void 0,e.flag=e.flag&-57|4,se(e)}function F(e,t){b=t;let n=e.depLinkTail,i=n?n.nextDepLink:e.depLink;for(;i;)i=x(i,e);e.flag&=-5;}function rt(e){let t=se(void 0),n=O;O=true;try{return e()}finally{O=n,se(t);}}function ot(e,t){let n=t.depLinkTail;for(;n;){if(n===e)return true;n=n.prevDepLink;}return false}var ae=new WeakMap,st=0;function ie(e,t,n){if(e)for(let i=e.subLink;i;i=i.nextSubLink){let r=i.subNode;r._triggerVersion!==n&&(r._triggerVersion=n,t.push(r));}}function l(e,t){if(!b||O)return;let n=ae.get(e);n||(n=new Map,ae.set(e,n));let i=n.get(t);i||(i=new re(n,t),n.set(t,i)),I(i,b);}function S(e,t,n,i){var c;let r=ae.get(e);if(!r)return;let o=[],s=++st;if(n!==void 0)if(Array.isArray(n))for(let u of n)ie(r.get(u),o,s);else ie(r.get(n),o,s);if(t==="ADD"||t==="DELETE"||t==="CLEAR"){let u=Array.isArray(e)?w:_e;ie(r.get(u),o,s);}for(let u of o)u.flag&2?(c=u.notify)==null||c.call(u):u.flag&1&&(u.flag|=16,u.subLink&&Y(u.subLink));}var pt=new WeakMap,dt=new WeakMap;function a(e){if(!e||!isObject(e))return e;let t=e._RAW;return t?a(t):h(e)?a(e.peek()):e}var me=ht();function ht(){let e={};return ["includes","indexOf","lastIndexOf"].forEach(t=>{e[t]=function(...n){let i=a(this);l(i,w);let r=i[t](...n);if((r===-1||r===false)&&n.length>0){let o=n.map(s=>a(s));r=i[t](...o);}return r};}),["find","findIndex","findLast","findLastIndex"].forEach(t=>{e[t]=function(...n){let i=a(this),r=L(this);l(i,w);let o=i[t](...n);return (t==="find"||t==="findLast")&&isObject(o)&&!r?d(o):o};}),["push","pop","shift","unshift","splice","sort","reverse","fill","copyWithin"].forEach(t=>{e[t]=function(...n){let i=a(this),r=Array.prototype[t].apply(i,n);return S(i,T.SET,[G,w]),r};}),["toReversed","toSorted","toSpliced"].forEach(t=>{e[t]=function(...n){let i=a(this),r=L(this);if(l(i,w),t==="toSpliced")for(let s=0,c=i.length;s<c;s++)l(i,`${s}`);let o=Array.prototype[t].apply(i,n);return Array.isArray(o)?o.map(s=>isObject(s)?d(s,r):s):o};}),["concat","slice","filter","map","flatMap","flat"].forEach(t=>{e[t]=function(...n){let i=a(this);return l(i,w),Array.prototype[t].apply(this,n)};}),["join","toString","toLocaleString"].forEach(t=>{e[t]=function(...n){let i=a(this);return l(i,w),Array.prototype[t].apply(i,n)};}),["values","keys","entries",Symbol.iterator].forEach(t=>{e[t]=function(){let n=a(this),i=L(this);l(n,G);let r=t===Symbol.iterator?n[Symbol.iterator]():n[t]();return {next(){let{value:o,done:s}=r.next();return s?{value:o,done:s}:Array.isArray(o)?{value:o.map(c=>isObject(c)?d(c,i):c),done:s}:{value:isObject(o)?d(o,i):o,done:s}},[Symbol.iterator](){return this}}};}),e}function we(e,t){let n=h(t)?t:a(t);return hasChanged(e,n)}var Re=e=>({get:(t,n,i)=>{if(n==="_RAW")return t;if(n==="_IS_REACTIVE")return true;if(n==="_IS_SHALLOW")return e;if(hasOwn(me,n))return me[n];let r=Reflect.get(t,n,i);return isStringNumber(n)&&l(t,n),l(t,G),isObject(r)&&!e?d(r):r},set:(t,n,i,r)=>{let o=Reflect.get(t,n,r),s=a(i),c=Reflect.set(t,n,s,r);return we(s,o)&&(isStringNumber(n)?S(t,T.SET,[n,w,G]):S(t,T.SET,n)),c}}),Tt=Re(true),St=Re(false),xe=e=>({get(t,n){return n==="_IS_REACTIVE"?true:n==="_RAW"?t:n==="_IS_SHALLOW"?e:Reflect.get(hasOwn(ke,n)?ke:t,n,t)}}),De=e=>({get(t,n){return n==="_IS_REACTIVE"?true:n==="_RAW"?t:n==="_IS_SHALLOW"?e:Reflect.get(hasOwn(ye,n)&&n in t?ye:t,n,t)}}),Et=xe(true),gt=xe(false),vt=De(true),_t=De(false),ke={get(e){let t=a(this);l(t,g);let n=t.get(e);return isUndefined(n)&&!t.has(e)&&m(e)&&(n=t.get(a(e))),isObject(n)&&!L(this)?d(n):n},set(e,t){let n=a(this),i=a(e),r=n.has(i),o=n.get(i),s=a(t);return n.set(i,s),(!r||hasChanged(o,s))&&S(n,T.SET,g),this},add(e){let t=a(this),n=a(e),i=t.has(n);return t.add(n),i||S(t,T.ADD,g),this},has(e){let t=a(this);l(t,g);let n=t.has(e);return !n&&isObject(e)?t.has(a(e)):n},delete(e){let t=a(this),n=t.has(e),i=t.delete(e);return !i&&isObject(e)&&(i=t.delete(a(e))),(n||i)&&S(t,T.DELETE,g),i},clear(){let e=a(this),t=e.size>0,n=e.clear();return t&&S(e,T.CLEAR,g),n},forEach(e,t){let n=a(this),i=L(this);l(n,g),n.forEach((r,o)=>{let s=i||!isObject(r)?r:d(r),c=i||!isObject(o)?o:d(o);e.call(t,s,c,this);});},[Symbol.iterator](){let e=a(this),t=L(this);l(e,g);let n=e[Symbol.iterator]();return {next(){let{value:i,done:r}=n.next();return r?{value:i,done:r}:t?{value:i,done:r}:Array.isArray(i)?{value:i.map(o=>isObject(o)?d(o):o),done:r}:{value:isObject(i)?d(i):i,done:r}},[Symbol.iterator](){return this}}},get size(){let e=a(this);return l(e,g),e.size},keys(){let e=a(this),t=L(this);l(e,g);let n=e.keys();return {next(){let{value:i,done:r}=n.next();return r?{value:i,done:r}:{value:t||!isObject(i)?i:d(i),done:r}},[Symbol.iterator](){return this}}},values(){let e=a(this),t=L(this);l(e,g);let n=e.values();return {next(){let{value:i,done:r}=n.next();return r?{value:i,done:r}:{value:t||!isObject(i)?i:d(i),done:r}},[Symbol.iterator](){return this}}},entries(){let e=a(this),t=L(this);l(e,g);let n=e.entries();return {next(){let{value:i,done:r}=n.next();return r?{value:i,done:r}:t?{value:i,done:r}:{value:i.map(o=>isObject(o)?d(o):o),done:r}},[Symbol.iterator](){return this}}}},ye={get(e){let t=a(this);l(t,V);let n=t.get(e);return isUndefined(n)&&!t.has(e)&&m(e)&&(n=t.get(a(e))),isObject(n)&&!L(this)?d(n):n},set(e,t){let n=a(this),i=a(e),r=n.has(i),o=n.get(i),s=a(t);return n.set(i,s),(!r||hasChanged(o,s))&&S(n,T.SET,V),this},add(e){let t=a(this),n=a(e),i=t.has(n);return t.add(n),i||S(t,T.ADD,V),this},has(e){let t=a(this);l(t,V);let n=t.has(e);return !n&&m(e)&&(n=t.has(a(e))),n},delete(e){let t=a(this),n=a(e),i=t.has(n),r=t.delete(n);return (i||r)&&S(t,T.DELETE,V),r}},Ie=e=>({get(t,n,i){if(n==="_RAW")return t;if(n==="_IS_REACTIVE")return true;if(n==="_IS_SHALLOW")return e;let r=Reflect.get(t,n,i),o=h(r)?r.value:r;return l(t,n),isObject(o)&&!e?d(o):o},set:(t,n,i,r)=>{let o=Reflect.get(t,n,r),s=a(i),c=Reflect.set(t,n,s,r);return we(s,o)&&S(t,T.SET,n),c},deleteProperty:(t,n)=>{let i=hasOwn(t,n),r=Reflect.deleteProperty(t,n);return i&&r&&S(t,T.DELETE,n),r}}),bt=Ie(true),mt=Ie(false);function d(e,t=false){if(!isObject(e)||m(e))return e;let n=t?dt:pt,i=n.get(e);if(i)return i;let r;isArray(e)?r=t?Tt:St:isSet(e)||isMap(e)?r=t?Et:gt:isWeakMap(e)||isWeakSet(e)?r=t?vt:_t:r=t?bt:mt;let o=new Proxy(e,r);return n.set(e,o),o}function m(e){return !!(e&&e._IS_REACTIVE)}function C(e){return m(e)||h(e)?e:d(e)}function B(e){return m(e)||h(e)?e:d(e,true)}function L(e){return !!(e&&e._IS_SHALLOW)}var kt=e=>isObject(e)?C(e):e;var Ne;Ne="_IS_SIGNAL";var P=class{constructor(t,n=false){this.flag=1;this[Ne]=true;let i=a(t);this._rawValue=i,this._IS_SHALLOW=n,Ae(i)?m(t)?this._value=t:this._value=n?B(i):C(i):this._value=i;}get dep(){return this}get value(){let t=b;if(t&&I(this,t),this.flag&16&&this.shouldUpdate()){let i=this.subLink;i&&j(i);}return this._value}set value(t){h(t)&&(t=t.peek());let n=t,i=a(t);if(!hasChanged(this._rawValue,i))return;if(this._oldValue=this._rawValue,this._rawValue=i,this.flag|=16,!Ae(i))this._value=i;else if(m(n))this._value=n;else {let o=this._IS_SHALLOW;this._value=o?B(i):C(i);}let r=this.subLink;r&&Y(r);}shouldUpdate(){if(this.flag&=-17,!("_oldValue"in this))return true;let t=hasChanged(this._oldValue,this._rawValue);return this._oldValue=this._rawValue,t}peek(){return this._value}set(t){this.value=t;}update(t){let n=t(this.peek());h(n)?this.value=n.peek():this.value=n;}};function Ae(e){return isObject(e)?isArray(e)||isMap(e)||isSet(e)||isWeakMap(e)||isWeakSet(e)||isPlainObject(e):false}function Ct(e){return h(e)?e:new P(e)}function At(e){return h(e)&&(e=e.peek()),new P(e,true)}function h(e){return !!e&&!!e._IS_SIGNAL}var $=new Set,ue=new Set,Ve=Promise.resolve(),fe=false;function Pe(e){return e?Ve.then(e):Ve}function A(e){$.add(e),Ge();}function Ge(){fe||(fe=true,Pe(le));}function Oe(e){ue.add(e),Ge();}function le(){for(fe=false,Nt();$.size>0;){for(let e of $)try{e();}catch(t){}$.clear();}}function Nt(){let e=Array.from(ue);ue.clear();for(let t of e)try{t();}catch(n){}}function je(e,t){switch(t){case "sync":return ()=>e();case "pre":return ()=>Oe(e);case "post":return ()=>A(e);default:return ()=>A(e)}}var M=0;function J(e){Ye();try{return e()}finally{Me();}}function Ye(){M++;}function Me(){M--,M===0&&le();}function pe(){return M>0}function Vt(){return M}var k,z=class{constructor(t=false,n=void 0){this.detached=t;this.parent=n;this._active=true;this.effects=[];this.scopes=[];this.cleanups=[];!t&&k&&(this.parent=k,k.scopes.push(this));}get active(){return this._active}pause(){var t,n;if(this._active){for(let i=0;i<this.scopes.length;i++)this.scopes[i].pause();for(let i=0;i<this.effects.length;i++)(n=(t=this.effects[i]).pause)==null||n.call(t);}}resume(){var t,n;if(this._active){for(let i=0;i<this.scopes.length;i++)this.scopes[i].resume();for(let i=0;i<this.effects.length;i++)(n=(t=this.effects[i]).resume)==null||n.call(t);}}run(t){if(!this._active)return;let n=k;k=this;try{return t()}finally{k=n;}}stop(t=false){if(!this._active)return;this._active=false;for(let i=0;i<this.scopes.length;i++)this.scopes[i].stop(true);this.scopes.length=0;let n=this.effects.slice();this.effects.length=0;for(let i of n)i.stop();for(let i=0;i<this.cleanups.length;i++)this.cleanups[i]();if(this.cleanups.length=0,!t&&this.parent){let i=this.parent.scopes.indexOf(this);i>=0&&this.parent.scopes.splice(i,1);}this.parent=void 0;}_record(t){this.effects.push(t),t.scope=this;}_remove(t){let n=this.effects.indexOf(t);n>=0&&this.effects.splice(n,1);}_pushCleanup(t){this.cleanups.push(t);}};function Pt(e=false){return new z(e)}function Gt(){return k}function Ot(e){let t=k;return k=e,t}function jt(e,t=false){k&&k._pushCleanup(e);}function Q(e,t=k){t&&t.active&&t._record(e);}function X(e){let t=e.scope;t&&(e.scope=void 0,t._remove(e));}var Ue;Ue="_IS_EFFECT";var de=class{constructor(t,n){this.flag=18;this[Ue]=true;this._active=true;if(this.fn=t,n){this.options=n;let i=n.flush||n.scheduler;i&&!isFunction(i)&&(this._flushScheduler=je(()=>this.run(),i));}Q(this);}get active(){return this._active}get dirty(){let t=this.flag;if(t&16)return true;if(t&32){if(this.depLink&&W(this.depLink,this))return this.flag=t&-33|16,true;this.flag=t&-33;}return false}pause(){this.flag|=256;}resume(){let n=this.flag&-257;this.flag=n;let i=(n&16)!==0,r=(n&32)!==0;(i||r)&&this.notify();}run(){if(!this._active)return this.fn();let t=this.flag;this.flag=t&-49|512;let n=H(this);try{return this.fn()}catch(i){throw this.flag|=16,i}finally{this.flag&=-513,F(this,n);}}getJob(){return this._job||(this._job=()=>this.run()),this._job}notify(){var r,o,s;let t=this.flag;if(!this._active||t&784)return;this.flag=t|16;let n=((r=this.options)==null?void 0:r.flush)||((o=this.options)==null?void 0:o.scheduler);n?isFunction(n)?n(this):(s=this._flushScheduler)==null||s.call(this):pe()?A(this.getJob()):this.run();}stop(){var i;if(!this._active)return;this._active=false,X(this);let t=this.depLink;for(;t;)t=x(t,this);let n=this.subLink;for(;n;)n=x(n);this._job=void 0,this._flushScheduler=void 0,this.depLinkTail=void 0,this.subLinkTail=void 0,(i=this.options)!=null&&i.onStop&&this.options.onStop();}};function Z(e,t){let n=new de(e,t);try{n.run();}catch(r){throw n.stop(),r}let i=()=>n.run();return i.effect=n,i.stop=()=>n.stop(),i}function Yt(e){e.effect.stop();}function Mt(e){return !!(e&&e._IS_EFFECT)}function Kt(e,t,n){let i=t;return Z(()=>{i=e(i);},n)}var R=Symbol("computed-no-value"),Fe;Fe="_IS_COMPUTED";var ee=class{constructor(t,n,i,r){this.flag=17;this[Fe]=true;this._value=R;this._active=true;this.getter=t,this.setter=n,this.onTrack=i,this.onTrigger=r,this.flag|=16,Q(this);}get value(){if(!this.active)return this._value===R?this.getter():this._value;b&&I(this,b);let t=this.flag,n=this._value!==R;return n&&!(t&48)?this._value:!n||t&16?(this.recompute(),this._value):(t&32&&(this.depLink&&W(this.depLink,this)?this.recompute():this.flag=t&-33),this._value)}set value(t){this.setter&&this.setter(t);}peek(){return this.active?(this._value===R&&this.recompute(),this._value):this._value===R?this.getter():this._value}get active(){return this._active}recompute(){if(!this._active){this._value===R&&(this._value=this.getter());return}let t=this._value,n=t!==R,i=H(this);try{let r=this.getter(),o=this.flag,s=this.subLink,c=-49;!n||hasChanged(t,r)?(this._value=r,this.flag=o&c,s&&j(s)):this.flag=o&c;}catch(r){let o=-49;throw this.flag&=o,this._value=R,r}finally{F(this,i);}}shouldUpdate(){let t=this._value!==R,n=this._value;return this.recompute(),t?hasChanged(this._value,n):true}stop(){if(!this._active)return;this._active=false,X(this);let t=this.depLink;for(;t;)t=x(t,this);let n=this.subLink;for(;n;)n=x(n);this.depLinkTail=void 0,this.subLinkTail=void 0,this.flag&=-49;}};function he(e){if(K(e))return e;if(!e)throw new Error("[Computed] Invalid argument: computed() requires a getter function or options object.");if(isFunction(e))return new ee(e);if(isPlainObject(e)){let{get:t,set:n,onTrack:i,onTrigger:r}=e;if(!t)throw new Error(`[Computed] Invalid options: getter function is required.
|
|
2
|
+
Usage: computed({ get: () => value, set: (v) => { ... } })`);if(!isFunction(t))throw new TypeError(`[Computed] Invalid options: getter must be a function.
|
|
3
|
+
Received: ${typeof t}`);return new ee(t,n,i,r)}throw new Error(`[Computed] Invalid argument: expected a function or options object.
|
|
4
|
+
Received: ${typeof e}`)}function K(e){return !!e&&!!e._IS_COMPUTED}function Wt(e){let{state:t,getters:n,actions:i}=e,r=ve({},t),o=C(t),s=new Set,c=new Set,u=f=>{s.forEach(y=>y(f)),c.forEach(y=>y(f));},D={patch$(f){J(()=>{Object.assign(o,f);}),u(o);},subscribe$(f){s.add(f);},unsubscribe$(f){s.delete(f);},onAction$(f){c.add(f);},offAction$(f){c.delete(f);},reset$(){J(()=>{Object.assign(o,r);}),u(o);}},E={};for(let f of Object.keys(r))Object.defineProperty(E,f,{get:()=>o[f],set:y=>{o[f]=y;},enumerable:true,configurable:true});if(Object.defineProperty(E,"state",{value:o,enumerable:true,configurable:true,writable:true}),Object.assign(E,D),n)for(let f in n){let y=n[f];if(!y)continue;let ne=he(()=>y.call(E,o));Object.defineProperty(E,f,{get:()=>ne.value,enumerable:true,configurable:true});}if(i)for(let f in i){let y=i[f];y&&(E[f]=(...ne)=>{let Xe=y.apply(E,ne);return c.forEach(Ze=>Ze(o)),Xe});}return E}function Ht(e){let t=new e,n=Object.create(null),i={},r={};return Object.getOwnPropertyNames(t).forEach(o=>{n[o]=t[o];}),Object.getOwnPropertyNames(e.prototype).forEach(o=>{let s=Object.getOwnPropertyDescriptor(e.prototype,o);s&&(isFunction(s.get)?i[o]=function(){return s.get.call(this)}:isFunction(s.value)&&o!=="constructor"&&(r[o]=function(...c){return s.value.apply(this,c)}));}),{state:n,getters:i,actions:r}}function Ft(e){return ()=>{let t;return isFunction(e)?t=Ht(e):t=e,Wt(t)}}var qe,Be,te=class extends(Be=P,qe="_IS_REF",Be){constructor(n){super(n,true);this[qe]=true;}get value(){let n=b;return n&&I(this,n),this._value}set value(n){h(n)&&(n=n.peek()),Se(n)&&(n=n.value),hasChanged(this._value,n)&&(this._rawValue=n,this._value=n,this.flag|=16,this.subLink&&Y(this.subLink));}};function Bt(e=void 0){return Se(e)?e:h(e)?new te(e.peek()):new te(e)}function Se(e){return !!e&&!!e._IS_REF}var $e={},Je=new Set;function N(e,t){if(t||(Je.clear(),t=Je),!isObject(e)||t.has(e))return e;if(t.add(e),h(e)||K(e))return N(e.value,t);if(Array.isArray(e))for(let n of e)N(n,t);else isMap(e)?(e.forEach(n=>{N(n,t);}),e.keys(),e.values()):isSet(e)?(e.forEach(n=>{N(n,t);}),e.values()):Object.keys(e).forEach(n=>{N(e[n],t);});return e}function ze(e){return isFunction(e)?e:h(e)||K(e)?()=>e.value:m(e)?()=>N(e):()=>e}function Xt(e){if(Array.isArray(e)){let t=e.map(n=>ze(n));return ()=>t.map(n=>n())}return ze(e)}function Zt(e,t,n={}){let{immediate:i=false,deep:r=false}=n,o=$e,s=Xt(e),c=()=>{let D=u.effect;if(!D.run)return;let E=D.run();(r||isObject(E)||hasChanged(E,o))&&(t(E,o===$e?void 0:o),o=E);},u=Z(()=>{let D=s();return r&&N(D),D},{scheduler:()=>A(c)});return i?c():o=u.effect.run(),()=>{u.stop();}}export{z as EffectScope,T as TriggerOpTypes,J as batch,he as computed,Ft as createStore,Z as effect,Pt as effectScope,Me as endBatch,Vt as getBatchDepth,Gt as getCurrentScope,pe as isBatching,K as isComputed,Mt as isEffect,m as isReactive,Se as isRef,L as isShallow,h as isSignal,Kt as memoEffect,Pe as nextTick,jt as onScopeDispose,A as queueJob,Oe as queuePreFlushCb,C as reactive,Bt as ref,Ot as setCurrentScope,B as shallowReactive,At as shallowSignal,Ct as signal,Ye as startBatch,Yt as stop,a as toRaw,kt as toReactive,S as trigger,rt as untrack,Zt as watch};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@estjs/signals",
|
|
3
|
-
"version": "0.0.16
|
|
3
|
+
"version": "0.0.16",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [],
|
|
@@ -16,29 +16,29 @@
|
|
|
16
16
|
"files": [
|
|
17
17
|
"dist"
|
|
18
18
|
],
|
|
19
|
-
"main": "./dist/signals.
|
|
20
|
-
"module": "./dist/signals.
|
|
19
|
+
"main": "./dist/signals.js",
|
|
20
|
+
"module": "./dist/signals.js",
|
|
21
21
|
"types": "./dist/signals.d.ts",
|
|
22
22
|
"exports": {
|
|
23
23
|
".": {
|
|
24
24
|
"browser": {
|
|
25
25
|
"development": {
|
|
26
26
|
"types": "./dist/signals.d.ts",
|
|
27
|
-
"require": "./dist/signals.dev.cjs
|
|
28
|
-
"import": "./dist/signals.dev.
|
|
27
|
+
"require": "./dist/signals.dev.cjs",
|
|
28
|
+
"import": "./dist/signals.dev.js"
|
|
29
29
|
},
|
|
30
30
|
"types": "./dist/signals.d.ts",
|
|
31
|
-
"require": "./dist/signals.cjs
|
|
32
|
-
"import": "./dist/signals.
|
|
31
|
+
"require": "./dist/signals.cjs",
|
|
32
|
+
"import": "./dist/signals.js"
|
|
33
33
|
},
|
|
34
34
|
"development": {
|
|
35
35
|
"types": "./dist/signals.d.ts",
|
|
36
|
-
"require": "./dist/signals.dev.cjs
|
|
37
|
-
"import": "./dist/signals.dev.
|
|
36
|
+
"require": "./dist/signals.dev.cjs",
|
|
37
|
+
"import": "./dist/signals.dev.js"
|
|
38
38
|
},
|
|
39
39
|
"types": "./dist/signals.d.ts",
|
|
40
|
-
"require": "./dist/signals.cjs
|
|
41
|
-
"import": "./dist/signals.
|
|
40
|
+
"require": "./dist/signals.cjs",
|
|
41
|
+
"import": "./dist/signals.js"
|
|
42
42
|
}
|
|
43
43
|
},
|
|
44
44
|
"typesVersions": {
|
|
@@ -49,10 +49,10 @@
|
|
|
49
49
|
}
|
|
50
50
|
},
|
|
51
51
|
"sideEffects": false,
|
|
52
|
-
"unpkg": "dist/signals.
|
|
53
|
-
"jsdelivr": "dist/signals.
|
|
52
|
+
"unpkg": "dist/signals.js",
|
|
53
|
+
"jsdelivr": "dist/signals.js",
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@estjs/shared": "0.0.16
|
|
55
|
+
"@estjs/shared": "0.0.16"
|
|
56
56
|
},
|
|
57
57
|
"scripts": {
|
|
58
58
|
"build": "tsup && cross-env NODE_ENV=production tsup --clean=false",
|
package/dist/signals.cjs.js
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
'use strict';var shared=require('@estjs/shared');var Ze=Object.defineProperty;var Se=Object.getOwnPropertySymbols;var et=Object.prototype.hasOwnProperty,tt=Object.prototype.propertyIsEnumerable;var Ee=(e,t,n)=>t in e?Ze(e,t,{enumerable:true,configurable:true,writable:true,value:n}):e[t]=n,ge=(e,t)=>{for(var n in t||(t={}))et.call(t,n)&&Ee(e,n,t[n]);if(Se)for(var n of Se(t))tt.call(t,n)&&Ee(e,n,t[n]);return e};var T={SET:"SET",ADD:"ADD",DELETE:"DELETE",CLEAR:"CLEAR"};var P=Symbol(""),g=Symbol(""),N=Symbol(""),ve=Symbol("");var L=Symbol("");var K=0,_,G=false,ie=class{constructor(t,n){this.map=t;this.key=n;this.isDep=true;this.flag=0;}get subLink(){return this._subLink}set subLink(t){this._subLink=t,t===void 0&&this.map.delete(this.key);}};function re(e){var t;(t=e==null?void 0:e.notify)==null||t.call(e);}function D(e,t){if(G)return;let n=t.depLinkTail;if(n&&n.depNode===e)return n;let i=n?n.nextDepLink:t.depLink;if(i&&i.depNode===e)return i.version=K,t.depLinkTail=i,i;let r=e.subLinkTail;if(r&&r.version===K&&r.subNode===t)return t.depLinkTail=r,r;let o={version:K,depNode:e,subNode:t,prevSubLink:r,nextSubLink:void 0,prevDepLink:n,nextDepLink:i};return i&&(i.prevDepLink=o),n?n.nextDepLink=o:t.depLink=o,r?r.nextSubLink=o:e.subLink=o,e.subLinkTail=o,t.depLinkTail=o,o}function R(e,t=e.subNode){let n=e.depNode,i=e.prevSubLink,r=e.nextSubLink,o=e.prevDepLink,s=e.nextDepLink;if(s?s.prevDepLink=o:t.depLinkTail=o,o?o.nextDepLink=s:t.depLink=s,r?r.prevSubLink=i:n.subLinkTail=i,i)i.nextSubLink=r;else if(n.subLink=r,r===void 0){let c=n.depLink;for(;c;)c=R(c,n);n.depLinkTail=void 0,n.isDep||(n.flag|=16);}return s}function U(e,t){let n,i=0,r=false;e:do{let o=false;if(t.flag&16)o=true;else {let s=e.depNode,c=s.flag;if((c&17)===17){let u=s.subLink;u&&u.nextSubLink&&O(u),o=true;}else if((c&33)===33)if(s.depLink){n={link:e,prev:n},e=s.depLink,t=s,++i;continue e}else s.flag&=-33;else c&32&&(s.flag&=-33);}if(!o&&e.nextDepLink!==void 0){e=e.nextDepLink;continue e}for(r=o;i--;){e=n.link,n=n.prev,t=e.subNode;let s=e.depNode;if(r?s.flag=s.flag&-33|16:s.flag&=-33,s.flag&16&&(r=true),!r&&e.nextDepLink!==void 0){e=e.nextDepLink;continue e}}return r?t.flag=t.flag&-33|16:t.flag&=-33,r}while(true)}function O(e){for(;e;){let t=e.subNode,n=t.flag;(n&48)===32&&(t.flag=n|16,(n&6)===2&&re(t)),e=e.nextSubLink;}}function j(e){let t=e.nextSubLink,n;e:do{let i=e.subNode,r=i.flag&2,o=i.flag;if(o&60?o&12?o&4?!(o&48)&&rt(e,i)?(i.flag=o|40,r&&re(i),o&=1):o=0:i.flag=o&-9|32:o=0:(i.flag=o|32,r&&re(i)),o&1){let s=i.subLink;if(s!==void 0){let c=s.nextSubLink;c!==void 0&&(n={value:t,prev:n},t=c),e=s;continue}}if((e=t)!==void 0){t=e.nextSubLink;continue}for(;n!==void 0;)if(e=n.value,n=n.prev,e!==void 0){t=e.nextSubLink;continue e}break}while(true)}function oe(e){let t=_;return _=e,t}function W(e){return K++,e.depLinkTail=void 0,e.flag=e.flag&-57|4,oe(e)}function H(e,t){_=t;let n=e.depLinkTail,i=n?n.nextDepLink:e.depLink;for(;i;)i=R(i,e);e.flag&=-5;}function it(e){let t=oe(void 0),n=G;G=true;try{return e()}finally{G=n,oe(t);}}function rt(e,t){let n=t.depLinkTail;for(;n;){if(n===e)return true;n=n.prevDepLink;}return false}var se=new WeakMap,ot=0;function ne(e,t,n){if(e)for(let i=e.subLink;i;i=i.nextSubLink){let r=i.subNode;r._triggerVersion!==n&&(r._triggerVersion=n,t.push(r));}}function l(e,t){if(!_||G)return;let n=se.get(e);n||(n=new Map,se.set(e,n));let i=n.get(t);i||(i=new ie(n,t),n.set(t,i)),D(i,_);}function S(e,t,n,i){var c;let r=se.get(e);if(!r)return;let o=[],s=++ot;if(n!==void 0)if(Array.isArray(n))for(let u of n)ne(r.get(u),o,s);else ne(r.get(n),o,s);if(t==="ADD"||t==="DELETE"||t==="CLEAR"){let u=Array.isArray(e)?L:ve;ne(r.get(u),o,s);}for(let u of o)u.flag&2?(c=u.notify)==null||c.call(u):u.flag&1&&(u.flag|=16,u.subLink&&j(u.subLink));}var lt=new WeakMap,pt=new WeakMap;function a(e){if(!e||!shared.isObject(e))return e;let t=e._RAW;return t?a(t):h(e)?a(e.peek()):e}var be=dt();function dt(){let e={};return ["includes","indexOf","lastIndexOf"].forEach(t=>{e[t]=function(...n){let i=a(this);l(i,L);let r=i[t](...n);if((r===-1||r===false)&&n.length>0){let o=n.map(s=>a(s));r=i[t](...o);}return r};}),["find","findIndex","findLast","findLastIndex"].forEach(t=>{e[t]=function(...n){let i=a(this),r=y(this);l(i,L);let o=i[t](...n);return (t==="find"||t==="findLast")&&shared.isObject(o)&&!r?d(o):o};}),["push","pop","shift","unshift","splice","sort","reverse","fill","copyWithin"].forEach(t=>{e[t]=function(...n){let i=a(this),r=Array.prototype[t].apply(i,n);return S(i,T.SET,[P,L]),r};}),["toReversed","toSorted","toSpliced"].forEach(t=>{e[t]=function(...n){let i=a(this),r=y(this);if(l(i,L),t==="toSpliced")for(let s=0,c=i.length;s<c;s++)l(i,`${s}`);let o=Array.prototype[t].apply(i,n);return Array.isArray(o)?o.map(s=>shared.isObject(s)?d(s,r):s):o};}),["concat","slice","filter","map","flatMap","flat"].forEach(t=>{e[t]=function(...n){let i=a(this);return l(i,L),Array.prototype[t].apply(this,n)};}),["join","toString","toLocaleString"].forEach(t=>{e[t]=function(...n){let i=a(this);return l(i,L),Array.prototype[t].apply(i,n)};}),["values","keys","entries",Symbol.iterator].forEach(t=>{e[t]=function(){let n=a(this),i=y(this);l(n,P);let r=t===Symbol.iterator?n[Symbol.iterator]():n[t]();return {next(){let{value:o,done:s}=r.next();return s?{value:o,done:s}:Array.isArray(o)?{value:o.map(c=>shared.isObject(c)?d(c,i):c),done:s}:{value:shared.isObject(o)?d(o,i):o,done:s}},[Symbol.iterator](){return this}}};}),e}function Le(e,t){let n=h(t)?t:a(t);return shared.hasChanged(e,n)}var we=e=>({get:(t,n,i)=>{if(n==="_RAW")return t;if(n==="_IS_REACTIVE")return true;if(n==="_IS_SHALLOW")return e;if(shared.hasOwn(be,n))return be[n];let r=Reflect.get(t,n,i);return shared.isStringNumber(n)&&l(t,n),l(t,P),shared.isObject(r)&&!e?d(r):r},set:(t,n,i,r)=>{let o=Reflect.get(t,n,r),s=a(i),c=Reflect.set(t,n,s,r);return Le(s,o)&&(shared.isStringNumber(n)?S(t,T.SET,[n,L,P]):S(t,T.SET,n)),c}}),ht=we(true),Tt=we(false),Re=e=>({get(t,n){return n==="_IS_REACTIVE"?true:n==="_RAW"?t:n==="_IS_SHALLOW"?e:Reflect.get(shared.hasOwn(me,n)?me:t,n,t)}}),xe=e=>({get(t,n){return n==="_IS_REACTIVE"?true:n==="_RAW"?t:n==="_IS_SHALLOW"?e:Reflect.get(shared.hasOwn(ke,n)&&n in t?ke:t,n,t)}}),St=Re(true),Et=Re(false),gt=xe(true),vt=xe(false),me={get(e){let t=a(this);l(t,g);let n=t.get(e);return shared.isUndefined(n)&&!t.has(e)&&b(e)&&(n=t.get(a(e))),shared.isObject(n)&&!y(this)?d(n):n},set(e,t){let n=a(this),i=a(e),r=n.has(i),o=n.get(i),s=a(t);return n.set(i,s),(!r||shared.hasChanged(o,s))&&S(n,T.SET,g),this},add(e){let t=a(this),n=a(e),i=t.has(n);return t.add(n),i||S(t,T.ADD,g),this},has(e){let t=a(this);l(t,g);let n=t.has(e);return !n&&shared.isObject(e)?t.has(a(e)):n},delete(e){let t=a(this),n=t.has(e),i=t.delete(e);return !i&&shared.isObject(e)&&(i=t.delete(a(e))),(n||i)&&S(t,T.DELETE,g),i},clear(){let e=a(this),t=e.size>0,n=e.clear();return t&&S(e,T.CLEAR,g),n},forEach(e,t){let n=a(this),i=y(this);l(n,g),n.forEach((r,o)=>{let s=i||!shared.isObject(r)?r:d(r),c=i||!shared.isObject(o)?o:d(o);e.call(t,s,c,this);});},[Symbol.iterator](){let e=a(this),t=y(this);l(e,g);let n=e[Symbol.iterator]();return {next(){let{value:i,done:r}=n.next();return r?{value:i,done:r}:t?{value:i,done:r}:Array.isArray(i)?{value:i.map(o=>shared.isObject(o)?d(o):o),done:r}:{value:shared.isObject(i)?d(i):i,done:r}},[Symbol.iterator](){return this}}},get size(){let e=a(this);return l(e,g),e.size},keys(){let e=a(this),t=y(this);l(e,g);let n=e.keys();return {next(){let{value:i,done:r}=n.next();return r?{value:i,done:r}:{value:t||!shared.isObject(i)?i:d(i),done:r}},[Symbol.iterator](){return this}}},values(){let e=a(this),t=y(this);l(e,g);let n=e.values();return {next(){let{value:i,done:r}=n.next();return r?{value:i,done:r}:{value:t||!shared.isObject(i)?i:d(i),done:r}},[Symbol.iterator](){return this}}},entries(){let e=a(this),t=y(this);l(e,g);let n=e.entries();return {next(){let{value:i,done:r}=n.next();return r?{value:i,done:r}:t?{value:i,done:r}:{value:i.map(o=>shared.isObject(o)?d(o):o),done:r}},[Symbol.iterator](){return this}}}},ke={get(e){let t=a(this);l(t,N);let n=t.get(e);return shared.isUndefined(n)&&!t.has(e)&&b(e)&&(n=t.get(a(e))),shared.isObject(n)&&!y(this)?d(n):n},set(e,t){let n=a(this),i=a(e),r=n.has(i),o=n.get(i),s=a(t);return n.set(i,s),(!r||shared.hasChanged(o,s))&&S(n,T.SET,N),this},add(e){let t=a(this),n=a(e),i=t.has(n);return t.add(n),i||S(t,T.ADD,N),this},has(e){let t=a(this);l(t,N);let n=t.has(e);return !n&&b(e)&&(n=t.has(a(e))),n},delete(e){let t=a(this),n=a(e),i=t.has(n),r=t.delete(n);return (i||r)&&S(t,T.DELETE,N),r}},De=e=>({get(t,n,i){if(n==="_RAW")return t;if(n==="_IS_REACTIVE")return true;if(n==="_IS_SHALLOW")return e;let r=Reflect.get(t,n,i),o=h(r)?r.value:r;return l(t,n),shared.isObject(o)&&!e?d(o):o},set:(t,n,i,r)=>{let o=Reflect.get(t,n,r),s=a(i),c=Reflect.set(t,n,s,r);return Le(s,o)&&S(t,T.SET,n),c},deleteProperty:(t,n)=>{let i=shared.hasOwn(t,n),r=Reflect.deleteProperty(t,n);return i&&r&&S(t,T.DELETE,n),r}}),_t=De(true),bt=De(false);function d(e,t=false){if(!shared.isObject(e)||b(e))return e;let n=t?pt:lt,i=n.get(e);if(i)return i;let r;shared.isArray(e)?r=t?ht:Tt:shared.isSet(e)||shared.isMap(e)?r=t?St:Et:shared.isWeakMap(e)||shared.isWeakSet(e)?r=t?gt:vt:r=t?_t:bt;let o=new Proxy(e,r);return n.set(e,o),o}function b(e){return !!(e&&e._IS_REACTIVE)}function I(e){return b(e)||h(e)?e:d(e)}function q(e){return b(e)||h(e)?e:d(e,true)}function y(e){return !!(e&&e._IS_SHALLOW)}var mt=e=>shared.isObject(e)?I(e):e;var Ae;Ae="_IS_SIGNAL";var V=class{constructor(t,n=false){this.flag=1;this[Ae]=true;let i=a(t);this._rawValue=i,this._IS_SHALLOW=n,Ce(i)?b(t)?this._value=t:this._value=n?q(i):I(i):this._value=i;}get dep(){return this}get value(){let t=_;if(t&&D(this,t),this.flag&16&&this.shouldUpdate()){let i=this.subLink;i&&O(i);}return this._value}set value(t){h(t)&&(t=t.peek());let n=t,i=a(t);if(!shared.hasChanged(this._rawValue,i))return;if(this._oldValue=this._rawValue,this._rawValue=i,this.flag|=16,!Ce(i))this._value=i;else if(b(n))this._value=n;else {let o=this._IS_SHALLOW;this._value=o?q(i):I(i);}let r=this.subLink;r&&j(r);}shouldUpdate(){if(this.flag&=-17,!("_oldValue"in this))return true;let t=shared.hasChanged(this._oldValue,this._rawValue);return this._oldValue=this._rawValue,t}peek(){return this._value}set(t){this.value=t;}update(t){let n=t(this.peek());h(n)?this.value=n.peek():this.value=n;}};function Ce(e){return shared.isObject(e)?shared.isArray(e)||shared.isMap(e)||shared.isSet(e)||shared.isWeakMap(e)||shared.isWeakSet(e)||shared.isPlainObject(e):false}function It(e){return h(e)?e:new V(e)}function Ct(e){return h(e)&&(e=e.peek()),new V(e,true)}function h(e){return !!e&&!!e._IS_SIGNAL}var B=new Set,ce=new Set,Ne=Promise.resolve(),ue=false;function Ve(e){return e?Ne.then(e):Ne}function C(e){B.add(e),Pe();}function Pe(){ue||(ue=true,Ve(fe));}function Ge(e){ce.add(e),Pe();}function fe(){for(ue=false,At();B.size>0;){for(let e of B)try{e();}catch(t){}B.clear();}}function At(){let e=Array.from(ce);ce.clear();for(let t of e)try{t();}catch(n){}}function Oe(e,t){switch(t){case "sync":return ()=>e();case "pre":return ()=>Ge(e);case "post":return ()=>C(e);default:return ()=>C(e)}}var Y=0;function $(e){je();try{return e()}finally{Ye();}}function je(){Y++;}function Ye(){Y--,Y===0&&fe();}function le(){return Y>0}function Nt(){return Y}var m,J=class{constructor(t=false,n=void 0){this.detached=t;this.parent=n;this._active=true;this.effects=[];this.scopes=[];this.cleanups=[];!t&&m&&(this.parent=m,m.scopes.push(this));}get active(){return this._active}pause(){var t,n;if(this._active){for(let i=0;i<this.scopes.length;i++)this.scopes[i].pause();for(let i=0;i<this.effects.length;i++)(n=(t=this.effects[i]).pause)==null||n.call(t);}}resume(){var t,n;if(this._active){for(let i=0;i<this.scopes.length;i++)this.scopes[i].resume();for(let i=0;i<this.effects.length;i++)(n=(t=this.effects[i]).resume)==null||n.call(t);}}run(t){if(!this._active)return;let n=m;m=this;try{return t()}finally{m=n;}}stop(t=false){if(!this._active)return;this._active=false;for(let i=0;i<this.scopes.length;i++)this.scopes[i].stop(true);this.scopes.length=0;let n=this.effects.slice();this.effects.length=0;for(let i of n)i.stop();for(let i=0;i<this.cleanups.length;i++)this.cleanups[i]();if(this.cleanups.length=0,!t&&this.parent){let i=this.parent.scopes.indexOf(this);i>=0&&this.parent.scopes.splice(i,1);}this.parent=void 0;}_record(t){this.effects.push(t),t.scope=this;}_remove(t){let n=this.effects.indexOf(t);n>=0&&this.effects.splice(n,1);}_pushCleanup(t){this.cleanups.push(t);}};function Vt(e=false){return new J(e)}function Pt(){return m}function Gt(e){let t=m;return m=e,t}function Ot(e,t=false){m&&m._pushCleanup(e);}function z(e,t=m){t&&t.active&&t._record(e);}function Q(e){let t=e.scope;t&&(e.scope=void 0,t._remove(e));}var Ke;Ke="_IS_EFFECT";var pe=class{constructor(t,n){this.flag=18;this[Ke]=true;this._active=true;if(this.fn=t,n){this.options=n;let i=n.flush||n.scheduler;i&&!shared.isFunction(i)&&(this._flushScheduler=Oe(()=>this.run(),i));}z(this);}get active(){return this._active}get dirty(){let t=this.flag;if(t&16)return true;if(t&32){if(this.depLink&&U(this.depLink,this))return this.flag=t&-33|16,true;this.flag=t&-33;}return false}pause(){this.flag|=256;}resume(){let n=this.flag&-257;this.flag=n;let i=(n&16)!==0,r=(n&32)!==0;(i||r)&&this.notify();}run(){if(!this._active)return this.fn();let t=this.flag;this.flag=t&-49|512;let n=W(this);try{return this.fn()}catch(i){throw this.flag|=16,i}finally{this.flag&=-513,H(this,n);}}getJob(){return this._job||(this._job=()=>this.run()),this._job}notify(){var r,o,s;let t=this.flag;if(!this._active||t&784)return;this.flag=t|16;let n=((r=this.options)==null?void 0:r.flush)||((o=this.options)==null?void 0:o.scheduler);n?shared.isFunction(n)?n(this):(s=this._flushScheduler)==null||s.call(this):le()?C(this.getJob()):this.run();}stop(){var i;if(!this._active)return;this._active=false,Q(this);let t=this.depLink;for(;t;)t=R(t,this);let n=this.subLink;for(;n;)n=R(n);this._job=void 0,this._flushScheduler=void 0,this.depLinkTail=void 0,this.subLinkTail=void 0,(i=this.options)!=null&&i.onStop&&this.options.onStop();}};function X(e,t){let n=new pe(e,t);try{n.run();}catch(r){throw n.stop(),r}let i=()=>n.run();return i.effect=n,i.stop=()=>n.stop(),i}function jt(e){e.effect.stop();}function Yt(e){return !!(e&&e._IS_EFFECT)}function Mt(e,t,n){let i=t;return X(()=>{i=e(i);},n)}var w=Symbol("computed-no-value"),He;He="_IS_COMPUTED";var Z=class{constructor(t,n,i,r){this.flag=17;this[He]=true;this._value=w;this._active=true;this.getter=t,this.setter=n,this.onTrack=i,this.onTrigger=r,this.flag|=16,z(this);}get value(){if(!this.active)return this._value===w?this.getter():this._value;_&&D(this,_);let t=this.flag,n=this._value!==w;return n&&!(t&48)?this._value:!n||t&16?(this.recompute(),this._value):(t&32&&(this.depLink&&U(this.depLink,this)?this.recompute():this.flag=t&-33),this._value)}set value(t){this.setter&&this.setter(t);}peek(){return this.active?(this._value===w&&this.recompute(),this._value):this._value===w?this.getter():this._value}get active(){return this._active}recompute(){if(!this._active){this._value===w&&(this._value=this.getter());return}let t=this._value,n=t!==w,i=W(this);try{let r=this.getter(),o=this.flag,s=this.subLink,c=-49;!n||shared.hasChanged(t,r)?(this._value=r,this.flag=o&c,s&&O(s)):this.flag=o&c;}catch(r){let o=-49;throw this.flag&=o,this._value=w,r}finally{H(this,i);}}shouldUpdate(){let t=this._value!==w,n=this._value;return this.recompute(),t?shared.hasChanged(this._value,n):true}stop(){if(!this._active)return;this._active=false,Q(this);let t=this.depLink;for(;t;)t=R(t,this);let n=this.subLink;for(;n;)n=R(n);this.depLinkTail=void 0,this.subLinkTail=void 0,this.flag&=-49;}};function de(e){if(M(e))return e;if(!e)throw new Error("[Computed] Invalid argument: computed() requires a getter function or options object.");if(shared.isFunction(e))return new Z(e);if(shared.isPlainObject(e)){let{get:t,set:n,onTrack:i,onTrigger:r}=e;if(!t)throw new Error(`[Computed] Invalid options: getter function is required.
|
|
2
|
-
Usage: computed({ get: () => value, set: (v) => { ... } })`);if(!shared.isFunction(t))throw new TypeError(`[Computed] Invalid options: getter must be a function.
|
|
3
|
-
Received: ${typeof t}`);return new Z(t,n,i,r)}throw new Error(`[Computed] Invalid argument: expected a function or options object.
|
|
4
|
-
Received: ${typeof e}`)}function M(e){return !!e&&!!e._IS_COMPUTED}function Ut(e){let{state:t,getters:n,actions:i}=e,r=ge({},t),o=I(t),s=new Set,c=new Set,u=f=>{s.forEach(k=>k(f)),c.forEach(k=>k(f));},x={patch$(f){$(()=>{Object.assign(o,f);}),u(o);},subscribe$(f){s.add(f);},unsubscribe$(f){s.delete(f);},onAction$(f){c.add(f);},offAction$(f){c.delete(f);},reset$(){$(()=>{Object.assign(o,r);}),u(o);}},E={};for(let f of Object.keys(r))Object.defineProperty(E,f,{get:()=>o[f],set:k=>{o[f]=k;},enumerable:true,configurable:true});if(Object.defineProperty(E,"state",{value:o,enumerable:true,configurable:true,writable:true}),Object.assign(E,x),n)for(let f in n){let k=n[f];if(!k)continue;let te=de(()=>k.call(E,o));Object.defineProperty(E,f,{get:()=>te.value,enumerable:true,configurable:true});}if(i)for(let f in i){let k=i[f];k&&(E[f]=(...te)=>{let Qe=k.apply(E,te);return c.forEach(Xe=>Xe(o)),Qe});}return E}function Wt(e){let t=new e,n=Object.create(null),i={},r={};return Object.getOwnPropertyNames(t).forEach(o=>{n[o]=t[o];}),Object.getOwnPropertyNames(e.prototype).forEach(o=>{let s=Object.getOwnPropertyDescriptor(e.prototype,o);s&&(shared.isFunction(s.get)?i[o]=function(){return s.get.call(this)}:shared.isFunction(s.value)&&o!=="constructor"&&(r[o]=function(...c){return s.value.apply(this,c)}));}),{state:n,getters:i,actions:r}}function Ht(e){return ()=>{let t;return shared.isFunction(e)?t=Wt(e):t=e,Ut(t)}}var Fe,qe,ee=class extends(qe=V,Fe="_IS_REF",qe){constructor(n){super(n,true);this[Fe]=true;}get value(){let n=_;return n&&D(this,n),this._value}set value(n){h(n)&&(n=n.peek()),Te(n)&&(n=n.value),shared.hasChanged(this._value,n)&&(this._rawValue=n,this._value=n,this.flag|=16,this.subLink&&j(this.subLink));}};function qt(e=void 0){return Te(e)?e:h(e)?new ee(e.peek()):new ee(e)}function Te(e){return !!e&&!!e._IS_REF}var Be={},$e=new Set;function A(e,t){if(t||($e.clear(),t=$e),!shared.isObject(e)||t.has(e))return e;if(t.add(e),h(e)||M(e))return A(e.value,t);if(Array.isArray(e))for(let n of e)A(n,t);else shared.isMap(e)?(e.forEach(n=>{A(n,t);}),e.keys(),e.values()):shared.isSet(e)?(e.forEach(n=>{A(n,t);}),e.values()):Object.keys(e).forEach(n=>{A(e[n],t);});return e}function Je(e){return shared.isFunction(e)?e:h(e)||M(e)?()=>e.value:b(e)?()=>A(e):()=>e}function Qt(e){if(Array.isArray(e)){let t=e.map(n=>Je(n));return ()=>t.map(n=>n())}return Je(e)}function Xt(e,t,n={}){let{immediate:i=false,deep:r=false}=n,o=Be,s=Qt(e),c=()=>{let x=u.effect;if(!x.run)return;let E=x.run();(r||shared.isObject(E)||shared.hasChanged(E,o))&&(t(E,o===Be?void 0:o),o=E);},u=X(()=>{let x=s();return r&&A(x),x},{scheduler:()=>C(c)});return i?c():o=u.effect.run(),()=>{u.stop();}}exports.EffectScope=J;exports.TriggerOpTypes=T;exports.batch=$;exports.computed=de;exports.createStore=Ht;exports.effect=X;exports.effectScope=Vt;exports.endBatch=Ye;exports.getBatchDepth=Nt;exports.getCurrentScope=Pt;exports.isBatching=le;exports.isComputed=M;exports.isEffect=Yt;exports.isReactive=b;exports.isRef=Te;exports.isShallow=y;exports.isSignal=h;exports.memoEffect=Mt;exports.nextTick=Ve;exports.onScopeDispose=Ot;exports.queueJob=C;exports.queuePreFlushCb=Ge;exports.reactive=I;exports.ref=qt;exports.setCurrentScope=Gt;exports.shallowReactive=q;exports.shallowSignal=Ct;exports.signal=It;exports.startBatch=je;exports.stop=jt;exports.toRaw=a;exports.toReactive=mt;exports.trigger=S;exports.untrack=it;exports.watch=Xt;
|
package/dist/signals.esm.js
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import {isObject,isFunction,isPlainObject,hasChanged,isArray,isSet,isMap,isWeakMap,isWeakSet,isStringNumber,hasOwn,isUndefined}from'@estjs/shared';var et=Object.defineProperty;var Ee=Object.getOwnPropertySymbols;var tt=Object.prototype.hasOwnProperty,nt=Object.prototype.propertyIsEnumerable;var ge=(e,t,n)=>t in e?et(e,t,{enumerable:true,configurable:true,writable:true,value:n}):e[t]=n,ve=(e,t)=>{for(var n in t||(t={}))tt.call(t,n)&&ge(e,n,t[n]);if(Ee)for(var n of Ee(t))nt.call(t,n)&&ge(e,n,t[n]);return e};var T={SET:"SET",ADD:"ADD",DELETE:"DELETE",CLEAR:"CLEAR"};var G=Symbol(""),g=Symbol(""),V=Symbol(""),_e=Symbol("");var w=Symbol("");var U=0,b,O=false,re=class{constructor(t,n){this.map=t;this.key=n;this.isDep=true;this.flag=0;}get subLink(){return this._subLink}set subLink(t){this._subLink=t,t===void 0&&this.map.delete(this.key);}};function oe(e){var t;(t=e==null?void 0:e.notify)==null||t.call(e);}function I(e,t){if(O)return;let n=t.depLinkTail;if(n&&n.depNode===e)return n;let i=n?n.nextDepLink:t.depLink;if(i&&i.depNode===e)return i.version=U,t.depLinkTail=i,i;let r=e.subLinkTail;if(r&&r.version===U&&r.subNode===t)return t.depLinkTail=r,r;let o={version:U,depNode:e,subNode:t,prevSubLink:r,nextSubLink:void 0,prevDepLink:n,nextDepLink:i};return i&&(i.prevDepLink=o),n?n.nextDepLink=o:t.depLink=o,r?r.nextSubLink=o:e.subLink=o,e.subLinkTail=o,t.depLinkTail=o,o}function x(e,t=e.subNode){let n=e.depNode,i=e.prevSubLink,r=e.nextSubLink,o=e.prevDepLink,s=e.nextDepLink;if(s?s.prevDepLink=o:t.depLinkTail=o,o?o.nextDepLink=s:t.depLink=s,r?r.prevSubLink=i:n.subLinkTail=i,i)i.nextSubLink=r;else if(n.subLink=r,r===void 0){let c=n.depLink;for(;c;)c=x(c,n);n.depLinkTail=void 0,n.isDep||(n.flag|=16);}return s}function W(e,t){let n,i=0,r=false;e:do{let o=false;if(t.flag&16)o=true;else {let s=e.depNode,c=s.flag;if((c&17)===17){let u=s.subLink;u&&u.nextSubLink&&j(u),o=true;}else if((c&33)===33)if(s.depLink){n={link:e,prev:n},e=s.depLink,t=s,++i;continue e}else s.flag&=-33;else c&32&&(s.flag&=-33);}if(!o&&e.nextDepLink!==void 0){e=e.nextDepLink;continue e}for(r=o;i--;){e=n.link,n=n.prev,t=e.subNode;let s=e.depNode;if(r?s.flag=s.flag&-33|16:s.flag&=-33,s.flag&16&&(r=true),!r&&e.nextDepLink!==void 0){e=e.nextDepLink;continue e}}return r?t.flag=t.flag&-33|16:t.flag&=-33,r}while(true)}function j(e){for(;e;){let t=e.subNode,n=t.flag;(n&48)===32&&(t.flag=n|16,(n&6)===2&&oe(t)),e=e.nextSubLink;}}function Y(e){let t=e.nextSubLink,n;e:do{let i=e.subNode,r=i.flag&2,o=i.flag;if(o&60?o&12?o&4?!(o&48)&&ot(e,i)?(i.flag=o|40,r&&oe(i),o&=1):o=0:i.flag=o&-9|32:o=0:(i.flag=o|32,r&&oe(i)),o&1){let s=i.subLink;if(s!==void 0){let c=s.nextSubLink;c!==void 0&&(n={value:t,prev:n},t=c),e=s;continue}}if((e=t)!==void 0){t=e.nextSubLink;continue}for(;n!==void 0;)if(e=n.value,n=n.prev,e!==void 0){t=e.nextSubLink;continue e}break}while(true)}function se(e){let t=b;return b=e,t}function H(e){return U++,e.depLinkTail=void 0,e.flag=e.flag&-57|4,se(e)}function F(e,t){b=t;let n=e.depLinkTail,i=n?n.nextDepLink:e.depLink;for(;i;)i=x(i,e);e.flag&=-5;}function rt(e){let t=se(void 0),n=O;O=true;try{return e()}finally{O=n,se(t);}}function ot(e,t){let n=t.depLinkTail;for(;n;){if(n===e)return true;n=n.prevDepLink;}return false}var ae=new WeakMap,st=0;function ie(e,t,n){if(e)for(let i=e.subLink;i;i=i.nextSubLink){let r=i.subNode;r._triggerVersion!==n&&(r._triggerVersion=n,t.push(r));}}function l(e,t){if(!b||O)return;let n=ae.get(e);n||(n=new Map,ae.set(e,n));let i=n.get(t);i||(i=new re(n,t),n.set(t,i)),I(i,b);}function S(e,t,n,i){var c;let r=ae.get(e);if(!r)return;let o=[],s=++st;if(n!==void 0)if(Array.isArray(n))for(let u of n)ie(r.get(u),o,s);else ie(r.get(n),o,s);if(t==="ADD"||t==="DELETE"||t==="CLEAR"){let u=Array.isArray(e)?w:_e;ie(r.get(u),o,s);}for(let u of o)u.flag&2?(c=u.notify)==null||c.call(u):u.flag&1&&(u.flag|=16,u.subLink&&Y(u.subLink));}var pt=new WeakMap,dt=new WeakMap;function a(e){if(!e||!isObject(e))return e;let t=e._RAW;return t?a(t):h(e)?a(e.peek()):e}var me=ht();function ht(){let e={};return ["includes","indexOf","lastIndexOf"].forEach(t=>{e[t]=function(...n){let i=a(this);l(i,w);let r=i[t](...n);if((r===-1||r===false)&&n.length>0){let o=n.map(s=>a(s));r=i[t](...o);}return r};}),["find","findIndex","findLast","findLastIndex"].forEach(t=>{e[t]=function(...n){let i=a(this),r=L(this);l(i,w);let o=i[t](...n);return (t==="find"||t==="findLast")&&isObject(o)&&!r?d(o):o};}),["push","pop","shift","unshift","splice","sort","reverse","fill","copyWithin"].forEach(t=>{e[t]=function(...n){let i=a(this),r=Array.prototype[t].apply(i,n);return S(i,T.SET,[G,w]),r};}),["toReversed","toSorted","toSpliced"].forEach(t=>{e[t]=function(...n){let i=a(this),r=L(this);if(l(i,w),t==="toSpliced")for(let s=0,c=i.length;s<c;s++)l(i,`${s}`);let o=Array.prototype[t].apply(i,n);return Array.isArray(o)?o.map(s=>isObject(s)?d(s,r):s):o};}),["concat","slice","filter","map","flatMap","flat"].forEach(t=>{e[t]=function(...n){let i=a(this);return l(i,w),Array.prototype[t].apply(this,n)};}),["join","toString","toLocaleString"].forEach(t=>{e[t]=function(...n){let i=a(this);return l(i,w),Array.prototype[t].apply(i,n)};}),["values","keys","entries",Symbol.iterator].forEach(t=>{e[t]=function(){let n=a(this),i=L(this);l(n,G);let r=t===Symbol.iterator?n[Symbol.iterator]():n[t]();return {next(){let{value:o,done:s}=r.next();return s?{value:o,done:s}:Array.isArray(o)?{value:o.map(c=>isObject(c)?d(c,i):c),done:s}:{value:isObject(o)?d(o,i):o,done:s}},[Symbol.iterator](){return this}}};}),e}function we(e,t){let n=h(t)?t:a(t);return hasChanged(e,n)}var Re=e=>({get:(t,n,i)=>{if(n==="_RAW")return t;if(n==="_IS_REACTIVE")return true;if(n==="_IS_SHALLOW")return e;if(hasOwn(me,n))return me[n];let r=Reflect.get(t,n,i);return isStringNumber(n)&&l(t,n),l(t,G),isObject(r)&&!e?d(r):r},set:(t,n,i,r)=>{let o=Reflect.get(t,n,r),s=a(i),c=Reflect.set(t,n,s,r);return we(s,o)&&(isStringNumber(n)?S(t,T.SET,[n,w,G]):S(t,T.SET,n)),c}}),Tt=Re(true),St=Re(false),xe=e=>({get(t,n){return n==="_IS_REACTIVE"?true:n==="_RAW"?t:n==="_IS_SHALLOW"?e:Reflect.get(hasOwn(ke,n)?ke:t,n,t)}}),De=e=>({get(t,n){return n==="_IS_REACTIVE"?true:n==="_RAW"?t:n==="_IS_SHALLOW"?e:Reflect.get(hasOwn(ye,n)&&n in t?ye:t,n,t)}}),Et=xe(true),gt=xe(false),vt=De(true),_t=De(false),ke={get(e){let t=a(this);l(t,g);let n=t.get(e);return isUndefined(n)&&!t.has(e)&&m(e)&&(n=t.get(a(e))),isObject(n)&&!L(this)?d(n):n},set(e,t){let n=a(this),i=a(e),r=n.has(i),o=n.get(i),s=a(t);return n.set(i,s),(!r||hasChanged(o,s))&&S(n,T.SET,g),this},add(e){let t=a(this),n=a(e),i=t.has(n);return t.add(n),i||S(t,T.ADD,g),this},has(e){let t=a(this);l(t,g);let n=t.has(e);return !n&&isObject(e)?t.has(a(e)):n},delete(e){let t=a(this),n=t.has(e),i=t.delete(e);return !i&&isObject(e)&&(i=t.delete(a(e))),(n||i)&&S(t,T.DELETE,g),i},clear(){let e=a(this),t=e.size>0,n=e.clear();return t&&S(e,T.CLEAR,g),n},forEach(e,t){let n=a(this),i=L(this);l(n,g),n.forEach((r,o)=>{let s=i||!isObject(r)?r:d(r),c=i||!isObject(o)?o:d(o);e.call(t,s,c,this);});},[Symbol.iterator](){let e=a(this),t=L(this);l(e,g);let n=e[Symbol.iterator]();return {next(){let{value:i,done:r}=n.next();return r?{value:i,done:r}:t?{value:i,done:r}:Array.isArray(i)?{value:i.map(o=>isObject(o)?d(o):o),done:r}:{value:isObject(i)?d(i):i,done:r}},[Symbol.iterator](){return this}}},get size(){let e=a(this);return l(e,g),e.size},keys(){let e=a(this),t=L(this);l(e,g);let n=e.keys();return {next(){let{value:i,done:r}=n.next();return r?{value:i,done:r}:{value:t||!isObject(i)?i:d(i),done:r}},[Symbol.iterator](){return this}}},values(){let e=a(this),t=L(this);l(e,g);let n=e.values();return {next(){let{value:i,done:r}=n.next();return r?{value:i,done:r}:{value:t||!isObject(i)?i:d(i),done:r}},[Symbol.iterator](){return this}}},entries(){let e=a(this),t=L(this);l(e,g);let n=e.entries();return {next(){let{value:i,done:r}=n.next();return r?{value:i,done:r}:t?{value:i,done:r}:{value:i.map(o=>isObject(o)?d(o):o),done:r}},[Symbol.iterator](){return this}}}},ye={get(e){let t=a(this);l(t,V);let n=t.get(e);return isUndefined(n)&&!t.has(e)&&m(e)&&(n=t.get(a(e))),isObject(n)&&!L(this)?d(n):n},set(e,t){let n=a(this),i=a(e),r=n.has(i),o=n.get(i),s=a(t);return n.set(i,s),(!r||hasChanged(o,s))&&S(n,T.SET,V),this},add(e){let t=a(this),n=a(e),i=t.has(n);return t.add(n),i||S(t,T.ADD,V),this},has(e){let t=a(this);l(t,V);let n=t.has(e);return !n&&m(e)&&(n=t.has(a(e))),n},delete(e){let t=a(this),n=a(e),i=t.has(n),r=t.delete(n);return (i||r)&&S(t,T.DELETE,V),r}},Ie=e=>({get(t,n,i){if(n==="_RAW")return t;if(n==="_IS_REACTIVE")return true;if(n==="_IS_SHALLOW")return e;let r=Reflect.get(t,n,i),o=h(r)?r.value:r;return l(t,n),isObject(o)&&!e?d(o):o},set:(t,n,i,r)=>{let o=Reflect.get(t,n,r),s=a(i),c=Reflect.set(t,n,s,r);return we(s,o)&&S(t,T.SET,n),c},deleteProperty:(t,n)=>{let i=hasOwn(t,n),r=Reflect.deleteProperty(t,n);return i&&r&&S(t,T.DELETE,n),r}}),bt=Ie(true),mt=Ie(false);function d(e,t=false){if(!isObject(e)||m(e))return e;let n=t?dt:pt,i=n.get(e);if(i)return i;let r;isArray(e)?r=t?Tt:St:isSet(e)||isMap(e)?r=t?Et:gt:isWeakMap(e)||isWeakSet(e)?r=t?vt:_t:r=t?bt:mt;let o=new Proxy(e,r);return n.set(e,o),o}function m(e){return !!(e&&e._IS_REACTIVE)}function C(e){return m(e)||h(e)?e:d(e)}function B(e){return m(e)||h(e)?e:d(e,true)}function L(e){return !!(e&&e._IS_SHALLOW)}var kt=e=>isObject(e)?C(e):e;var Ne;Ne="_IS_SIGNAL";var P=class{constructor(t,n=false){this.flag=1;this[Ne]=true;let i=a(t);this._rawValue=i,this._IS_SHALLOW=n,Ae(i)?m(t)?this._value=t:this._value=n?B(i):C(i):this._value=i;}get dep(){return this}get value(){let t=b;if(t&&I(this,t),this.flag&16&&this.shouldUpdate()){let i=this.subLink;i&&j(i);}return this._value}set value(t){h(t)&&(t=t.peek());let n=t,i=a(t);if(!hasChanged(this._rawValue,i))return;if(this._oldValue=this._rawValue,this._rawValue=i,this.flag|=16,!Ae(i))this._value=i;else if(m(n))this._value=n;else {let o=this._IS_SHALLOW;this._value=o?B(i):C(i);}let r=this.subLink;r&&Y(r);}shouldUpdate(){if(this.flag&=-17,!("_oldValue"in this))return true;let t=hasChanged(this._oldValue,this._rawValue);return this._oldValue=this._rawValue,t}peek(){return this._value}set(t){this.value=t;}update(t){let n=t(this.peek());h(n)?this.value=n.peek():this.value=n;}};function Ae(e){return isObject(e)?isArray(e)||isMap(e)||isSet(e)||isWeakMap(e)||isWeakSet(e)||isPlainObject(e):false}function Ct(e){return h(e)?e:new P(e)}function At(e){return h(e)&&(e=e.peek()),new P(e,true)}function h(e){return !!e&&!!e._IS_SIGNAL}var $=new Set,ue=new Set,Ve=Promise.resolve(),fe=false;function Pe(e){return e?Ve.then(e):Ve}function A(e){$.add(e),Ge();}function Ge(){fe||(fe=true,Pe(le));}function Oe(e){ue.add(e),Ge();}function le(){for(fe=false,Nt();$.size>0;){for(let e of $)try{e();}catch(t){}$.clear();}}function Nt(){let e=Array.from(ue);ue.clear();for(let t of e)try{t();}catch(n){}}function je(e,t){switch(t){case "sync":return ()=>e();case "pre":return ()=>Oe(e);case "post":return ()=>A(e);default:return ()=>A(e)}}var M=0;function J(e){Ye();try{return e()}finally{Me();}}function Ye(){M++;}function Me(){M--,M===0&&le();}function pe(){return M>0}function Vt(){return M}var k,z=class{constructor(t=false,n=void 0){this.detached=t;this.parent=n;this._active=true;this.effects=[];this.scopes=[];this.cleanups=[];!t&&k&&(this.parent=k,k.scopes.push(this));}get active(){return this._active}pause(){var t,n;if(this._active){for(let i=0;i<this.scopes.length;i++)this.scopes[i].pause();for(let i=0;i<this.effects.length;i++)(n=(t=this.effects[i]).pause)==null||n.call(t);}}resume(){var t,n;if(this._active){for(let i=0;i<this.scopes.length;i++)this.scopes[i].resume();for(let i=0;i<this.effects.length;i++)(n=(t=this.effects[i]).resume)==null||n.call(t);}}run(t){if(!this._active)return;let n=k;k=this;try{return t()}finally{k=n;}}stop(t=false){if(!this._active)return;this._active=false;for(let i=0;i<this.scopes.length;i++)this.scopes[i].stop(true);this.scopes.length=0;let n=this.effects.slice();this.effects.length=0;for(let i of n)i.stop();for(let i=0;i<this.cleanups.length;i++)this.cleanups[i]();if(this.cleanups.length=0,!t&&this.parent){let i=this.parent.scopes.indexOf(this);i>=0&&this.parent.scopes.splice(i,1);}this.parent=void 0;}_record(t){this.effects.push(t),t.scope=this;}_remove(t){let n=this.effects.indexOf(t);n>=0&&this.effects.splice(n,1);}_pushCleanup(t){this.cleanups.push(t);}};function Pt(e=false){return new z(e)}function Gt(){return k}function Ot(e){let t=k;return k=e,t}function jt(e,t=false){k&&k._pushCleanup(e);}function Q(e,t=k){t&&t.active&&t._record(e);}function X(e){let t=e.scope;t&&(e.scope=void 0,t._remove(e));}var Ue;Ue="_IS_EFFECT";var de=class{constructor(t,n){this.flag=18;this[Ue]=true;this._active=true;if(this.fn=t,n){this.options=n;let i=n.flush||n.scheduler;i&&!isFunction(i)&&(this._flushScheduler=je(()=>this.run(),i));}Q(this);}get active(){return this._active}get dirty(){let t=this.flag;if(t&16)return true;if(t&32){if(this.depLink&&W(this.depLink,this))return this.flag=t&-33|16,true;this.flag=t&-33;}return false}pause(){this.flag|=256;}resume(){let n=this.flag&-257;this.flag=n;let i=(n&16)!==0,r=(n&32)!==0;(i||r)&&this.notify();}run(){if(!this._active)return this.fn();let t=this.flag;this.flag=t&-49|512;let n=H(this);try{return this.fn()}catch(i){throw this.flag|=16,i}finally{this.flag&=-513,F(this,n);}}getJob(){return this._job||(this._job=()=>this.run()),this._job}notify(){var r,o,s;let t=this.flag;if(!this._active||t&784)return;this.flag=t|16;let n=((r=this.options)==null?void 0:r.flush)||((o=this.options)==null?void 0:o.scheduler);n?isFunction(n)?n(this):(s=this._flushScheduler)==null||s.call(this):pe()?A(this.getJob()):this.run();}stop(){var i;if(!this._active)return;this._active=false,X(this);let t=this.depLink;for(;t;)t=x(t,this);let n=this.subLink;for(;n;)n=x(n);this._job=void 0,this._flushScheduler=void 0,this.depLinkTail=void 0,this.subLinkTail=void 0,(i=this.options)!=null&&i.onStop&&this.options.onStop();}};function Z(e,t){let n=new de(e,t);try{n.run();}catch(r){throw n.stop(),r}let i=()=>n.run();return i.effect=n,i.stop=()=>n.stop(),i}function Yt(e){e.effect.stop();}function Mt(e){return !!(e&&e._IS_EFFECT)}function Kt(e,t,n){let i=t;return Z(()=>{i=e(i);},n)}var R=Symbol("computed-no-value"),Fe;Fe="_IS_COMPUTED";var ee=class{constructor(t,n,i,r){this.flag=17;this[Fe]=true;this._value=R;this._active=true;this.getter=t,this.setter=n,this.onTrack=i,this.onTrigger=r,this.flag|=16,Q(this);}get value(){if(!this.active)return this._value===R?this.getter():this._value;b&&I(this,b);let t=this.flag,n=this._value!==R;return n&&!(t&48)?this._value:!n||t&16?(this.recompute(),this._value):(t&32&&(this.depLink&&W(this.depLink,this)?this.recompute():this.flag=t&-33),this._value)}set value(t){this.setter&&this.setter(t);}peek(){return this.active?(this._value===R&&this.recompute(),this._value):this._value===R?this.getter():this._value}get active(){return this._active}recompute(){if(!this._active){this._value===R&&(this._value=this.getter());return}let t=this._value,n=t!==R,i=H(this);try{let r=this.getter(),o=this.flag,s=this.subLink,c=-49;!n||hasChanged(t,r)?(this._value=r,this.flag=o&c,s&&j(s)):this.flag=o&c;}catch(r){let o=-49;throw this.flag&=o,this._value=R,r}finally{F(this,i);}}shouldUpdate(){let t=this._value!==R,n=this._value;return this.recompute(),t?hasChanged(this._value,n):true}stop(){if(!this._active)return;this._active=false,X(this);let t=this.depLink;for(;t;)t=x(t,this);let n=this.subLink;for(;n;)n=x(n);this.depLinkTail=void 0,this.subLinkTail=void 0,this.flag&=-49;}};function he(e){if(K(e))return e;if(!e)throw new Error("[Computed] Invalid argument: computed() requires a getter function or options object.");if(isFunction(e))return new ee(e);if(isPlainObject(e)){let{get:t,set:n,onTrack:i,onTrigger:r}=e;if(!t)throw new Error(`[Computed] Invalid options: getter function is required.
|
|
2
|
-
Usage: computed({ get: () => value, set: (v) => { ... } })`);if(!isFunction(t))throw new TypeError(`[Computed] Invalid options: getter must be a function.
|
|
3
|
-
Received: ${typeof t}`);return new ee(t,n,i,r)}throw new Error(`[Computed] Invalid argument: expected a function or options object.
|
|
4
|
-
Received: ${typeof e}`)}function K(e){return !!e&&!!e._IS_COMPUTED}function Wt(e){let{state:t,getters:n,actions:i}=e,r=ve({},t),o=C(t),s=new Set,c=new Set,u=f=>{s.forEach(y=>y(f)),c.forEach(y=>y(f));},D={patch$(f){J(()=>{Object.assign(o,f);}),u(o);},subscribe$(f){s.add(f);},unsubscribe$(f){s.delete(f);},onAction$(f){c.add(f);},offAction$(f){c.delete(f);},reset$(){J(()=>{Object.assign(o,r);}),u(o);}},E={};for(let f of Object.keys(r))Object.defineProperty(E,f,{get:()=>o[f],set:y=>{o[f]=y;},enumerable:true,configurable:true});if(Object.defineProperty(E,"state",{value:o,enumerable:true,configurable:true,writable:true}),Object.assign(E,D),n)for(let f in n){let y=n[f];if(!y)continue;let ne=he(()=>y.call(E,o));Object.defineProperty(E,f,{get:()=>ne.value,enumerable:true,configurable:true});}if(i)for(let f in i){let y=i[f];y&&(E[f]=(...ne)=>{let Xe=y.apply(E,ne);return c.forEach(Ze=>Ze(o)),Xe});}return E}function Ht(e){let t=new e,n=Object.create(null),i={},r={};return Object.getOwnPropertyNames(t).forEach(o=>{n[o]=t[o];}),Object.getOwnPropertyNames(e.prototype).forEach(o=>{let s=Object.getOwnPropertyDescriptor(e.prototype,o);s&&(isFunction(s.get)?i[o]=function(){return s.get.call(this)}:isFunction(s.value)&&o!=="constructor"&&(r[o]=function(...c){return s.value.apply(this,c)}));}),{state:n,getters:i,actions:r}}function Ft(e){return ()=>{let t;return isFunction(e)?t=Ht(e):t=e,Wt(t)}}var qe,Be,te=class extends(Be=P,qe="_IS_REF",Be){constructor(n){super(n,true);this[qe]=true;}get value(){let n=b;return n&&I(this,n),this._value}set value(n){h(n)&&(n=n.peek()),Se(n)&&(n=n.value),hasChanged(this._value,n)&&(this._rawValue=n,this._value=n,this.flag|=16,this.subLink&&Y(this.subLink));}};function Bt(e=void 0){return Se(e)?e:h(e)?new te(e.peek()):new te(e)}function Se(e){return !!e&&!!e._IS_REF}var $e={},Je=new Set;function N(e,t){if(t||(Je.clear(),t=Je),!isObject(e)||t.has(e))return e;if(t.add(e),h(e)||K(e))return N(e.value,t);if(Array.isArray(e))for(let n of e)N(n,t);else isMap(e)?(e.forEach(n=>{N(n,t);}),e.keys(),e.values()):isSet(e)?(e.forEach(n=>{N(n,t);}),e.values()):Object.keys(e).forEach(n=>{N(e[n],t);});return e}function ze(e){return isFunction(e)?e:h(e)||K(e)?()=>e.value:m(e)?()=>N(e):()=>e}function Xt(e){if(Array.isArray(e)){let t=e.map(n=>ze(n));return ()=>t.map(n=>n())}return ze(e)}function Zt(e,t,n={}){let{immediate:i=false,deep:r=false}=n,o=$e,s=Xt(e),c=()=>{let D=u.effect;if(!D.run)return;let E=D.run();(r||isObject(E)||hasChanged(E,o))&&(t(E,o===$e?void 0:o),o=E);},u=Z(()=>{let D=s();return r&&N(D),D},{scheduler:()=>A(c)});return i?c():o=u.effect.run(),()=>{u.stop();}}export{z as EffectScope,T as TriggerOpTypes,J as batch,he as computed,Ft as createStore,Z as effect,Pt as effectScope,Me as endBatch,Vt as getBatchDepth,Gt as getCurrentScope,pe as isBatching,K as isComputed,Mt as isEffect,m as isReactive,Se as isRef,L as isShallow,h as isSignal,Kt as memoEffect,Pe as nextTick,jt as onScopeDispose,A as queueJob,Oe as queuePreFlushCb,C as reactive,Bt as ref,Ot as setCurrentScope,B as shallowReactive,At as shallowSignal,Ct as signal,Ye as startBatch,Yt as stop,a as toRaw,kt as toReactive,S as trigger,rt as untrack,Zt as watch};
|