@fluixi/reactive 1.0.0-alpha.82 → 1.0.0-alpha.84
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/README.md +4 -0
- package/dist/cdn/reactive.cjs +2673 -1
- package/dist/cdn/reactive.global.js +2 -1
- package/dist/cdn/reactive.mjs +2657 -1
- package/dist/cdn/signal.cjs +299 -1
- package/dist/cdn/signal.d.ts +1 -1
- package/dist/cdn/signal.global.js +2 -1
- package/dist/cdn/signal.js +1 -1
- package/dist/cdn/signal.mjs +276 -1
- package/dist/index.cjs +2673 -1
- package/dist/index.mjs +2657 -1
- package/dist/lib/index.cjs +2674 -1
- package/dist/lib/index.js +1 -1
- package/dist/lib/index.mjs +2659 -1
- package/dist/lib/observable/index.cjs +386 -1
- package/dist/lib/observable/index.mjs +364 -1
- package/dist/lib/observable/observable.cjs +384 -1
- package/dist/lib/observable/observable.d.ts +0 -137
- package/dist/lib/observable/observable.d.ts.map +1 -1
- package/dist/lib/observable/observable.js +0 -71
- package/dist/lib/observable/observable.mjs +361 -1
- package/dist/lib/observable/subscription.cjs +180 -1
- package/dist/lib/observable/subscription.d.ts +0 -12
- package/dist/lib/observable/subscription.d.ts.map +1 -1
- package/dist/lib/observable/subscription.js +0 -12
- package/dist/lib/observable/subscription.mjs +157 -1
- package/dist/lib/observable/types.cjs +18 -1
- package/dist/lib/observable/types.d.ts.map +1 -1
- package/dist/lib/predicates.cjs +44 -1
- package/dist/lib/predicates.d.ts +2 -2
- package/dist/lib/predicates.js +2 -2
- package/dist/lib/predicates.mjs +23 -1
- package/dist/lib/signal/api.cjs +571 -1
- package/dist/lib/signal/api.d.ts +211 -1
- package/dist/lib/signal/api.d.ts.map +1 -1
- package/dist/lib/signal/api.js +207 -12
- package/dist/lib/signal/api.mjs +548 -1
- package/dist/lib/signal/cached-resource.cjs +672 -1
- package/dist/lib/signal/cached-resource.d.ts +28 -16
- package/dist/lib/signal/cached-resource.d.ts.map +1 -1
- package/dist/lib/signal/cached-resource.js +35 -29
- package/dist/lib/signal/cached-resource.mjs +650 -1
- package/dist/lib/signal/graph/children.cjs +325 -1
- package/dist/lib/signal/graph/children.js +1 -1
- package/dist/lib/signal/graph/children.mjs +302 -1
- package/dist/lib/signal/graph/compat.cjs +578 -1
- package/dist/lib/signal/graph/compat.d.ts +13 -13
- package/dist/lib/signal/graph/compat.d.ts.map +1 -1
- package/dist/lib/signal/graph/compat.js +51 -32
- package/dist/lib/signal/graph/compat.mjs +556 -1
- package/dist/lib/signal/graph/core.cjs +295 -1
- package/dist/lib/signal/graph/core.d.ts +28 -24
- package/dist/lib/signal/graph/core.d.ts.map +1 -1
- package/dist/lib/signal/graph/core.js +45 -31
- package/dist/lib/signal/graph/core.mjs +273 -1
- package/dist/lib/signal/graph/debounced.cjs +668 -1
- package/dist/lib/signal/graph/debounced.d.ts +5 -5
- package/dist/lib/signal/graph/debounced.d.ts.map +1 -1
- package/dist/lib/signal/graph/debounced.js +5 -5
- package/dist/lib/signal/graph/debounced.mjs +645 -1
- package/dist/lib/signal/graph/derived.cjs +496 -1
- package/dist/lib/signal/graph/derived.d.ts +1 -1
- package/dist/lib/signal/graph/derived.js +1 -1
- package/dist/lib/signal/graph/derived.mjs +473 -1
- package/dist/lib/signal/graph/detect.cjs +66 -1
- package/dist/lib/signal/graph/detect.mjs +45 -1
- package/dist/lib/signal/graph/error-boundary.cjs +301 -1
- package/dist/lib/signal/graph/error-boundary.js +3 -3
- package/dist/lib/signal/graph/error-boundary.mjs +278 -1
- package/dist/lib/signal/graph/index.cjs +305 -1
- package/dist/lib/signal/graph/index.d.ts +7 -6
- package/dist/lib/signal/graph/index.d.ts.map +1 -1
- package/dist/lib/signal/graph/index.js +7 -6
- package/dist/lib/signal/graph/index.mjs +283 -1
- package/dist/lib/signal/graph/observe.cjs +163 -0
- package/dist/lib/signal/graph/observe.d.ts +141 -0
- package/dist/lib/signal/graph/observe.d.ts.map +1 -0
- package/dist/lib/signal/graph/observe.js +149 -0
- package/dist/lib/signal/graph/observe.mjs +140 -0
- package/dist/lib/signal/graph/resource.cjs +620 -1
- package/dist/lib/signal/graph/resource.d.ts +1 -1
- package/dist/lib/signal/graph/resource.js +7 -8
- package/dist/lib/signal/graph/resource.mjs +597 -1
- package/dist/lib/signal/graph/runtime.cjs +501 -1
- package/dist/lib/signal/graph/runtime.d.ts +9 -9
- package/dist/lib/signal/graph/runtime.d.ts.map +1 -1
- package/dist/lib/signal/graph/runtime.js +56 -37
- package/dist/lib/signal/graph/runtime.mjs +478 -1
- package/dist/lib/signal/graph/signal-next.cjs +1208 -1
- package/dist/lib/signal/graph/signal-next.d.ts +5 -5
- package/dist/lib/signal/graph/signal-next.d.ts.map +1 -1
- package/dist/lib/signal/graph/signal-next.js +14 -12
- package/dist/lib/signal/graph/signal-next.mjs +1186 -1
- package/dist/lib/signal/graph/ssr-hooks.cjs +60 -1
- package/dist/lib/signal/graph/ssr-hooks.d.ts +6 -7
- package/dist/lib/signal/graph/ssr-hooks.d.ts.map +1 -1
- package/dist/lib/signal/graph/ssr-hooks.js +6 -7
- package/dist/lib/signal/graph/ssr-hooks.mjs +39 -1
- package/dist/lib/signal/graph/state.cjs +72 -1
- package/dist/lib/signal/graph/state.d.ts +43 -10
- package/dist/lib/signal/graph/state.d.ts.map +1 -1
- package/dist/lib/signal/graph/state.js +83 -21
- package/dist/lib/signal/graph/state.mjs +49 -1
- package/dist/lib/signal/graph/suspense.cjs +301 -1
- package/dist/lib/signal/graph/suspense.js +4 -4
- package/dist/lib/signal/graph/suspense.mjs +278 -1
- package/dist/lib/signal/index-legacy.cjs +2540 -1
- package/dist/lib/signal/index-legacy.d.ts +1 -1
- package/dist/lib/signal/index-legacy.js +1 -1
- package/dist/lib/signal/index-legacy.mjs +2518 -1
- package/dist/lib/signal/index.cjs +1275 -1
- package/dist/lib/signal/index.d.ts +5 -2
- package/dist/lib/signal/index.d.ts.map +1 -1
- package/dist/lib/signal/index.js +8 -3
- package/dist/lib/signal/index.mjs +1253 -1
- package/dist/lib/signal/list.cjs +549 -1
- package/dist/lib/signal/list.d.ts +5 -5
- package/dist/lib/signal/list.js +10 -10
- package/dist/lib/signal/list.mjs +526 -1
- package/dist/lib/signal/resource-api.cjs +626 -1
- package/dist/lib/signal/resource-api.d.ts +5 -5
- package/dist/lib/signal/resource-api.js +5 -5
- package/dist/lib/signal/resource-api.mjs +603 -1
- package/dist/lib/signal/signal.cjs +2023 -1
- package/dist/lib/signal/signal.d.ts +4 -4
- package/dist/lib/signal/signal.d.ts.map +1 -1
- package/dist/lib/signal/signal.js +22 -23
- package/dist/lib/signal/signal.mjs +2000 -1
- package/dist/lib/signal/types.cjs +38 -1
- package/dist/lib/signal/types.d.ts.map +1 -1
- package/dist/lib/signal/types.js +2 -2
- package/dist/lib/signal/types.mjs +17 -1
- package/dist/lib/signal/utilities.cjs +1012 -1
- package/dist/lib/signal/utilities.d.ts +0 -108
- package/dist/lib/signal/utilities.d.ts.map +1 -1
- package/dist/lib/signal/utilities.js +0 -158
- package/dist/lib/signal/utilities.mjs +990 -1
- package/dist/lib/store/api.cjs +612 -1
- package/dist/lib/store/api.d.ts +33 -0
- package/dist/lib/store/api.d.ts.map +1 -1
- package/dist/lib/store/api.js +41 -8
- package/dist/lib/store/api.mjs +596 -1
- package/dist/lib/store/index.cjs +691 -1
- package/dist/lib/store/index.js +1 -1
- package/dist/lib/store/index.mjs +676 -1
- package/dist/lib/store/setter.types.cjs +18 -1
- package/dist/lib/store/setter.types.d.ts +43 -3
- package/dist/lib/store/setter.types.d.ts.map +1 -1
- package/dist/lib/store/store.cjs +658 -1
- package/dist/lib/store/store.d.ts +72 -0
- package/dist/lib/store/store.d.ts.map +1 -1
- package/dist/lib/store/store.js +294 -11
- package/dist/lib/store/store.mjs +644 -1
- package/dist/lib/store/types.cjs +18 -1
- package/dist/lib/store/types.d.ts +1 -1
- package/dist/lib/store/types.d.ts.map +1 -1
- package/dist/lib/store/utils.cjs +43 -1
- package/dist/lib/store/utils.d.ts +1 -1
- package/dist/lib/store/utils.js +1 -1
- package/dist/lib/store/utils.mjs +22 -1
- package/dist/lib/subject.cjs +450 -1
- package/dist/lib/subject.js +3 -91
- package/dist/lib/subject.mjs +427 -1
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/dist/version.generated.cjs +27 -1
- package/dist/version.generated.d.ts +1 -1
- package/dist/version.generated.js +2 -2
- package/dist/version.generated.mjs +7 -1
- package/package.json +5 -4
|
@@ -1 +1,2000 @@
|
|
|
1
|
-
function de(e){return typeof e=="function"&&!/^class\s/.test(Function.prototype.toString.call(e))}function Me(e){return e==null||Array.isArray(e)||typeof e=="function"||e instanceof Date||e instanceof RegExp||e instanceof Map||e instanceof Set||e instanceof Error?!1:typeof e=="object"}function $(e){return e instanceof Promise||!!e&&(typeof e=="object"||typeof e=="function")&&"then"in e}var W=class e{constructor(n){this._closed=!1;this._parentOrParents=null;this._subscriptions=null;n&&(this._subscriptions=[n])}get closed(){return this._closed}unsubscribe(){if(this._closed)return;this._closed=!0;let{_parentOrParents:n,_subscriptions:t}=this;if(n instanceof e)n.remove(this);else if(n!==null)for(let o of n)o.remove(this);if(t){for(let o of t)if(de(o)&&!(o instanceof e))try{o()}catch(r){console.error("Error in unsubscribe function:",r)}else if(Me(o)&&typeof o.unsubscribe=="function")try{o.unsubscribe()}catch(r){console.error("Error unsubscribing child:",r)}this._subscriptions=null}}add(n){if(!n||n===this)return this;if(n.closed)return this;let{_closed:t,_subscriptions:o}=this;if(t){if(de(n))try{n()}catch(r){console.error("Error in unsubscribe function:",r)}else if(n.unsubscribe)try{n.unsubscribe()}catch(r){console.error("Error unsubscribing:",r)}return this}return o||(this._subscriptions=[]),this._subscriptions.push(n),n instanceof e&&n._addParent(this),this}remove(n){let{_subscriptions:t}=this;if(!t)return;let o=t.indexOf(n);o!==-1&&(t.splice(o,1),n._removeParent(this))}_addParent(n){let{_parentOrParents:t}=this;t?Array.isArray(t)?t.push(n):this._parentOrParents=[t,n]:this._parentOrParents=n}_removeParent(n){let{_parentOrParents:t}=this;if(t===n)this._parentOrParents=null;else if(Array.isArray(t)){let o=t.indexOf(n);o!==-1&&(t.splice(o,1),t.length===1&&(this._parentOrParents=t[0]))}}};var Z=class extends W{constructor(t,o,r){super();this.isStopped=!1;let s;t?typeof t=="object"?s=t:s={next:t,error:o,complete:r}:s={},this.destination=s}next(t){if(!this.isStopped&&this.destination.next)try{this.destination.next(t)}catch(o){this.error(o)}}error(t){if(!this.isStopped){if(this.isStopped=!0,this.destination.error)try{this.destination.error(t)}catch(o){throw o}else throw t;this.unsubscribe()}}complete(){if(!this.isStopped){if(this.isStopped=!0,this.destination.complete)try{this.destination.complete()}catch(t){this.error(t);return}this.unsubscribe()}}unsubscribe(){this.closed||(this.isStopped=!0,super.unsubscribe())}},pe=class extends Z{constructor(t,o,r,s){super(t,o,r);this._isUnsubscribing=!1;this._parentSubscriber=null;this._parentSubscriber=s||null}next(t){if(!this.isStopped&&!this._isUnsubscribing)try{super.next(t)}catch(o){this.error(o)}}error(t){if(!this.isStopped&&!this._isUnsubscribing){this._isUnsubscribing=!0;try{super.error(t)}finally{this._isUnsubscribing=!1}}}complete(){if(!this.isStopped&&!this._isUnsubscribing){this._isUnsubscribing=!0;try{super.complete()}finally{this._isUnsubscribing=!1}}}unsubscribe(){this.closed||(this._isUnsubscribing=!0,super.unsubscribe(),this._isUnsubscribing=!1)}};var z=class extends W{constructor(n){if(super(),n)this._subscribe=n;else throw new TypeError("Observable constructor requires a subscribe function")}subscribe(n,t,o){let r;n instanceof Z?r=n:r=new pe(n,t,o);let{_subscribe:s}=this;try{let l=s.call(this,r);l&&(typeof l=="function"||typeof l.unsubscribe=="function")&&r.add(l)}catch(l){r.error(l)}return r}pipe(...n){return n.length===0?this:n.reduce((t,o)=>o(t),this)}toPromise(){return new Promise((n,t)=>{let o;this.subscribe({next:r=>o=r,error:t,complete:()=>n(o)})})}};var vn=typeof window>"u"?!1:window.__FLUIXI_PROD__===!0,ee=typeof process>"u"?vn:!1,Tn=Symbol.for("signal"),bn=Symbol.for("memo"),yn=Symbol.for("resource");function ne(e){return typeof e=="function"&&e[Tn]===!0}function mn(e){return typeof e=="function"&&e[bn]===!0}function wn(e){return typeof e=="function"&&e[yn]===!0}function xn(e){return typeof e=="function"&&e[Symbol.for("fluixi-component")]===!0}function gn(e){return typeof e=="function"&&e[Symbol.for("fluixi-suspense")]===!0}function Sn(e){return typeof e=="function"&&e[Symbol.for("fluixi-provider")]===!0}function Le(e){return Array.isArray(e)?e.length===2&&e[1]===" "?Array.isArray(e[0])?Le(e[0]):(typeof e[0]=="function",e[0]):e.length===1&&typeof e[0]=="function"?e[0]:e:e}var On="__fluixi_signal_next_state__",Cn=e=>{typeof queueMicrotask=="function"?queueMicrotask(e):Promise.resolve().then(e)},a=globalThis[On]??={consumer:null,untracked:!1,owner:null,queue:[],scheduled:!1,flushing:!1,batchDepth:0,hostSchedule:Cn,onSuspend:null,onError:null};var Be=0,je=1,H=2,te=class{constructor(){this.observers=null;this.watchers=null;this.version=0}updateIfNecessary(){}track(){if(a.untracked)return;let n=a.consumer;n&&((this.observers??=new Set).add(n),(n.sources??=new Set).add(this))}},re=class extends te{constructor(n,t){super(),this._value=n,this._equals=t?.equals===!1?()=>!1:t?.equals??Object.is}get(){return this.track(),this._value}set(n){if(!this._equals(this._value,n)){if(this._value=n,this.version++,this.observers)for(let t of[...this.observers])t.markDirty(H);he(this)}}peek(){return this._value}},j=class extends te{constructor(t,o){super();this._threw=!1;this._initialized=!1;this.state=H;this.sources=null;this._fn=t,this._equals=o?.equals===!1?()=>!1:o?.equals??Object.is}get(){if(a.consumer===this)throw new Error("Signal.Computed cannot read itself");if(this.track(),this.updateIfNecessary(),this._threw)throw this._error;return this._value}updateIfNecessary(){if(this.state===je&&this.sources){for(let t of this.sources)if(t.updateIfNecessary(),this.state===H)break}(this.state===H||!this._initialized)&&this.recompute(),this.state=Be}recompute(){if(this.sources){for(let f of this.sources)f.observers?.delete(this);this.sources.clear()}let t=a.consumer,o=a.untracked;a.consumer=this,a.untracked=!1;let r,s=!1,l;try{r=this._fn()}catch(f){s=!0,l=f,r=this._value}finally{a.consumer=t,a.untracked=o}let c=!this._initialized||this._threw!==s||(s?l!==this._error:!this._equals(this._value,r));if(this._initialized=!0,this._threw=s,this._error=l,this._value=r,c){if(this.version++,this.observers)for(let f of[...this.observers])f.markDirty(H);he(this)}}markDirty(t){if(this.state>=t)return;let o=this.state===Be;if(this.state=t,o){if(this.observers)for(let r of[...this.observers])r.markDirty(je);he(this)}}peek(){if(this.updateIfNecessary(),this._threw)throw this._error;return this._value}};function he(e){if(e.watchers)for(let n of[...e.watchers])n._notify(e)}var oe=class{constructor(n){this._watched=new Set;this._pending=new Set;this._notifyFn=n}watch(...n){for(let t of n)this._watched.add(t),(t.watchers??=new Set).add(this)}unwatch(...n){for(let t of n)this._watched.delete(t),t.watchers?.delete(this),this._pending.delete(t)}getPending(){let n=[...this._pending];return this._pending.clear(),n}_notify(n){if(!this._watched.has(n)||this._pending.has(n))return;let t=this._pending.size===0;this._pending.add(n),t&&this._notifyFn()}};function _n(e){return{cleanups:null,owned:null,parent:e,contexts:null}}function Ge(e){return a.onSuspend?(a.onSuspend(e,a.owner),!0):!1}function be(){return a.owner}function se(e,n){let t=a.owner;a.owner=e;try{return n()}finally{a.owner=t}}function ye(e){if(a.owner){if(a.owner.disposed){e();return}(a.owner.cleanups??=[]).push(e)}}function ve(e,n=!0){if(!e.disposed){if(e.owned){for(let t=e.owned.length-1;t>=0;t--)ve(e.owned[t]);e.owned=null}if(e.cleanups){for(let t=e.cleanups.length-1;t>=0;t--)e.cleanups[t]();e.cleanups=null}n&&(e.disposed=!0)}}function Ve(e){a.hostSchedule=e??(n=>{Promise.resolve().then(n)})}function Rn(e){e.queued||(e.queued=!0,a.queue.push(e),!a.scheduled&&a.batchDepth===0&&(a.scheduled=!0,a.hostSchedule(me)))}function me(){if(a.scheduled=!1,a.flushing)return;a.flushing=!0;let e=0;try{for(;a.queue.length;){if(++e>1e5)throw new Error("[fluixi] effect flush did not settle (cycle?)");let n=a.queue;a.queue=[];for(let t of n)t.queued=!1,t.disposed||t.run()}}finally{a.flushing=!1}}function $e(){a.batchDepth===0&&me()}var Te=class{constructor(n){this.queued=!1;this.disposed=!1;this.owner=_n(a.owner),a.owner&&(a.owner.cleanups??=[]).push(()=>this.dispose()),this.computed=new j(()=>{ve(this.owner,!1),se(this.owner,()=>{let t=n();typeof t=="function"&&(this.owner.cleanups??=[]).push(t)})}),this.watcher=new oe(()=>Rn(this)),this.run(),this.watcher.watch(this.computed)}run(){if(!this.disposed){this.watcher.getPending();try{this.computed.get()}catch(n){if(n&&typeof n.then=="function"&&a.onSuspend){a.onSuspend(n,this.owner);return}if(a.onError&&a.onError(n,this.owner))return;throw n}}}dispose(){this.disposed||(this.disposed=!0,this.watcher.unwatch(this.computed),ve(this.owner))}};function We(e){let n=new Te(e);return()=>n.dispose()}function An(e){return!!e&&typeof e.then=="function"}Ve(()=>{});var ze=Symbol.for("signal"),Fn=Symbol.for("memo"),En=Symbol.for("signal-node");function we(e,n){let t=new re(e,{equals:n?.equals}),o=(()=>t.get()),r=(s=>{let l=typeof s=="function"?s(t.peek()):s;return t.set(l),$e(),l});return Object.defineProperty(o,ze,{value:!0,enumerable:!0}),Object.defineProperty(o,En,{value:{get value(){return t.peek()},get version(){return t.version}},enumerable:!1}),[o,r]}function ie(e,n,t){let o=n,r=be(),s=new j(()=>se(r,()=>{try{return o=e(o)}catch(c){if(An(c))return Ge(c),o;throw c}}),{equals:t?.equals}),l=(()=>s.get());return Object.defineProperty(l,ze,{value:!0,enumerable:!0}),Object.defineProperty(l,Fn,{value:!0,enumerable:!0}),l}function xe(e,n){let t=n;return We(()=>{t=e(t)})}function He(e,n=(t,o)=>t===o){let t=new Map;return xe(()=>{let o=e();for(let[r,s]of t){let[l,c]=s,f=n(r,o);l()!==f&&c(f)}}),o=>{let r=t.get(o);if(!r){let[s,l]=we(!1);r=[s,l],t.set(o,r);let c=e();l(n(o,c))}return r[0]()}}function Pn(e,n){let[t,o]=we(e(),n);return xe(()=>{let r=e();n?.timeoutMs?setTimeout(()=>o(()=>r),n.timeoutMs):typeof requestIdleCallback=="function"?requestIdleCallback(()=>o(()=>r)):Promise.resolve().then(()=>o(()=>r))}),t}function kn(e,n){let t,o=(...r)=>{t!==void 0&&clearTimeout(t),t=setTimeout(()=>{t=void 0,e(...r)},n)};return ye(()=>{t!==void 0&&clearTimeout(t)}),o}function ue(e){if(typeof e=="function"&&!e.length){let n=e();return ne(n)?n:ue(n)}if(Array.isArray(e)){let n=[];for(let t=0;t<e.length;t++){let o=ue(e[t]);Array.isArray(o)?n.push.apply(n,o):n.push(o)}return n}return e}function Ye(e){let n=ie(e);return ee?ie(()=>ue(n()),void 0,{name:"children"}):ie(()=>ue(n()))}var ge=null;function Dn(e){ge=e}function Ke(e){ge&&ge(e)}var Se=null;function qn(e){Se=e}function Xe(e){return Se?Se(e):void 0}var Oe=null;function Un(e){Oe=e}function Je(){return Oe?Oe():void 0}var Ce=null;function Nn(e){Ce=e}function Qe(e,n){Ce&&Ce(e,n)}var Pe=Symbol.for("signal"),In=Symbol.for("memo"),Mn=Symbol.for("resource"),Ze=Symbol("fluixi-proxy"),tn=Symbol.for("signal-node"),A=0,Y=1,E=2,F=3,u=null,d=null,i=null,ae=null,le=0,Ln=!1,_e=!1,G=0,Bn=1e6,m=new WeakMap,g=null;var jn=null,Gn=new Map,Vn=0,Re={context:null,owner:null,routeData:new Map,matchedRoute:new Map};function Bt(e){u=e,Re.owner=e,Re.context=e}function jt(){return Re}function $n(){return`node_${++Vn}_${Date.now()}`}function Wn(e){ee&&Gn.set(e.id,new WeakRef(e))}function rn(e,n,t){let o={id:$n(),type:e,value:n,version:0,equals:t?.equals,name:t?.name,created:Date.now(),updated:Date.now()};return Wn(o),o}function on(e,n){return e===n}function ke(e){throw typeof console<"u"&&console.error("Reactive error:",e),e}var Ae=null,Fe=null;function sn(){if(!Ae){let[e,n]=M(!1);Ae=e,Fe=n}}function un(e){if(i)i.indexOf(e)===-1&&i.push(e);else if(g&&g.running&&!e.pure)g.effects.indexOf(e)===-1&&g.effects.push(e);else if(!e.pure||e.computed)J(e);else if(e.pure&&!e.computed&&e.accessor){let n=d,t=i;d=null,i=[],e.accessor(),d=n;let o=i;if(i=t,o.length>0){let r=i;ce(o),i=r}}}function en(e,n){for(let t=0;t<e.length;t++)n(e[t])}function M(e,n){let t=e;typeof t=="object"&&t&&Ze in t&&delete t[Ze];let o=rn("signal",t,{equals:n?.equals===!1?void 0:n?.equals,name:n?.name}),r=[l,c];m.set(r,new Set);let s;function l(){let f=d;if(f){f.sources?f.sources.indexOf(r)===-1&&f.sources.push(r):f.sources=[r];let p=m.get(r);p&&!p.has(f)&&p.add(f)}return t}function c(f){let p=typeof f=="function"?f(t):f,b=o.equals||on;if(n?.equals===!1||!b(t,p)){t=p,o.value=p,o.version++,o.updated=Date.now();let k=m.get(r);if(k&&k.size>0){let D=function(h,v=!1){let q=h.state;if(!(q===F&&h===d)){if(v&&!h.pure){q===A&&(h.state=Y,Ln&&(i!==null&&i.indexOf(h)===-1?i.push(h):C.push(h)));return}if(!w.has(h)&&(w.add(h),h.state=E,q===A||q===Y?C.push(h):!h.pure&&i!==null&&i.indexOf(h)===-1&&i.push(h),h.pure&&h.accessor)){let O=m.get(h.accessor);O&&en(Array.from(O),_=>D(_,!0))}}};var x=D;let S=Array.from(k),C=[],w=new Set;en(S,D);for(let h of C)un(h)}}}return l.toObservable=()=>new z(f=>{let p=!0;return X(()=>{let x=l();p?p=!1:f.next(x)})}),Object.defineProperty(l,Pe,{value:!0,enumerable:!0}),Object.defineProperty(l,tn,{value:o,enumerable:!1}),r}function X(e,n,t){let o={fn:e,state:E,sources:null,sourceSlots:null,owned:null,cleanups:null,owner:u,contexts:null,pure:!1,updatedAt:null};u&&(u.owned?u.owned.push(o):u.owned=[o]);let r=T&&P(T);return r&&(o.suspense=r),De(o,n),()=>N(o)}function De(e,n){if(e.sources){for(let r of e.sources){let s=m.get(r);s&&s.delete(e)}e.sources=null,e.sourceSlots=null}if(e.owned){for(let r=0;r<e.owned.length;r++)N(e.owned[r]);e.owned=null}let t=d,o=u;if(d=e,u=e,le++,le>Bn)throw le=0,d=t,u=o,new Error("Potential infinite loop detected. Exceeded maximum iterations.");try{e.state=F;let r=e.fn(n);typeof r=="function"&&(e.cleanups?e.cleanups.push(r):e.cleanups=[r]),e.state===F&&(e.state=A)}catch(r){if($(r)){let s=T&&P(T);s&&(s.increment(),r.finally(()=>s.decrement()),e.suspense&&s.effects.push(e));return}ke(r)}finally{d=t,u=o}}function J(e){if(!(e.disposed||!e.fn||e.state===A)&&(e.state===E||e.state===Y||e.state===F)){if(e.cleanups){for(let n=0;n<e.cleanups.length;n++)e.cleanups[n]();e.cleanups=null}if(e.owned){for(let n=0;n<e.owned.length;n++)N(e.owned[n]);e.owned=null}e.renderEffect?fn(e):De(e,e.value)}}function N(e){if(e.disposed=!0,e.sources)for(let n of e.sources){let t=m.get(n);t&&t.delete(e)}if(e.cleanups)for(let n=0;n<e.cleanups.length;n++)e.cleanups[n]();if(e.owned)for(let n=0;n<e.owned.length;n++)N(e.owned[n]);if(e.owner&&e.owner.owned){let n=e.owner.owned.indexOf(e);n!==-1&&e.owner.owned.splice(n,1)}}function zn(e,n,t){let o=rn("memo",n,{equals:t?.equals===!1?void 0:t?.equals,name:t?.name}),r={fn:e,state:E,sources:null,sourceSlots:null,value:n,owned:null,cleanups:null,owner:u,contexts:null,pure:!0,updatedAt:null,node:o,accessor:void 0};u&&(u.owned?u.owned.push(r):u.owned=[r]);let s=()=>{if(d&&d!==r){d.sources?d.sources.indexOf(s)===-1&&d.sources.push(s):d.sources=[s];let c=s;m.has(c)||m.set(c,new Set);let f=m.get(c);f&&f.add(d)}if(r.state!==A){if(r.sources){for(let p of r.sources){let b=m.get(p);b&&b.delete(r)}r.sources=null,r.sourceSlots=null}if(r.cleanups){for(let p=0;p<r.cleanups.length;p++)r.cleanups[p]();r.cleanups=null}if(r.owned){for(let p=0;p<r.owned.length;p++)N(r.owned[p]);r.owned=null}let c=d,f=u;d=r,u=r,r.state=F;try{let p=r.fn(r.value),b=o.equals||on;if(t?.equals===!1||!b(r.value,p)){r.value=p,o.value=p,o.version++,o.updated=Date.now();let k=s,S=m.get(k);if(S&&S.size>0){let h=function(v,q=!1){if(v===r)return;let O=v.state;if(O!==F){if(q&&!v.pure){O===A&&(v.state=Y,i!==null&&i.indexOf(v)===-1?i.push(v):w.push(v));return}if(!D.has(v)&&(D.add(v),v.state=E,O===A||O===Y?w.push(v):!v.pure&&i!==null&&i.indexOf(v)===-1&&i.push(v),v.pure&&v.accessor)){let _=m.get(v.accessor);if(_&&_.size>0)for(let V of Array.from(_))h(V,!0)}}};var l=h;let C=Array.from(S),w=[],D=new Set;for(let v=0;v<C.length;v++)h(C[v]);for(let v of w)un(v)}}r.state===F&&(r.state=A)}catch(p){if($(p)){let b=T&&P(T);if(!b&&T){let x=f;for(;x;){if(x.contexts?.has(T.id)){b=x.contexts.get(T.id);break}x=x.owner}}return b&&(b.increment(),p.finally(()=>b.decrement())),r.value}ke(p)}finally{d=c,u=f}}return r.value};return r.accessor=s,m.set(s,new Set),s.toObservable=()=>new z(l=>{let c=!0;return X(()=>{let p=s();c?c=!1:l.next(p)})}),Object.defineProperty(s,Pe,{value:!0,enumerable:!0}),Object.defineProperty(s,In,{value:!0,enumerable:!0}),Object.defineProperty(s,tn,{value:o,enumerable:!1}),s}function ce(e){let n=[],t=[];for(let r of e)r.pure&&!r.computed&&r.accessor?n.indexOf(r)===-1&&n.push(r):(r.computed||!r.pure)&&t.indexOf(r)===-1&&t.push(r);i=[];let o=0;for(;o<n.length;){let r=n[o++],s=m.get(r.accessor);if(s&&s.size>0){let c=d;d=null,r.accessor(),d=c}let l=i.splice(0);for(let c of l)c.pure&&!c.computed&&c.accessor?n.indexOf(c)===-1&&n.push(c):(c.computed||!c.pure)&&t.indexOf(c)===-1&&t.push(c)}i=null;for(let r of t)(r.computed||!r.pure)&&J(r)}function R(e){if(i&&G>0)return e();if(i&&G===0){let n=i,t=[];i=t,G++;let o;try{o=e()}finally{G--,i=n}let r=i;return ce(t),i=r,o}G++,i=[],ae=[];try{return e()}finally{G--,an()}}function an(){if(!_e){_e=!0,le=0;try{for(;i&&i.length>0;){let e=i;i=null,ce(e)}if(i=null,ae){let e=ae;ae=null;for(let n=0;n<e.length;n++)J(e[n])}}finally{_e=!1}}}function Hn(e){let n={owned:null,cleanups:null,contexts:null,owner:u},t=d;d=null;let o=u;u=n;try{return e(()=>{if(n.owned)for(let r=0;r<n.owned.length;r++)N(n.owned[r]);if(n.cleanups)for(let r=0;r<n.cleanups.length;r++)n.cleanups[r]()})}finally{u=o,d=t}}function K(e){let n=d;d=null;try{return e()}finally{d=n}}function Ee(e){u&&(u.cleanups?u.cleanups.push(e):u.cleanups=[e])}function Yn(e,n,t={}){let o,r;typeof n=="function"?(o=typeof e=="function"?e:()=>e,r=n):(o=()=>!0,r=e,n&&typeof n=="object"&&(t=n));let{initialValue:s,name:l}=t,c=t.transport===!1?void 0:Je(),f=c!==void 0?Xe(c):void 0,p=f!==void 0,[b,x]=M(f!==void 0?f.value:t.initialValue,{equals:!1}),[k,S]=M(void 0,{equals:!1}),[C,w]=M(f!==void 0||t.initialValue!==void 0?"ready":"unresolved",{equals:!1}),[D,h]=M(void 0,{equals:!1}),[v,q]=M(void 0,{equals:!1}),O=Symbol(),_=O,V=!1,dn=y=>{if(!(typeof localStorage>"u"))try{y&&localStorage.setItem("storage",JSON.stringify({data:y,timestamp:Date.now()}))}catch(L){console.error(`Failed to save resource to cache (${l}):`,L)}},pn=X(()=>{let y=o?o():e;if(v(),y===!1||y===null||y===void 0){_=O,R(()=>{w("unresolved"),h(void 0),S(void 0)});return}let L=V;if(V=!1,_!==O&&y===_&&!L)return;if(_=y,p){p=!1;return}let B=!1;Ee(()=>B=!0);let Ne=K(C),hn=K(b),Ie=Ne==="ready"||Ne==="refreshing";R(()=>{w(Ie?"refreshing":"pending"),S(void 0)});try{let U=r(y,{value:hn,refetching:Ie});if($(U)){h(U),Ke(U),U.then(I=>{B||(c!==void 0&&Qe(c,I),R(()=>{x(()=>I),dn(I),w("ready"),h(void 0)}))},I=>{B||R(()=>{S(I),w("errored"),h(void 0)})}).catch(I=>{B||R(()=>{S(I),w("errored"),h(void 0)})});let fe=T&&P(T);fe&&(fe.increment(),U.finally(()=>fe.decrement()))}else{if(B)return;R(()=>{x(()=>U),w("ready"),h(void 0)})}}catch(U){if(B)return;R(()=>{S(U),w("errored"),h(void 0)})}});Ee(pn);let Ue=()=>{let y=C();return y==="pending"||y==="refreshing"},Q=(()=>{let y=k();if(y)throw y;if(Ue()){let L=D();if(L)throw L}return b()});return Object.defineProperty(Q,Mn,{value:!0,enumerable:!0}),Object.defineProperty(Q,Pe,{value:!0,enumerable:!0}),Object.defineProperties(Q,{state:{get:C},loading:{get:()=>Ue()},error:{get:k},latest:{get:b}}),[Q,{mutate:x,refetch:()=>{V=!0,q(void 0)}}]}function Kn(){return u}function Xn(e,n){let t=u,o=d;u=e,d=null;try{return n()}finally{u=t,d=o}}function qe(e){let n=Symbol("context"),t=Jn(n);return{id:n,Provider:t,defaultValue:e}}function Jn(e){return n=>{let t=u;for(;t;)t.contexts||(t.contexts=new Map),t.contexts.has(e)||t.contexts.set(e,n.value),t=t.owner;let o;return cn(()=>{o=K(()=>{let r=u;return r&&(r.contexts||(r.contexts=new Map),r.contexts.set(e,n.value)),Ye(()=>n.children)})}),o}}function P(e){let n=u;for(;n;){if(n.contexts&&n.contexts.has(e.id))return n.contexts.get(e.id);n=n.owner}if(e)return e.defaultValue}function Qn(){return new Promise(e=>{queueMicrotask(()=>{an(),e()})})}function ln(e){if(g&&g.running)return e(),g.done;sn();let n,t=new Promise(r=>n=r),o={running:!0,effects:[],resolve:n,done:t};g=o;try{e()}finally{o.running=!1}return o.effects.length?(Fe(!0),Promise.resolve().then(()=>{let r=o.effects.splice(0);g=null,Fe(!1),r.length&&R(()=>{for(let s of r)s.state=E,J(s)}),n()}),t):(g=null,n(),t)}function Zn(){return sn(),[Ae,ln]}function et(e,n,t){let o=t?.defer??!1,r=!0;return s=>{let l=e();return o&&r?(r=!1,s):K(()=>n(l,s))}}function cn(e,n,t){let o={fn:e,state:E,sources:null,sourceSlots:null,value:n,owned:null,cleanups:null,owner:u,contexts:null,pure:!1,updatedAt:null,renderEffect:!0};u&&(u.owned?u.owned.push(o):u.owned=[o]);let r=T&&P(T);return r&&(o.suspense=r),fn(o),()=>N(o)}function fn(e){if(e.sources){for(let r of e.sources){let s=m.get(r);s&&s.delete(e)}e.sources=null,e.sourceSlots=null}if(e.cleanups){for(let r=0;r<e.cleanups.length;r++)e.cleanups[r]();e.cleanups=null}if(e.owned){for(let r=0;r<e.owned.length;r++)N(e.owned[r]);e.owned=null}let n=d,t=u,o=i;d=e,u=e,i===null&&(i=[]),e.state=F;try{let r=e.fn(e.value);typeof r=="function"&&(e.cleanups||(e.cleanups=[]),e.cleanups.push(r)),e.value=r,e.state===F&&(e.state=A)}catch(r){if($(r)){let s=T&&P(T);s&&(s.increment(),r.finally(()=>s.decrement()),e.suspense&&s.effects.push(e));return}ke(r)}finally{d=n,u=t;let r=i;if(i=o,r!==o&&r&&r.length>0){let s=i;ce(r),i=s}}}function nt(e,n,t){let o={fn:e,state:E,sources:null,sourceSlots:null,value:n,owned:null,cleanups:null,owner:u,contexts:null,pure:!0,computed:!0,updatedAt:null};u&&(u.owned?u.owned.push(o):u.owned=[o]),g&&g.running?(i||(i=[]),i.indexOf(o)===-1&&i.push(o)):i?i.indexOf(o)===-1&&i.push(o):De(o,n)}var T;function tt(){return T||(T=qe())}var nn;function rt(){return nn||(nn=qe())}function ot(e){if(!e.length)return;let n=e.slice();e.length=0;for(let t of n)t.state=E,J(t)}function st(e){let n=T&&P(T);n&&n.inFallback()?X(()=>{n.inFallback()||e()}):e()}function it(e){jn=e}function ut(e){let n=T&&P(T);return n&&(n.increment(),e.finally(()=>n.decrement())),e}var Vt={createSignal:M,createEffect:X,createMemo:zn,createComputed:nt,createRoot:Hn,createSelector:He,createResource:Yn,batch:R,untrack:K,onCleanup:Ee,getOwner:Kn,runWithOwner:Xn,createContext:qe,useContext:P,flush:Qn,startTransition:ln,useTransition:Zn,isSignal:ne,on:et,createRenderEffect:cn,getSuspenseContext:tt,getSuspenseListContext:rt,resumeEffects:ot,onResolve:st,setScheduler:it,trackPromise:ut};export{In as $MEMO,Ze as $PROXY,Mn as $RESOURCE,Pe as $SIGNAL,ee as __DEV__,R as batch,nt as createComputed,qe as createContext,kn as createDebounce,Pn as createDeferred,X as createEffect,zn as createMemo,Jn as createProvider,cn as createRenderEffect,Yn as createResource,Hn as createRoot,He as createSelector,M as createSignal,Vt as default,Qn as flush,Kn as getOwner,Xe as getServerData,jt as getSharedConfig,tt as getSuspenseContext,rt as getSuspenseListContext,xn as isComponent,mn as isMemo,Sn as isProvider,wn as isResource,ne as isSignal,gn as isSuspense,Le as makeArrayFlat,Je as nextResourceId,et as on,Ee as onCleanup,st as onResolve,Ye as readChildren,Qe as reportResourceData,ot as resumeEffects,Xn as runWithOwner,Bt as setOwner,Nn as setResourceDataSink,Un as setResourceIdSource,Dn as setResourceTracker,it as setScheduler,qn as setServerDataGetter,Re as sharedConfig,ln as startTransition,ut as trackPromise,Ke as trackResourcePromise,K as untrack,P as useContext,Zn as useTransition};
|
|
1
|
+
// src/lib/predicates.ts
|
|
2
|
+
function isFunction(value) {
|
|
3
|
+
return typeof value === "function" && !/^class\s/.test(Function.prototype.toString.call(value));
|
|
4
|
+
}
|
|
5
|
+
function isObject(value) {
|
|
6
|
+
if (value == null) return false;
|
|
7
|
+
if (Array.isArray(value)) return false;
|
|
8
|
+
if (typeof value === "function") return false;
|
|
9
|
+
if (value instanceof Date) return false;
|
|
10
|
+
if (value instanceof RegExp) return false;
|
|
11
|
+
if (value instanceof Map) return false;
|
|
12
|
+
if (value instanceof Set) return false;
|
|
13
|
+
if (value instanceof Error) return false;
|
|
14
|
+
return typeof value === "object";
|
|
15
|
+
}
|
|
16
|
+
function isPromise(value) {
|
|
17
|
+
return value instanceof Promise || !!value && (typeof value === "object" || typeof value === "function") && "then" in value;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// src/lib/observable/subscription.ts
|
|
21
|
+
var Subscription = class _Subscription {
|
|
22
|
+
/**
|
|
23
|
+
* Creates a new Subscription.
|
|
24
|
+
*/
|
|
25
|
+
constructor(unsubscribe) {
|
|
26
|
+
/** @private */
|
|
27
|
+
this._closed = false;
|
|
28
|
+
/** @private */
|
|
29
|
+
this._parentOrParents = null;
|
|
30
|
+
/** @private */
|
|
31
|
+
this._subscriptions = null;
|
|
32
|
+
if (unsubscribe) {
|
|
33
|
+
this._subscriptions = [unsubscribe];
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Whether the subscription is closed.
|
|
38
|
+
*/
|
|
39
|
+
get closed() {
|
|
40
|
+
return this._closed;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Disposes the resources held by the subscription.
|
|
44
|
+
* May be called multiple times (idempotent).
|
|
45
|
+
*/
|
|
46
|
+
unsubscribe() {
|
|
47
|
+
if (this._closed) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
this._closed = true;
|
|
51
|
+
const { _parentOrParents, _subscriptions } = this;
|
|
52
|
+
if (_parentOrParents instanceof _Subscription) {
|
|
53
|
+
_parentOrParents.remove(this);
|
|
54
|
+
} else if (_parentOrParents !== null) {
|
|
55
|
+
for (const parent of _parentOrParents) {
|
|
56
|
+
parent.remove(this);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (_subscriptions) {
|
|
60
|
+
for (const sub of _subscriptions) {
|
|
61
|
+
if (isFunction(sub) && !(sub instanceof _Subscription)) {
|
|
62
|
+
try {
|
|
63
|
+
sub();
|
|
64
|
+
} catch (error) {
|
|
65
|
+
console.error("Error in unsubscribe function:", error);
|
|
66
|
+
}
|
|
67
|
+
} else if (isObject(sub) && typeof sub.unsubscribe === "function") {
|
|
68
|
+
try {
|
|
69
|
+
sub.unsubscribe();
|
|
70
|
+
} catch (error) {
|
|
71
|
+
console.error("Error unsubscribing child:", error);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
this._subscriptions = null;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Adds a child subscription or cleanup function to this subscription.
|
|
80
|
+
* When this subscription is unsubscribed, all added subscriptions/functions will be unsubscribed/called.
|
|
81
|
+
*
|
|
82
|
+
* @throws {TypeError} If the argument is not a subscription-like object or function
|
|
83
|
+
*/
|
|
84
|
+
add(subscription) {
|
|
85
|
+
if (!subscription || subscription === this) {
|
|
86
|
+
return this;
|
|
87
|
+
}
|
|
88
|
+
if (subscription.closed) {
|
|
89
|
+
return this;
|
|
90
|
+
}
|
|
91
|
+
let { _closed, _subscriptions } = this;
|
|
92
|
+
if (_closed) {
|
|
93
|
+
if (isFunction(subscription)) {
|
|
94
|
+
try {
|
|
95
|
+
subscription();
|
|
96
|
+
} catch (error) {
|
|
97
|
+
console.error("Error in unsubscribe function:", error);
|
|
98
|
+
}
|
|
99
|
+
} else if (subscription.unsubscribe) {
|
|
100
|
+
try {
|
|
101
|
+
subscription.unsubscribe();
|
|
102
|
+
} catch (error) {
|
|
103
|
+
console.error("Error unsubscribing:", error);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return this;
|
|
107
|
+
}
|
|
108
|
+
if (!_subscriptions) {
|
|
109
|
+
this._subscriptions = [];
|
|
110
|
+
}
|
|
111
|
+
this._subscriptions.push(subscription);
|
|
112
|
+
if (subscription instanceof _Subscription) {
|
|
113
|
+
subscription._addParent(this);
|
|
114
|
+
}
|
|
115
|
+
return this;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Removes a child subscription from this subscription.
|
|
119
|
+
*/
|
|
120
|
+
remove(subscription) {
|
|
121
|
+
const { _subscriptions } = this;
|
|
122
|
+
if (!_subscriptions) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
const index = _subscriptions.indexOf(subscription);
|
|
126
|
+
if (index !== -1) {
|
|
127
|
+
_subscriptions.splice(index, 1);
|
|
128
|
+
subscription._removeParent(this);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
/** @private */
|
|
132
|
+
_addParent(parent) {
|
|
133
|
+
const { _parentOrParents } = this;
|
|
134
|
+
if (!_parentOrParents) {
|
|
135
|
+
this._parentOrParents = parent;
|
|
136
|
+
} else if (Array.isArray(_parentOrParents)) {
|
|
137
|
+
_parentOrParents.push(parent);
|
|
138
|
+
} else {
|
|
139
|
+
this._parentOrParents = [_parentOrParents, parent];
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
/** @private */
|
|
143
|
+
_removeParent(parent) {
|
|
144
|
+
const { _parentOrParents } = this;
|
|
145
|
+
if (_parentOrParents === parent) {
|
|
146
|
+
this._parentOrParents = null;
|
|
147
|
+
} else if (Array.isArray(_parentOrParents)) {
|
|
148
|
+
const index = _parentOrParents.indexOf(parent);
|
|
149
|
+
if (index !== -1) {
|
|
150
|
+
_parentOrParents.splice(index, 1);
|
|
151
|
+
if (_parentOrParents.length === 1) {
|
|
152
|
+
this._parentOrParents = _parentOrParents[0];
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
// src/lib/observable/observable.ts
|
|
160
|
+
var Subscriber = class extends Subscription {
|
|
161
|
+
/**
|
|
162
|
+
* Creates a new Subscriber.
|
|
163
|
+
*/
|
|
164
|
+
constructor(destinationOrNext, error, complete) {
|
|
165
|
+
super();
|
|
166
|
+
/** @private */
|
|
167
|
+
this.isStopped = false;
|
|
168
|
+
let observer;
|
|
169
|
+
if (!destinationOrNext) {
|
|
170
|
+
observer = {};
|
|
171
|
+
} else if (typeof destinationOrNext === "object") {
|
|
172
|
+
observer = destinationOrNext;
|
|
173
|
+
} else {
|
|
174
|
+
observer = {
|
|
175
|
+
next: destinationOrNext,
|
|
176
|
+
error,
|
|
177
|
+
complete
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
this.destination = observer;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Sends the next value to the observer.
|
|
184
|
+
*/
|
|
185
|
+
next(value) {
|
|
186
|
+
if (!this.isStopped && this.destination.next) {
|
|
187
|
+
try {
|
|
188
|
+
this.destination.next(value);
|
|
189
|
+
} catch (error) {
|
|
190
|
+
this.error(error);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Sends an error notification to the observer.
|
|
196
|
+
*/
|
|
197
|
+
error(err) {
|
|
198
|
+
if (!this.isStopped) {
|
|
199
|
+
this.isStopped = true;
|
|
200
|
+
if (this.destination.error) {
|
|
201
|
+
try {
|
|
202
|
+
this.destination.error(err);
|
|
203
|
+
} catch (error) {
|
|
204
|
+
throw error;
|
|
205
|
+
}
|
|
206
|
+
} else {
|
|
207
|
+
throw err;
|
|
208
|
+
}
|
|
209
|
+
this.unsubscribe();
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Sends a complete notification to the observer.
|
|
214
|
+
*/
|
|
215
|
+
complete() {
|
|
216
|
+
if (!this.isStopped) {
|
|
217
|
+
this.isStopped = true;
|
|
218
|
+
if (this.destination.complete) {
|
|
219
|
+
try {
|
|
220
|
+
this.destination.complete();
|
|
221
|
+
} catch (error) {
|
|
222
|
+
this.error(error);
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
this.unsubscribe();
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Unsubscribes the subscriber.
|
|
231
|
+
*/
|
|
232
|
+
unsubscribe() {
|
|
233
|
+
if (this.closed) {
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
this.isStopped = true;
|
|
237
|
+
super.unsubscribe();
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
var SafeSubscriber = class extends Subscriber {
|
|
241
|
+
constructor(observerOrNext, error, complete, parentSubscriber) {
|
|
242
|
+
super(observerOrNext, error, complete);
|
|
243
|
+
/** @private */
|
|
244
|
+
this._isUnsubscribing = false;
|
|
245
|
+
/** @private */
|
|
246
|
+
this._parentSubscriber = null;
|
|
247
|
+
this._parentSubscriber = parentSubscriber || null;
|
|
248
|
+
}
|
|
249
|
+
next(value) {
|
|
250
|
+
if (!this.isStopped && !this._isUnsubscribing) {
|
|
251
|
+
try {
|
|
252
|
+
super.next(value);
|
|
253
|
+
} catch (error) {
|
|
254
|
+
this.error(error);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
error(err) {
|
|
259
|
+
if (!this.isStopped && !this._isUnsubscribing) {
|
|
260
|
+
this._isUnsubscribing = true;
|
|
261
|
+
try {
|
|
262
|
+
super.error(err);
|
|
263
|
+
} finally {
|
|
264
|
+
this._isUnsubscribing = false;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
complete() {
|
|
269
|
+
if (!this.isStopped && !this._isUnsubscribing) {
|
|
270
|
+
this._isUnsubscribing = true;
|
|
271
|
+
try {
|
|
272
|
+
super.complete();
|
|
273
|
+
} finally {
|
|
274
|
+
this._isUnsubscribing = false;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
unsubscribe() {
|
|
279
|
+
if (this.closed) {
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
this._isUnsubscribing = true;
|
|
283
|
+
super.unsubscribe();
|
|
284
|
+
this._isUnsubscribing = false;
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
var Observable = class extends Subscription {
|
|
288
|
+
/**
|
|
289
|
+
* Creates a new Observable.
|
|
290
|
+
*/
|
|
291
|
+
constructor(subscribe) {
|
|
292
|
+
super();
|
|
293
|
+
if (subscribe) {
|
|
294
|
+
this._subscribe = subscribe;
|
|
295
|
+
} else {
|
|
296
|
+
throw new TypeError("Observable constructor requires a subscribe function");
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
subscribe(observerOrNext, error, complete) {
|
|
300
|
+
let subscriber;
|
|
301
|
+
if (observerOrNext instanceof Subscriber) {
|
|
302
|
+
subscriber = observerOrNext;
|
|
303
|
+
} else {
|
|
304
|
+
subscriber = new SafeSubscriber(observerOrNext, error, complete);
|
|
305
|
+
}
|
|
306
|
+
const { _subscribe } = this;
|
|
307
|
+
try {
|
|
308
|
+
const result = _subscribe.call(this, subscriber);
|
|
309
|
+
if (result) {
|
|
310
|
+
if (typeof result === "function") {
|
|
311
|
+
subscriber.add(result);
|
|
312
|
+
} else if (typeof result.unsubscribe === "function") {
|
|
313
|
+
subscriber.add(result);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
} catch (err) {
|
|
317
|
+
subscriber.error(err);
|
|
318
|
+
}
|
|
319
|
+
return subscriber;
|
|
320
|
+
}
|
|
321
|
+
pipe(...operations) {
|
|
322
|
+
if (operations.length === 0) {
|
|
323
|
+
return this;
|
|
324
|
+
}
|
|
325
|
+
return operations.reduce(
|
|
326
|
+
(prev, fn) => fn(prev),
|
|
327
|
+
this
|
|
328
|
+
);
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Converts the Observable to a Promise.
|
|
332
|
+
* The Promise resolves with the last emitted value when the Observable completes,
|
|
333
|
+
* or rejects if the Observable errors.
|
|
334
|
+
*
|
|
335
|
+
* @example
|
|
336
|
+
* // Convert Observable to Promise
|
|
337
|
+
* const value = await of(1, 2, 3).toPromise();
|
|
338
|
+
* console.log(value); // 3
|
|
339
|
+
*
|
|
340
|
+
* @example
|
|
341
|
+
* // Handle empty Observable
|
|
342
|
+
* const value = await EMPTY.toPromise();
|
|
343
|
+
* console.log(value); // undefined
|
|
344
|
+
*/
|
|
345
|
+
toPromise() {
|
|
346
|
+
return new Promise((resolve, reject) => {
|
|
347
|
+
let lastValue;
|
|
348
|
+
this.subscribe({
|
|
349
|
+
next: (value) => lastValue = value,
|
|
350
|
+
error: reject,
|
|
351
|
+
complete: () => resolve(lastValue)
|
|
352
|
+
});
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
};
|
|
356
|
+
|
|
357
|
+
// src/lib/signal/graph/detect.ts
|
|
358
|
+
var __BROWSER_PROD__ = typeof window === "undefined" ? false : window.__FLUIXI_PROD__ === true;
|
|
359
|
+
var __DEV__ = typeof process === "undefined" ? __BROWSER_PROD__ : false;
|
|
360
|
+
var $SIGNAL = /* @__PURE__ */ Symbol.for("signal");
|
|
361
|
+
var $MEMO = /* @__PURE__ */ Symbol.for("memo");
|
|
362
|
+
var $RESOURCE = /* @__PURE__ */ Symbol.for("resource");
|
|
363
|
+
function isSignal(value) {
|
|
364
|
+
return typeof value === "function" && value[$SIGNAL] === true;
|
|
365
|
+
}
|
|
366
|
+
function isMemo(value) {
|
|
367
|
+
return typeof value === "function" && value[$MEMO] === true;
|
|
368
|
+
}
|
|
369
|
+
function isResource(value) {
|
|
370
|
+
return typeof value === "function" && value[$RESOURCE] === true;
|
|
371
|
+
}
|
|
372
|
+
function isComponent(value) {
|
|
373
|
+
return typeof value === "function" && value[/* @__PURE__ */ Symbol.for("fluixi-component")] === true;
|
|
374
|
+
}
|
|
375
|
+
function isSuspense(value) {
|
|
376
|
+
return typeof value === "function" && value[/* @__PURE__ */ Symbol.for("fluixi-suspense")] === true;
|
|
377
|
+
}
|
|
378
|
+
function isProvider(value) {
|
|
379
|
+
return typeof value === "function" && value[/* @__PURE__ */ Symbol.for("fluixi-provider")] === true;
|
|
380
|
+
}
|
|
381
|
+
function makeArrayFlat(values) {
|
|
382
|
+
if (!Array.isArray(values)) return values;
|
|
383
|
+
if (values.length === 2 && values[1] === " ") {
|
|
384
|
+
if (Array.isArray(values[0])) return makeArrayFlat(values[0]);
|
|
385
|
+
if (typeof values[0] === "function") return values[0];
|
|
386
|
+
return values[0];
|
|
387
|
+
}
|
|
388
|
+
if (values.length === 1 && typeof values[0] === "function") return values[0];
|
|
389
|
+
return values;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
// src/version.generated.ts
|
|
393
|
+
var VERSION = "1.0.0-alpha.84";
|
|
394
|
+
|
|
395
|
+
// src/lib/signal/graph/state.ts
|
|
396
|
+
var MAJOR = VERSION.split(".")[0];
|
|
397
|
+
var KEY = `__fluixi_signal_state_v${MAJOR}__`;
|
|
398
|
+
var VERSIONS_KEY = `__fluixi_signal_builds_v${MAJOR}__`;
|
|
399
|
+
var defaultSchedule = (run) => {
|
|
400
|
+
if (typeof queueMicrotask === "function") queueMicrotask(run);
|
|
401
|
+
else void Promise.resolve().then(run);
|
|
402
|
+
};
|
|
403
|
+
function defaults() {
|
|
404
|
+
return {
|
|
405
|
+
consumer: null,
|
|
406
|
+
untracked: false,
|
|
407
|
+
owner: null,
|
|
408
|
+
queue: [],
|
|
409
|
+
scheduled: false,
|
|
410
|
+
flushing: false,
|
|
411
|
+
batchDepth: 0,
|
|
412
|
+
hostSchedule: defaultSchedule,
|
|
413
|
+
onSuspend: null,
|
|
414
|
+
onError: null,
|
|
415
|
+
observer: null
|
|
416
|
+
};
|
|
417
|
+
}
|
|
418
|
+
var realm = globalThis;
|
|
419
|
+
function backfillState(existing) {
|
|
420
|
+
const fresh = defaults();
|
|
421
|
+
const target = existing;
|
|
422
|
+
for (const field of Object.keys(fresh)) {
|
|
423
|
+
if (!(field in existing)) target[field] = fresh[field];
|
|
424
|
+
}
|
|
425
|
+
return existing;
|
|
426
|
+
}
|
|
427
|
+
function claim() {
|
|
428
|
+
const existing = realm[KEY];
|
|
429
|
+
return existing ? backfillState(existing) : realm[KEY] = defaults();
|
|
430
|
+
}
|
|
431
|
+
var G = claim();
|
|
432
|
+
(realm[VERSIONS_KEY] ??= []).push(VERSION);
|
|
433
|
+
|
|
434
|
+
// src/lib/signal/graph/observe.ts
|
|
435
|
+
function observeReactiveNodes(next) {
|
|
436
|
+
G.observer = next;
|
|
437
|
+
return () => {
|
|
438
|
+
if (G.observer === next) G.observer = null;
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
var running = [];
|
|
442
|
+
var origin;
|
|
443
|
+
function reportReactiveNode(report) {
|
|
444
|
+
const observer = G.observer;
|
|
445
|
+
if (observer) {
|
|
446
|
+
observer.created(
|
|
447
|
+
report.parents === void 0 ? { ...report, parents: running, origin: report.origin ?? origin } : report
|
|
448
|
+
);
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
function enterReactiveRun(node) {
|
|
452
|
+
if (!G.observer) return false;
|
|
453
|
+
running.push(node);
|
|
454
|
+
return true;
|
|
455
|
+
}
|
|
456
|
+
function exitReactiveRun() {
|
|
457
|
+
running.pop();
|
|
458
|
+
}
|
|
459
|
+
function reportReactiveRun(node) {
|
|
460
|
+
G.observer?.ran?.(node);
|
|
461
|
+
}
|
|
462
|
+
function reportReactiveWrite(node, by) {
|
|
463
|
+
G.observer?.wrote?.(node, by);
|
|
464
|
+
}
|
|
465
|
+
function reportReactiveDispose(node) {
|
|
466
|
+
G.observer?.disposed?.(node);
|
|
467
|
+
}
|
|
468
|
+
var HOOK = "__FLUIXI_DEVTOOLS_HOOK__";
|
|
469
|
+
var hook = globalThis[HOOK];
|
|
470
|
+
if (typeof hook?.inject === "function") {
|
|
471
|
+
try {
|
|
472
|
+
hook.inject({ observeReactiveNodes, version: VERSION });
|
|
473
|
+
} catch {
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
function isObserved() {
|
|
477
|
+
return G.observer != null;
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
// src/lib/signal/graph/core.ts
|
|
481
|
+
var CLEAN = 0;
|
|
482
|
+
var CHECK = 1;
|
|
483
|
+
var DIRTY = 2;
|
|
484
|
+
var Source = class {
|
|
485
|
+
constructor() {
|
|
486
|
+
/** Computeds, and watched leaves, that read this node. */
|
|
487
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
488
|
+
this.observers = null;
|
|
489
|
+
/** Watchers eagerly observing this node, which is how `runtime.ts` schedules effects. */
|
|
490
|
+
this.watchers = null;
|
|
491
|
+
/** Bumped whenever this node's value actually changes (equality-gated). */
|
|
492
|
+
this.version = 0;
|
|
493
|
+
}
|
|
494
|
+
/** Settle this node so a reader sees a current value/version. Overridden by Computed. */
|
|
495
|
+
updateIfNecessary() {
|
|
496
|
+
}
|
|
497
|
+
/** Link the current consumer (if any) as an observer of this node. */
|
|
498
|
+
track() {
|
|
499
|
+
if (G.untracked) return;
|
|
500
|
+
const consumer = G.consumer;
|
|
501
|
+
if (!consumer) return;
|
|
502
|
+
(this.observers ??= /* @__PURE__ */ new Set()).add(consumer);
|
|
503
|
+
(consumer.sources ??= /* @__PURE__ */ new Set()).add(this);
|
|
504
|
+
}
|
|
505
|
+
};
|
|
506
|
+
var State = class extends Source {
|
|
507
|
+
constructor(value, options) {
|
|
508
|
+
super();
|
|
509
|
+
this._value = value;
|
|
510
|
+
this._equals = options?.equals === false ? () => false : options?.equals ?? Object.is;
|
|
511
|
+
}
|
|
512
|
+
get() {
|
|
513
|
+
this.track();
|
|
514
|
+
return this._value;
|
|
515
|
+
}
|
|
516
|
+
set(next) {
|
|
517
|
+
if (this._equals(this._value, next)) return;
|
|
518
|
+
this._value = next;
|
|
519
|
+
this.version++;
|
|
520
|
+
reportReactiveWrite(this, G.consumer);
|
|
521
|
+
if (this.observers) for (const o of [...this.observers]) o.markDirty(DIRTY);
|
|
522
|
+
notifyWatchers(this);
|
|
523
|
+
}
|
|
524
|
+
/** Read without subscribing (peek). */
|
|
525
|
+
peek() {
|
|
526
|
+
return this._value;
|
|
527
|
+
}
|
|
528
|
+
};
|
|
529
|
+
var Computed = class extends Source {
|
|
530
|
+
constructor(fn, options) {
|
|
531
|
+
super();
|
|
532
|
+
this._threw = false;
|
|
533
|
+
this._initialized = false;
|
|
534
|
+
this.state = DIRTY;
|
|
535
|
+
/** Nodes this computation read on its last run. Rebuilt on every run. */
|
|
536
|
+
this.sources = null;
|
|
537
|
+
this._fn = fn;
|
|
538
|
+
this._equals = options?.equals === false ? () => false : options?.equals ?? Object.is;
|
|
539
|
+
}
|
|
540
|
+
get() {
|
|
541
|
+
if (G.consumer === this) {
|
|
542
|
+
throw new Error("Signal.Computed cannot read itself");
|
|
543
|
+
}
|
|
544
|
+
this.track();
|
|
545
|
+
this.updateIfNecessary();
|
|
546
|
+
if (this._threw) throw this._error;
|
|
547
|
+
return this._value;
|
|
548
|
+
}
|
|
549
|
+
/** Settle, if CHECK, verify sources; if DIRTY (or never run), recompute. */
|
|
550
|
+
updateIfNecessary() {
|
|
551
|
+
if (this.state === CHECK) {
|
|
552
|
+
if (this.sources) {
|
|
553
|
+
for (const s of this.sources) {
|
|
554
|
+
s.updateIfNecessary();
|
|
555
|
+
if (this.state === DIRTY) break;
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
if (this.state === DIRTY || !this._initialized) this.recompute();
|
|
560
|
+
this.state = CLEAN;
|
|
561
|
+
}
|
|
562
|
+
recompute() {
|
|
563
|
+
if (this.sources) {
|
|
564
|
+
for (const s of this.sources) s.observers?.delete(this);
|
|
565
|
+
this.sources.clear();
|
|
566
|
+
}
|
|
567
|
+
const prevConsumer = G.consumer;
|
|
568
|
+
const prevUntracked = G.untracked;
|
|
569
|
+
const watched = enterReactiveRun(this);
|
|
570
|
+
G.consumer = this;
|
|
571
|
+
G.untracked = false;
|
|
572
|
+
let next;
|
|
573
|
+
let threw = false;
|
|
574
|
+
let err;
|
|
575
|
+
try {
|
|
576
|
+
next = this._fn();
|
|
577
|
+
} catch (e) {
|
|
578
|
+
threw = true;
|
|
579
|
+
err = e;
|
|
580
|
+
next = this._value;
|
|
581
|
+
} finally {
|
|
582
|
+
G.consumer = prevConsumer;
|
|
583
|
+
G.untracked = prevUntracked;
|
|
584
|
+
if (watched) exitReactiveRun();
|
|
585
|
+
}
|
|
586
|
+
const changed = !this._initialized || this._threw !== threw || (threw ? err !== this._error : !this._equals(this._value, next));
|
|
587
|
+
this._initialized = true;
|
|
588
|
+
this._threw = threw;
|
|
589
|
+
this._error = err;
|
|
590
|
+
this._value = next;
|
|
591
|
+
reportReactiveRun(this);
|
|
592
|
+
if (changed) {
|
|
593
|
+
this.version++;
|
|
594
|
+
if (this.observers) for (const o of [...this.observers]) o.markDirty(DIRTY);
|
|
595
|
+
notifyWatchers(this);
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
/**
|
|
599
|
+
* Push a maybe-dirty mark. A direct observer of a changed node gets DIRTY; its
|
|
600
|
+
* own observers get CHECK (recurse), stopping where already marked, so the
|
|
601
|
+
* push is O(newly-dirtied) and never recomputes.
|
|
602
|
+
*/
|
|
603
|
+
markDirty(level) {
|
|
604
|
+
if (this.state >= level) return;
|
|
605
|
+
const wasClean = this.state === CLEAN;
|
|
606
|
+
this.state = level;
|
|
607
|
+
if (wasClean) {
|
|
608
|
+
if (this.observers) for (const o of [...this.observers]) o.markDirty(CHECK);
|
|
609
|
+
notifyWatchers(this);
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
peek() {
|
|
613
|
+
this.updateIfNecessary();
|
|
614
|
+
if (this._threw) throw this._error;
|
|
615
|
+
return this._value;
|
|
616
|
+
}
|
|
617
|
+
};
|
|
618
|
+
function notifyWatchers(node) {
|
|
619
|
+
if (!node.watchers) return;
|
|
620
|
+
for (const w of [...node.watchers]) w._notify(node);
|
|
621
|
+
}
|
|
622
|
+
var Watcher = class {
|
|
623
|
+
constructor(notify) {
|
|
624
|
+
this._watched = /* @__PURE__ */ new Set();
|
|
625
|
+
this._pending = /* @__PURE__ */ new Set();
|
|
626
|
+
this._notifyFn = notify;
|
|
627
|
+
}
|
|
628
|
+
watch(...nodes) {
|
|
629
|
+
for (const n of nodes) {
|
|
630
|
+
this._watched.add(n);
|
|
631
|
+
(n.watchers ??= /* @__PURE__ */ new Set()).add(this);
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
unwatch(...nodes) {
|
|
635
|
+
for (const n of nodes) {
|
|
636
|
+
this._watched.delete(n);
|
|
637
|
+
n.watchers?.delete(this);
|
|
638
|
+
this._pending.delete(n);
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
/** Watched nodes that may have changed since the last getPending(). */
|
|
642
|
+
getPending() {
|
|
643
|
+
const out = [...this._pending];
|
|
644
|
+
this._pending.clear();
|
|
645
|
+
return out;
|
|
646
|
+
}
|
|
647
|
+
/** @internal, a watched node became non-clean. Edge-triggered: notify once. */
|
|
648
|
+
_notify(node) {
|
|
649
|
+
if (!this._watched.has(node) || this._pending.has(node)) return;
|
|
650
|
+
const wasEmpty = this._pending.size === 0;
|
|
651
|
+
this._pending.add(node);
|
|
652
|
+
if (wasEmpty) this._notifyFn();
|
|
653
|
+
}
|
|
654
|
+
};
|
|
655
|
+
|
|
656
|
+
// src/lib/signal/graph/runtime.ts
|
|
657
|
+
function makeOwner(parent) {
|
|
658
|
+
return { cleanups: null, owned: null, parent, contexts: null };
|
|
659
|
+
}
|
|
660
|
+
function reportSuspend(promise) {
|
|
661
|
+
if (G.onSuspend) {
|
|
662
|
+
G.onSuspend(promise, G.owner);
|
|
663
|
+
return true;
|
|
664
|
+
}
|
|
665
|
+
return false;
|
|
666
|
+
}
|
|
667
|
+
function getOwner() {
|
|
668
|
+
return G.owner;
|
|
669
|
+
}
|
|
670
|
+
function runWithOwner(owner, fn) {
|
|
671
|
+
const prev = G.owner;
|
|
672
|
+
G.owner = owner;
|
|
673
|
+
try {
|
|
674
|
+
return fn();
|
|
675
|
+
} finally {
|
|
676
|
+
G.owner = prev;
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
function onCleanup(fn) {
|
|
680
|
+
if (!G.owner) return;
|
|
681
|
+
if (G.owner.disposed) {
|
|
682
|
+
fn();
|
|
683
|
+
return;
|
|
684
|
+
}
|
|
685
|
+
(G.owner.cleanups ??= []).push(fn);
|
|
686
|
+
}
|
|
687
|
+
function disposeOwner(owner, final = true) {
|
|
688
|
+
if (owner.disposed) return;
|
|
689
|
+
if (owner.owned) {
|
|
690
|
+
for (let i = owner.owned.length - 1; i >= 0; i--) disposeOwner(owner.owned[i]);
|
|
691
|
+
owner.owned = null;
|
|
692
|
+
}
|
|
693
|
+
if (owner.cleanups) {
|
|
694
|
+
for (let i = owner.cleanups.length - 1; i >= 0; i--) owner.cleanups[i]();
|
|
695
|
+
owner.cleanups = null;
|
|
696
|
+
}
|
|
697
|
+
if (final) owner.disposed = true;
|
|
698
|
+
}
|
|
699
|
+
function setScheduler(fn) {
|
|
700
|
+
G.hostSchedule = fn ?? ((run) => void Promise.resolve().then(run));
|
|
701
|
+
}
|
|
702
|
+
function enqueue(e) {
|
|
703
|
+
if (e.queued) return;
|
|
704
|
+
e.queued = true;
|
|
705
|
+
G.queue.push(e);
|
|
706
|
+
if (!G.scheduled && G.batchDepth === 0) {
|
|
707
|
+
G.scheduled = true;
|
|
708
|
+
G.hostSchedule(flushSync);
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
function flushSync() {
|
|
712
|
+
G.scheduled = false;
|
|
713
|
+
if (G.flushing) return;
|
|
714
|
+
G.flushing = true;
|
|
715
|
+
let guard = 0;
|
|
716
|
+
try {
|
|
717
|
+
while (G.queue.length) {
|
|
718
|
+
if (++guard > 1e5) throw new Error("[fluixi] effect flush did not settle (cycle?)");
|
|
719
|
+
const batchOf = G.queue;
|
|
720
|
+
G.queue = [];
|
|
721
|
+
for (const e of batchOf) {
|
|
722
|
+
e.queued = false;
|
|
723
|
+
if (!e.disposed) e.run();
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
} finally {
|
|
727
|
+
G.flushing = false;
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
function afterWrite() {
|
|
731
|
+
if (G.batchDepth === 0) flushSync();
|
|
732
|
+
}
|
|
733
|
+
var EffectNode = class {
|
|
734
|
+
constructor(fn, report = false) {
|
|
735
|
+
this.queued = false;
|
|
736
|
+
this.disposed = false;
|
|
737
|
+
this.owner = makeOwner(G.owner);
|
|
738
|
+
if (G.owner) (G.owner.cleanups ??= []).push(() => this.dispose());
|
|
739
|
+
this.computed = new Computed(() => {
|
|
740
|
+
disposeOwner(this.owner, false);
|
|
741
|
+
runWithOwner(this.owner, () => {
|
|
742
|
+
const r = fn();
|
|
743
|
+
if (typeof r === "function") (this.owner.cleanups ??= []).push(r);
|
|
744
|
+
});
|
|
745
|
+
});
|
|
746
|
+
reportReactiveNode({ kind: "effect", node: this.computed, handle: this, internal: !report });
|
|
747
|
+
this.watcher = new Watcher(() => enqueue(this));
|
|
748
|
+
this.run();
|
|
749
|
+
this.watcher.watch(this.computed);
|
|
750
|
+
}
|
|
751
|
+
run() {
|
|
752
|
+
if (this.disposed) return;
|
|
753
|
+
this.watcher.getPending();
|
|
754
|
+
try {
|
|
755
|
+
this.computed.get();
|
|
756
|
+
} catch (e) {
|
|
757
|
+
if (e && typeof e.then === "function" && G.onSuspend) {
|
|
758
|
+
G.onSuspend(e, this.owner);
|
|
759
|
+
return;
|
|
760
|
+
}
|
|
761
|
+
if (G.onError && G.onError(e, this.owner)) return;
|
|
762
|
+
throw e;
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
dispose() {
|
|
766
|
+
if (this.disposed) return;
|
|
767
|
+
this.disposed = true;
|
|
768
|
+
reportReactiveDispose(this.computed);
|
|
769
|
+
this.watcher.unwatch(this.computed);
|
|
770
|
+
disposeOwner(this.owner);
|
|
771
|
+
}
|
|
772
|
+
};
|
|
773
|
+
function effect(fn, report = false) {
|
|
774
|
+
const node = new EffectNode(fn, report);
|
|
775
|
+
return () => node.dispose();
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
// src/lib/signal/graph/compat.ts
|
|
779
|
+
function isThenable(v) {
|
|
780
|
+
return !!v && typeof v.then === "function";
|
|
781
|
+
}
|
|
782
|
+
setScheduler(() => {
|
|
783
|
+
});
|
|
784
|
+
var $SIGNAL2 = /* @__PURE__ */ Symbol.for("signal");
|
|
785
|
+
var $MEMO2 = /* @__PURE__ */ Symbol.for("memo");
|
|
786
|
+
var $NODE = /* @__PURE__ */ Symbol.for("signal-node");
|
|
787
|
+
function createSignal(value, options) {
|
|
788
|
+
const state = new State(value, { equals: options?.equals });
|
|
789
|
+
const read = (() => state.get());
|
|
790
|
+
const write = ((next) => {
|
|
791
|
+
const v = typeof next === "function" ? next(state.peek()) : next;
|
|
792
|
+
state.set(v);
|
|
793
|
+
afterWrite();
|
|
794
|
+
return v;
|
|
795
|
+
});
|
|
796
|
+
Object.defineProperty(read, $SIGNAL2, { value: true, enumerable: true });
|
|
797
|
+
Object.defineProperty(read, $NODE, {
|
|
798
|
+
value: {
|
|
799
|
+
get value() {
|
|
800
|
+
return state.peek();
|
|
801
|
+
},
|
|
802
|
+
get version() {
|
|
803
|
+
return state.version;
|
|
804
|
+
}
|
|
805
|
+
},
|
|
806
|
+
enumerable: false
|
|
807
|
+
});
|
|
808
|
+
reportReactiveNode({
|
|
809
|
+
kind: "signal",
|
|
810
|
+
node: state,
|
|
811
|
+
handle: read,
|
|
812
|
+
name: options?.name,
|
|
813
|
+
set: write
|
|
814
|
+
});
|
|
815
|
+
if (isObserved()) onCleanup(() => reportReactiveDispose(state));
|
|
816
|
+
return [read, write];
|
|
817
|
+
}
|
|
818
|
+
function createMemo(fn, value, options) {
|
|
819
|
+
let prev = value;
|
|
820
|
+
const owner = getOwner();
|
|
821
|
+
const c = new Computed(
|
|
822
|
+
() => runWithOwner(owner, () => {
|
|
823
|
+
try {
|
|
824
|
+
return prev = fn(prev);
|
|
825
|
+
} catch (e) {
|
|
826
|
+
if (isThenable(e)) {
|
|
827
|
+
reportSuspend(e);
|
|
828
|
+
return prev;
|
|
829
|
+
}
|
|
830
|
+
throw e;
|
|
831
|
+
}
|
|
832
|
+
}),
|
|
833
|
+
{ equals: options?.equals }
|
|
834
|
+
);
|
|
835
|
+
const read = (() => c.get());
|
|
836
|
+
Object.defineProperty(read, $SIGNAL2, { value: true, enumerable: true });
|
|
837
|
+
Object.defineProperty(read, $MEMO2, { value: true, enumerable: true });
|
|
838
|
+
reportReactiveNode({ kind: "memo", node: c, handle: read, name: options?.name });
|
|
839
|
+
if (isObserved()) onCleanup(() => reportReactiveDispose(c));
|
|
840
|
+
return read;
|
|
841
|
+
}
|
|
842
|
+
function createEffect(fn, value) {
|
|
843
|
+
let prev = value;
|
|
844
|
+
return effect(() => {
|
|
845
|
+
const r = fn(prev);
|
|
846
|
+
prev = r;
|
|
847
|
+
}, true);
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
// src/lib/signal/graph/derived.ts
|
|
851
|
+
function createSelector(source, fn = (k, v) => k === v) {
|
|
852
|
+
const map = /* @__PURE__ */ new Map();
|
|
853
|
+
createEffect(() => {
|
|
854
|
+
const value = source();
|
|
855
|
+
for (const [key, signal] of map) {
|
|
856
|
+
const [get, set] = signal;
|
|
857
|
+
const match = fn(key, value);
|
|
858
|
+
if (get() !== match) set(match);
|
|
859
|
+
}
|
|
860
|
+
});
|
|
861
|
+
return (key) => {
|
|
862
|
+
let signal = map.get(key);
|
|
863
|
+
if (!signal) {
|
|
864
|
+
const [get, set] = createSignal(false);
|
|
865
|
+
signal = [get, set];
|
|
866
|
+
map.set(key, signal);
|
|
867
|
+
const value = source();
|
|
868
|
+
set(fn(key, value));
|
|
869
|
+
}
|
|
870
|
+
return signal[0]();
|
|
871
|
+
};
|
|
872
|
+
}
|
|
873
|
+
function createDeferred(source, options) {
|
|
874
|
+
const [delayed, setDelayed] = createSignal(source(), options);
|
|
875
|
+
createEffect(() => {
|
|
876
|
+
const v = source();
|
|
877
|
+
if (options?.timeoutMs) setTimeout(() => setDelayed(() => v), options.timeoutMs);
|
|
878
|
+
else if (typeof requestIdleCallback === "function")
|
|
879
|
+
requestIdleCallback(() => setDelayed(() => v));
|
|
880
|
+
else Promise.resolve().then(() => setDelayed(() => v));
|
|
881
|
+
});
|
|
882
|
+
return delayed;
|
|
883
|
+
}
|
|
884
|
+
function createDebounce(fn, delay) {
|
|
885
|
+
let timer;
|
|
886
|
+
const debounced = (...args) => {
|
|
887
|
+
if (timer !== void 0) clearTimeout(timer);
|
|
888
|
+
timer = setTimeout(() => {
|
|
889
|
+
timer = void 0;
|
|
890
|
+
fn(...args);
|
|
891
|
+
}, delay);
|
|
892
|
+
};
|
|
893
|
+
onCleanup(() => {
|
|
894
|
+
if (timer !== void 0) clearTimeout(timer);
|
|
895
|
+
});
|
|
896
|
+
return debounced;
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
// src/lib/signal/graph/children.ts
|
|
900
|
+
function resolveChildrenValue(children) {
|
|
901
|
+
if (typeof children === "function" && !children.length) {
|
|
902
|
+
const result = children();
|
|
903
|
+
if (isSignal(result)) return result;
|
|
904
|
+
return resolveChildrenValue(result);
|
|
905
|
+
}
|
|
906
|
+
if (Array.isArray(children)) {
|
|
907
|
+
const results = [];
|
|
908
|
+
for (let i = 0; i < children.length; i++) {
|
|
909
|
+
const result = resolveChildrenValue(children[i]);
|
|
910
|
+
Array.isArray(result) ? results.push.apply(results, result) : results.push(result);
|
|
911
|
+
}
|
|
912
|
+
return results;
|
|
913
|
+
}
|
|
914
|
+
return children;
|
|
915
|
+
}
|
|
916
|
+
function readChildren(fn) {
|
|
917
|
+
const children = createMemo(fn);
|
|
918
|
+
return __DEV__ ? createMemo(() => resolveChildrenValue(children()), void 0, { name: "children" }) : createMemo(() => resolveChildrenValue(children()));
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
// src/lib/signal/graph/ssr-hooks.ts
|
|
922
|
+
var _resourceTracker = null;
|
|
923
|
+
function setResourceTracker(fn) {
|
|
924
|
+
_resourceTracker = fn;
|
|
925
|
+
}
|
|
926
|
+
function trackResourcePromise(p) {
|
|
927
|
+
if (_resourceTracker) _resourceTracker(p);
|
|
928
|
+
}
|
|
929
|
+
var _serverDataGetter = null;
|
|
930
|
+
function setServerDataGetter(fn) {
|
|
931
|
+
_serverDataGetter = fn;
|
|
932
|
+
}
|
|
933
|
+
function getServerData(id) {
|
|
934
|
+
return _serverDataGetter ? _serverDataGetter(id) : void 0;
|
|
935
|
+
}
|
|
936
|
+
var _resourceIdSource = null;
|
|
937
|
+
function setResourceIdSource(fn) {
|
|
938
|
+
_resourceIdSource = fn;
|
|
939
|
+
}
|
|
940
|
+
function nextResourceId() {
|
|
941
|
+
return _resourceIdSource ? _resourceIdSource() : void 0;
|
|
942
|
+
}
|
|
943
|
+
var _resourceDataSink = null;
|
|
944
|
+
function setResourceDataSink(fn) {
|
|
945
|
+
_resourceDataSink = fn;
|
|
946
|
+
}
|
|
947
|
+
function reportResourceData(id, value) {
|
|
948
|
+
if (_resourceDataSink) _resourceDataSink(id, value);
|
|
949
|
+
}
|
|
950
|
+
|
|
951
|
+
// src/lib/signal/signal.ts
|
|
952
|
+
var $SIGNAL3 = /* @__PURE__ */ Symbol.for("signal");
|
|
953
|
+
var $MEMO3 = /* @__PURE__ */ Symbol.for("memo");
|
|
954
|
+
var $RESOURCE2 = /* @__PURE__ */ Symbol.for("resource");
|
|
955
|
+
var $PROXY = /* @__PURE__ */ Symbol("fluixi-proxy");
|
|
956
|
+
var $NODE2 = /* @__PURE__ */ Symbol.for("signal-node");
|
|
957
|
+
var CLEAN2 = 0;
|
|
958
|
+
var STALE = 1;
|
|
959
|
+
var DIRTY2 = 2;
|
|
960
|
+
var RUNNING = 3;
|
|
961
|
+
var Owner = null;
|
|
962
|
+
var Listener = null;
|
|
963
|
+
var Updates = null;
|
|
964
|
+
var Effects = null;
|
|
965
|
+
var ExecCount = 0;
|
|
966
|
+
var _eagerStaleEffects = false;
|
|
967
|
+
var Pending = false;
|
|
968
|
+
var BatchDepth = 0;
|
|
969
|
+
var MAX_ITERATIONS = 1e6;
|
|
970
|
+
var signalObservers = /* @__PURE__ */ new WeakMap();
|
|
971
|
+
var Transition = null;
|
|
972
|
+
var Scheduler = null;
|
|
973
|
+
var nodeRegistry = /* @__PURE__ */ new Map();
|
|
974
|
+
var nodeIdCounter = 0;
|
|
975
|
+
var sharedConfig = {
|
|
976
|
+
context: null,
|
|
977
|
+
owner: null,
|
|
978
|
+
routeData: /* @__PURE__ */ new Map(),
|
|
979
|
+
matchedRoute: /* @__PURE__ */ new Map()
|
|
980
|
+
};
|
|
981
|
+
function setOwner2(owner) {
|
|
982
|
+
Owner = owner;
|
|
983
|
+
sharedConfig.owner = owner;
|
|
984
|
+
sharedConfig.context = owner;
|
|
985
|
+
}
|
|
986
|
+
function getSharedConfig() {
|
|
987
|
+
return sharedConfig;
|
|
988
|
+
}
|
|
989
|
+
function createNodeId() {
|
|
990
|
+
return `node_${++nodeIdCounter}_${Date.now()}`;
|
|
991
|
+
}
|
|
992
|
+
function registerNode(node) {
|
|
993
|
+
if (__DEV__) nodeRegistry.set(node.id, new WeakRef(node));
|
|
994
|
+
}
|
|
995
|
+
function createReactiveNode(type, initialValue, options) {
|
|
996
|
+
const node = {
|
|
997
|
+
id: createNodeId(),
|
|
998
|
+
type,
|
|
999
|
+
value: initialValue,
|
|
1000
|
+
version: 0,
|
|
1001
|
+
equals: options?.equals,
|
|
1002
|
+
name: options?.name,
|
|
1003
|
+
created: Date.now(),
|
|
1004
|
+
updated: Date.now()
|
|
1005
|
+
};
|
|
1006
|
+
registerNode(node);
|
|
1007
|
+
return node;
|
|
1008
|
+
}
|
|
1009
|
+
function defaultEquals(a, b) {
|
|
1010
|
+
return a === b;
|
|
1011
|
+
}
|
|
1012
|
+
function handleError(err) {
|
|
1013
|
+
if (typeof console !== "undefined") console.error("Reactive error:", err);
|
|
1014
|
+
throw err;
|
|
1015
|
+
}
|
|
1016
|
+
var _transPending = null;
|
|
1017
|
+
var _setTransPending = null;
|
|
1018
|
+
function ensureTransPending() {
|
|
1019
|
+
if (!_transPending) {
|
|
1020
|
+
const [get, set] = createSignal2(false);
|
|
1021
|
+
_transPending = get;
|
|
1022
|
+
_setTransPending = set;
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
function scheduleComputation(c) {
|
|
1026
|
+
if (Updates) {
|
|
1027
|
+
if (Updates.indexOf(c) === -1) Updates.push(c);
|
|
1028
|
+
} else if (Transition && Transition.running && !c.pure) {
|
|
1029
|
+
if (Transition.effects.indexOf(c) === -1) Transition.effects.push(c);
|
|
1030
|
+
} else if (!c.pure || c.computed) {
|
|
1031
|
+
updateComputation(c);
|
|
1032
|
+
} else if (c.pure && !c.computed && c.accessor) {
|
|
1033
|
+
const prevListener = Listener;
|
|
1034
|
+
const prevUpdatesM = Updates;
|
|
1035
|
+
Listener = null;
|
|
1036
|
+
Updates = [];
|
|
1037
|
+
c.accessor();
|
|
1038
|
+
Listener = prevListener;
|
|
1039
|
+
const memoDeferred = Updates;
|
|
1040
|
+
Updates = prevUpdatesM;
|
|
1041
|
+
if (memoDeferred.length > 0) {
|
|
1042
|
+
const savedU = Updates;
|
|
1043
|
+
runCascadeAndEffects(memoDeferred);
|
|
1044
|
+
Updates = savedU;
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
function propagate(observerList, propagator) {
|
|
1049
|
+
for (let i = 0; i < observerList.length; i++) propagator(observerList[i]);
|
|
1050
|
+
}
|
|
1051
|
+
function createSignal2(_value, options) {
|
|
1052
|
+
let value = _value;
|
|
1053
|
+
if (typeof value === "object" && value && $PROXY in value)
|
|
1054
|
+
delete value[$PROXY];
|
|
1055
|
+
const node = createReactiveNode("signal", value, {
|
|
1056
|
+
equals: options?.equals === false ? void 0 : options?.equals,
|
|
1057
|
+
name: options?.name
|
|
1058
|
+
});
|
|
1059
|
+
const s = [read, write];
|
|
1060
|
+
signalObservers.set(s, /* @__PURE__ */ new Set());
|
|
1061
|
+
let lastObs;
|
|
1062
|
+
function read() {
|
|
1063
|
+
let observer = Listener;
|
|
1064
|
+
if (observer) {
|
|
1065
|
+
if (!observer.sources) observer.sources = [s];
|
|
1066
|
+
else if (observer.sources.indexOf(s) === -1) observer.sources.push(s);
|
|
1067
|
+
const observers = signalObservers.get(s);
|
|
1068
|
+
if (observers && !observers.has(observer)) observers.add(observer);
|
|
1069
|
+
}
|
|
1070
|
+
return value;
|
|
1071
|
+
}
|
|
1072
|
+
function write(nextValue) {
|
|
1073
|
+
const v = typeof nextValue === "function" ? nextValue(value) : nextValue;
|
|
1074
|
+
const equals = node.equals || defaultEquals;
|
|
1075
|
+
if (options?.equals === false || !equals(value, v)) {
|
|
1076
|
+
value = v;
|
|
1077
|
+
node.value = v;
|
|
1078
|
+
node.version++;
|
|
1079
|
+
node.updated = Date.now();
|
|
1080
|
+
const observers = signalObservers.get(s);
|
|
1081
|
+
if (observers && observers.size > 0) {
|
|
1082
|
+
let propagateDirty2 = function(comp, viaPureMemo = false) {
|
|
1083
|
+
const prevState = comp.state;
|
|
1084
|
+
if (prevState === RUNNING && comp === Listener) return;
|
|
1085
|
+
if (viaPureMemo && !comp.pure) {
|
|
1086
|
+
if (prevState === CLEAN2) {
|
|
1087
|
+
comp.state = STALE;
|
|
1088
|
+
if (_eagerStaleEffects) {
|
|
1089
|
+
if (Updates !== null && Updates.indexOf(comp) === -1)
|
|
1090
|
+
Updates.push(comp);
|
|
1091
|
+
else toUpdate.push(comp);
|
|
1092
|
+
}
|
|
1093
|
+
}
|
|
1094
|
+
return;
|
|
1095
|
+
}
|
|
1096
|
+
if (visited.has(comp)) return;
|
|
1097
|
+
visited.add(comp);
|
|
1098
|
+
comp.state = DIRTY2;
|
|
1099
|
+
if (prevState === CLEAN2 || prevState === STALE) toUpdate.push(comp);
|
|
1100
|
+
else if (!comp.pure && Updates !== null && Updates.indexOf(comp) === -1)
|
|
1101
|
+
Updates.push(comp);
|
|
1102
|
+
if (comp.pure && comp.accessor) {
|
|
1103
|
+
const memoObservers = signalObservers.get(comp.accessor);
|
|
1104
|
+
if (memoObservers)
|
|
1105
|
+
propagate(
|
|
1106
|
+
Array.from(memoObservers),
|
|
1107
|
+
(c) => propagateDirty2(c, true)
|
|
1108
|
+
);
|
|
1109
|
+
}
|
|
1110
|
+
};
|
|
1111
|
+
var propagateDirty = propagateDirty2;
|
|
1112
|
+
const observerList = Array.from(observers);
|
|
1113
|
+
const toUpdate = [];
|
|
1114
|
+
const visited = /* @__PURE__ */ new Set();
|
|
1115
|
+
propagate(observerList, propagateDirty2);
|
|
1116
|
+
for (const comp of toUpdate) scheduleComputation(comp);
|
|
1117
|
+
}
|
|
1118
|
+
}
|
|
1119
|
+
}
|
|
1120
|
+
read.toObservable = () => new Observable((observer) => {
|
|
1121
|
+
let first = true;
|
|
1122
|
+
const dispose2 = createEffect2(() => {
|
|
1123
|
+
const val = read();
|
|
1124
|
+
if (first) first = false;
|
|
1125
|
+
else observer.next(val);
|
|
1126
|
+
});
|
|
1127
|
+
return dispose2;
|
|
1128
|
+
});
|
|
1129
|
+
Object.defineProperty(read, $SIGNAL3, { value: true, enumerable: true });
|
|
1130
|
+
Object.defineProperty(read, $NODE2, { value: node, enumerable: false });
|
|
1131
|
+
return s;
|
|
1132
|
+
}
|
|
1133
|
+
function createEffect2(fn, value, options) {
|
|
1134
|
+
const c = {
|
|
1135
|
+
fn,
|
|
1136
|
+
state: DIRTY2,
|
|
1137
|
+
sources: null,
|
|
1138
|
+
sourceSlots: null,
|
|
1139
|
+
owned: null,
|
|
1140
|
+
cleanups: null,
|
|
1141
|
+
owner: Owner,
|
|
1142
|
+
contexts: null,
|
|
1143
|
+
pure: false,
|
|
1144
|
+
updatedAt: null
|
|
1145
|
+
};
|
|
1146
|
+
if (Owner) {
|
|
1147
|
+
if (!Owner.owned) Owner.owned = [c];
|
|
1148
|
+
else Owner.owned.push(c);
|
|
1149
|
+
}
|
|
1150
|
+
const SC = _SuspenseContext && useContext(_SuspenseContext);
|
|
1151
|
+
if (SC) c.suspense = SC;
|
|
1152
|
+
runComputation(c, value);
|
|
1153
|
+
return () => dispose(c);
|
|
1154
|
+
}
|
|
1155
|
+
function runComputation(c, value) {
|
|
1156
|
+
if (c.sources) {
|
|
1157
|
+
for (const source of c.sources) {
|
|
1158
|
+
const observers = signalObservers.get(source);
|
|
1159
|
+
if (observers) observers.delete(c);
|
|
1160
|
+
}
|
|
1161
|
+
c.sources = null;
|
|
1162
|
+
c.sourceSlots = null;
|
|
1163
|
+
}
|
|
1164
|
+
if (c.owned) {
|
|
1165
|
+
for (let i = 0; i < c.owned.length; i++) dispose(c.owned[i]);
|
|
1166
|
+
c.owned = null;
|
|
1167
|
+
}
|
|
1168
|
+
const prevListener = Listener;
|
|
1169
|
+
const prevOwner = Owner;
|
|
1170
|
+
Listener = c;
|
|
1171
|
+
Owner = c;
|
|
1172
|
+
ExecCount++;
|
|
1173
|
+
if (ExecCount > MAX_ITERATIONS) {
|
|
1174
|
+
ExecCount = 0;
|
|
1175
|
+
Listener = prevListener;
|
|
1176
|
+
Owner = prevOwner;
|
|
1177
|
+
throw new Error(
|
|
1178
|
+
"Potential infinite loop detected. Exceeded maximum iterations."
|
|
1179
|
+
);
|
|
1180
|
+
}
|
|
1181
|
+
try {
|
|
1182
|
+
c.state = RUNNING;
|
|
1183
|
+
const result = c.fn(value);
|
|
1184
|
+
if (typeof result === "function") {
|
|
1185
|
+
if (!c.cleanups) c.cleanups = [result];
|
|
1186
|
+
else c.cleanups.push(result);
|
|
1187
|
+
}
|
|
1188
|
+
if (c.state === RUNNING) c.state = CLEAN2;
|
|
1189
|
+
} catch (err) {
|
|
1190
|
+
if (isPromise(err)) {
|
|
1191
|
+
const ctx = _SuspenseContext && useContext(_SuspenseContext);
|
|
1192
|
+
if (ctx) {
|
|
1193
|
+
ctx.increment();
|
|
1194
|
+
err.finally(() => ctx.decrement());
|
|
1195
|
+
if (c.suspense) ctx.effects.push(c);
|
|
1196
|
+
}
|
|
1197
|
+
return;
|
|
1198
|
+
}
|
|
1199
|
+
handleError(err);
|
|
1200
|
+
} finally {
|
|
1201
|
+
Listener = prevListener;
|
|
1202
|
+
Owner = prevOwner;
|
|
1203
|
+
}
|
|
1204
|
+
}
|
|
1205
|
+
function updateComputation(c) {
|
|
1206
|
+
if (c.disposed || !c.fn || c.state === CLEAN2) return;
|
|
1207
|
+
if (c.state === DIRTY2 || c.state === STALE || c.state === RUNNING) {
|
|
1208
|
+
if (c.cleanups) {
|
|
1209
|
+
for (let i = 0; i < c.cleanups.length; i++) c.cleanups[i]();
|
|
1210
|
+
c.cleanups = null;
|
|
1211
|
+
}
|
|
1212
|
+
if (c.owned) {
|
|
1213
|
+
for (let i = 0; i < c.owned.length; i++) dispose(c.owned[i]);
|
|
1214
|
+
c.owned = null;
|
|
1215
|
+
}
|
|
1216
|
+
if (c.renderEffect) runRenderComputation(c);
|
|
1217
|
+
else runComputation(c, c.value);
|
|
1218
|
+
}
|
|
1219
|
+
}
|
|
1220
|
+
function dispose(c) {
|
|
1221
|
+
c.disposed = true;
|
|
1222
|
+
if (c.sources) {
|
|
1223
|
+
for (const source of c.sources) {
|
|
1224
|
+
const observers = signalObservers.get(source);
|
|
1225
|
+
if (observers) observers.delete(c);
|
|
1226
|
+
}
|
|
1227
|
+
}
|
|
1228
|
+
if (c.cleanups) for (let i = 0; i < c.cleanups.length; i++) c.cleanups[i]();
|
|
1229
|
+
if (c.owned) for (let i = 0; i < c.owned.length; i++) dispose(c.owned[i]);
|
|
1230
|
+
if (c.owner && c.owner.owned) {
|
|
1231
|
+
const index = c.owner.owned.indexOf(c);
|
|
1232
|
+
if (index !== -1) c.owner.owned.splice(index, 1);
|
|
1233
|
+
}
|
|
1234
|
+
}
|
|
1235
|
+
function createMemo2(fn, value, options) {
|
|
1236
|
+
const node = createReactiveNode("memo", value, {
|
|
1237
|
+
equals: options?.equals === false ? void 0 : options?.equals,
|
|
1238
|
+
name: options?.name
|
|
1239
|
+
});
|
|
1240
|
+
const c = {
|
|
1241
|
+
fn,
|
|
1242
|
+
state: DIRTY2,
|
|
1243
|
+
sources: null,
|
|
1244
|
+
sourceSlots: null,
|
|
1245
|
+
value,
|
|
1246
|
+
owned: null,
|
|
1247
|
+
cleanups: null,
|
|
1248
|
+
owner: Owner,
|
|
1249
|
+
contexts: null,
|
|
1250
|
+
pure: true,
|
|
1251
|
+
updatedAt: null,
|
|
1252
|
+
node,
|
|
1253
|
+
accessor: void 0
|
|
1254
|
+
};
|
|
1255
|
+
if (Owner) {
|
|
1256
|
+
if (!Owner.owned) Owner.owned = [c];
|
|
1257
|
+
else Owner.owned.push(c);
|
|
1258
|
+
}
|
|
1259
|
+
const read = () => {
|
|
1260
|
+
if (Listener && Listener !== c) {
|
|
1261
|
+
if (!Listener.sources) Listener.sources = [read];
|
|
1262
|
+
else if (Listener.sources.indexOf(read) === -1)
|
|
1263
|
+
Listener.sources.push(read);
|
|
1264
|
+
const memoAsSignal = read;
|
|
1265
|
+
if (!signalObservers.has(memoAsSignal))
|
|
1266
|
+
signalObservers.set(memoAsSignal, /* @__PURE__ */ new Set());
|
|
1267
|
+
const observers = signalObservers.get(memoAsSignal);
|
|
1268
|
+
if (observers) observers.add(Listener);
|
|
1269
|
+
}
|
|
1270
|
+
if (c.state !== CLEAN2) {
|
|
1271
|
+
if (c.sources) {
|
|
1272
|
+
for (const source of c.sources) {
|
|
1273
|
+
const observers = signalObservers.get(source);
|
|
1274
|
+
if (observers) observers.delete(c);
|
|
1275
|
+
}
|
|
1276
|
+
c.sources = null;
|
|
1277
|
+
c.sourceSlots = null;
|
|
1278
|
+
}
|
|
1279
|
+
if (c.cleanups) {
|
|
1280
|
+
for (let i = 0; i < c.cleanups.length; i++) c.cleanups[i]();
|
|
1281
|
+
c.cleanups = null;
|
|
1282
|
+
}
|
|
1283
|
+
if (c.owned) {
|
|
1284
|
+
for (let i = 0; i < c.owned.length; i++) dispose(c.owned[i]);
|
|
1285
|
+
c.owned = null;
|
|
1286
|
+
}
|
|
1287
|
+
const prevListener = Listener;
|
|
1288
|
+
const prevOwner = Owner;
|
|
1289
|
+
Listener = c;
|
|
1290
|
+
Owner = c;
|
|
1291
|
+
c.state = RUNNING;
|
|
1292
|
+
try {
|
|
1293
|
+
const nextValue = c.fn(c.value);
|
|
1294
|
+
const equals = node.equals || defaultEquals;
|
|
1295
|
+
const hasChanged = options?.equals === false || !equals(c.value, nextValue);
|
|
1296
|
+
if (hasChanged) {
|
|
1297
|
+
c.value = nextValue;
|
|
1298
|
+
node.value = nextValue;
|
|
1299
|
+
node.version++;
|
|
1300
|
+
node.updated = Date.now();
|
|
1301
|
+
const memoAsSignal = read;
|
|
1302
|
+
const observers = signalObservers.get(memoAsSignal);
|
|
1303
|
+
if (observers && observers.size > 0) {
|
|
1304
|
+
let propagateDirty2 = function(comp, viaPureMemo = false) {
|
|
1305
|
+
if (comp === c) return;
|
|
1306
|
+
const prevState = comp.state;
|
|
1307
|
+
if (prevState === RUNNING) return;
|
|
1308
|
+
if (viaPureMemo && !comp.pure) {
|
|
1309
|
+
if (prevState === CLEAN2) {
|
|
1310
|
+
comp.state = STALE;
|
|
1311
|
+
if (Updates !== null && Updates.indexOf(comp) === -1)
|
|
1312
|
+
Updates.push(comp);
|
|
1313
|
+
else toUpdate.push(comp);
|
|
1314
|
+
}
|
|
1315
|
+
return;
|
|
1316
|
+
}
|
|
1317
|
+
if (visited.has(comp)) return;
|
|
1318
|
+
visited.add(comp);
|
|
1319
|
+
comp.state = DIRTY2;
|
|
1320
|
+
if (prevState === CLEAN2 || prevState === STALE)
|
|
1321
|
+
toUpdate.push(comp);
|
|
1322
|
+
else if (!comp.pure && Updates !== null && Updates.indexOf(comp) === -1)
|
|
1323
|
+
Updates.push(comp);
|
|
1324
|
+
if (comp.pure && comp.accessor) {
|
|
1325
|
+
const memoObservers = signalObservers.get(comp.accessor);
|
|
1326
|
+
if (memoObservers && memoObservers.size > 0)
|
|
1327
|
+
for (const o of Array.from(memoObservers))
|
|
1328
|
+
propagateDirty2(o, true);
|
|
1329
|
+
}
|
|
1330
|
+
};
|
|
1331
|
+
var propagateDirty = propagateDirty2;
|
|
1332
|
+
const observerList = Array.from(observers);
|
|
1333
|
+
const toUpdate = [];
|
|
1334
|
+
const visited = /* @__PURE__ */ new Set();
|
|
1335
|
+
for (let i = 0; i < observerList.length; i++)
|
|
1336
|
+
propagateDirty2(observerList[i]);
|
|
1337
|
+
for (const comp of toUpdate) scheduleComputation(comp);
|
|
1338
|
+
}
|
|
1339
|
+
}
|
|
1340
|
+
if (c.state === RUNNING) c.state = CLEAN2;
|
|
1341
|
+
} catch (err) {
|
|
1342
|
+
if (isPromise(err)) {
|
|
1343
|
+
let ctx = _SuspenseContext && useContext(_SuspenseContext);
|
|
1344
|
+
if (!ctx && _SuspenseContext) {
|
|
1345
|
+
let owner = prevOwner;
|
|
1346
|
+
while (owner) {
|
|
1347
|
+
if (owner.contexts?.has(_SuspenseContext.id)) {
|
|
1348
|
+
ctx = owner.contexts.get(_SuspenseContext.id);
|
|
1349
|
+
break;
|
|
1350
|
+
}
|
|
1351
|
+
owner = owner.owner;
|
|
1352
|
+
}
|
|
1353
|
+
}
|
|
1354
|
+
if (ctx) {
|
|
1355
|
+
ctx.increment();
|
|
1356
|
+
err.finally(() => ctx.decrement());
|
|
1357
|
+
}
|
|
1358
|
+
return c.value;
|
|
1359
|
+
}
|
|
1360
|
+
handleError(err);
|
|
1361
|
+
} finally {
|
|
1362
|
+
Listener = prevListener;
|
|
1363
|
+
Owner = prevOwner;
|
|
1364
|
+
}
|
|
1365
|
+
}
|
|
1366
|
+
return c.value;
|
|
1367
|
+
};
|
|
1368
|
+
c.accessor = read;
|
|
1369
|
+
signalObservers.set(read, /* @__PURE__ */ new Set());
|
|
1370
|
+
read.toObservable = () => new Observable((observer) => {
|
|
1371
|
+
let first = true;
|
|
1372
|
+
const dispose2 = createEffect2(() => {
|
|
1373
|
+
const val = read();
|
|
1374
|
+
if (first) first = false;
|
|
1375
|
+
else observer.next(val);
|
|
1376
|
+
});
|
|
1377
|
+
return dispose2;
|
|
1378
|
+
});
|
|
1379
|
+
Object.defineProperty(read, $SIGNAL3, { value: true, enumerable: true });
|
|
1380
|
+
Object.defineProperty(read, $MEMO3, { value: true, enumerable: true });
|
|
1381
|
+
Object.defineProperty(read, $NODE2, { value: node, enumerable: false });
|
|
1382
|
+
return read;
|
|
1383
|
+
}
|
|
1384
|
+
function runCascadeAndEffects(initial) {
|
|
1385
|
+
const cascadeQueue = [];
|
|
1386
|
+
const effectsToRun = [];
|
|
1387
|
+
for (const comp of initial) {
|
|
1388
|
+
if (comp.pure && !comp.computed && comp.accessor) {
|
|
1389
|
+
if (cascadeQueue.indexOf(comp) === -1) cascadeQueue.push(comp);
|
|
1390
|
+
} else if ((comp.computed || !comp.pure) && effectsToRun.indexOf(comp) === -1)
|
|
1391
|
+
effectsToRun.push(comp);
|
|
1392
|
+
}
|
|
1393
|
+
Updates = [];
|
|
1394
|
+
let ci = 0;
|
|
1395
|
+
while (ci < cascadeQueue.length) {
|
|
1396
|
+
const comp = cascadeQueue[ci++];
|
|
1397
|
+
const observers = signalObservers.get(comp.accessor);
|
|
1398
|
+
if (observers && observers.size > 0) {
|
|
1399
|
+
const prevListener = Listener;
|
|
1400
|
+
Listener = null;
|
|
1401
|
+
comp.accessor();
|
|
1402
|
+
Listener = prevListener;
|
|
1403
|
+
}
|
|
1404
|
+
const fresh = Updates.splice(0);
|
|
1405
|
+
for (const c of fresh) {
|
|
1406
|
+
if (c.pure && !c.computed && c.accessor) {
|
|
1407
|
+
if (cascadeQueue.indexOf(c) === -1) cascadeQueue.push(c);
|
|
1408
|
+
} else if ((c.computed || !c.pure) && effectsToRun.indexOf(c) === -1)
|
|
1409
|
+
effectsToRun.push(c);
|
|
1410
|
+
}
|
|
1411
|
+
}
|
|
1412
|
+
Updates = null;
|
|
1413
|
+
for (const comp of effectsToRun)
|
|
1414
|
+
if (comp.computed || !comp.pure) updateComputation(comp);
|
|
1415
|
+
}
|
|
1416
|
+
function batch2(fn) {
|
|
1417
|
+
if (Updates && BatchDepth > 0) return fn();
|
|
1418
|
+
if (Updates && BatchDepth === 0) {
|
|
1419
|
+
const prev = Updates;
|
|
1420
|
+
const nested = [];
|
|
1421
|
+
Updates = nested;
|
|
1422
|
+
BatchDepth++;
|
|
1423
|
+
let result;
|
|
1424
|
+
try {
|
|
1425
|
+
result = fn();
|
|
1426
|
+
} finally {
|
|
1427
|
+
BatchDepth--;
|
|
1428
|
+
Updates = prev;
|
|
1429
|
+
}
|
|
1430
|
+
const savedUpdates = Updates;
|
|
1431
|
+
runCascadeAndEffects(nested);
|
|
1432
|
+
Updates = savedUpdates;
|
|
1433
|
+
return result;
|
|
1434
|
+
}
|
|
1435
|
+
BatchDepth++;
|
|
1436
|
+
Updates = [];
|
|
1437
|
+
Effects = [];
|
|
1438
|
+
try {
|
|
1439
|
+
return fn();
|
|
1440
|
+
} finally {
|
|
1441
|
+
BatchDepth--;
|
|
1442
|
+
flushUpdates();
|
|
1443
|
+
}
|
|
1444
|
+
}
|
|
1445
|
+
function flushUpdates() {
|
|
1446
|
+
if (Pending) return;
|
|
1447
|
+
Pending = true;
|
|
1448
|
+
ExecCount = 0;
|
|
1449
|
+
try {
|
|
1450
|
+
while (Updates && Updates.length > 0) {
|
|
1451
|
+
const updates = Updates;
|
|
1452
|
+
Updates = null;
|
|
1453
|
+
runCascadeAndEffects(updates);
|
|
1454
|
+
}
|
|
1455
|
+
Updates = null;
|
|
1456
|
+
if (Effects) {
|
|
1457
|
+
const effects = Effects;
|
|
1458
|
+
Effects = null;
|
|
1459
|
+
for (let i = 0; i < effects.length; i++) updateComputation(effects[i]);
|
|
1460
|
+
}
|
|
1461
|
+
} finally {
|
|
1462
|
+
Pending = false;
|
|
1463
|
+
}
|
|
1464
|
+
}
|
|
1465
|
+
function createRoot2(fn) {
|
|
1466
|
+
const owner = {
|
|
1467
|
+
owned: null,
|
|
1468
|
+
cleanups: null,
|
|
1469
|
+
contexts: null,
|
|
1470
|
+
owner: Owner
|
|
1471
|
+
};
|
|
1472
|
+
const prevListener = Listener;
|
|
1473
|
+
Listener = null;
|
|
1474
|
+
const prevOwner = Owner;
|
|
1475
|
+
Owner = owner;
|
|
1476
|
+
try {
|
|
1477
|
+
return fn(() => {
|
|
1478
|
+
if (owner.owned)
|
|
1479
|
+
for (let i = 0; i < owner.owned.length; i++) dispose(owner.owned[i]);
|
|
1480
|
+
if (owner.cleanups)
|
|
1481
|
+
for (let i = 0; i < owner.cleanups.length; i++) owner.cleanups[i]();
|
|
1482
|
+
});
|
|
1483
|
+
} finally {
|
|
1484
|
+
Owner = prevOwner;
|
|
1485
|
+
Listener = prevListener;
|
|
1486
|
+
}
|
|
1487
|
+
}
|
|
1488
|
+
function untrack2(fn) {
|
|
1489
|
+
const prevListener = Listener;
|
|
1490
|
+
Listener = null;
|
|
1491
|
+
try {
|
|
1492
|
+
return fn();
|
|
1493
|
+
} finally {
|
|
1494
|
+
Listener = prevListener;
|
|
1495
|
+
}
|
|
1496
|
+
}
|
|
1497
|
+
function onCleanup2(fn) {
|
|
1498
|
+
if (Owner) {
|
|
1499
|
+
if (!Owner.cleanups) Owner.cleanups = [fn];
|
|
1500
|
+
else Owner.cleanups.push(fn);
|
|
1501
|
+
}
|
|
1502
|
+
}
|
|
1503
|
+
function createResource(source, fetcherFn, options = {}) {
|
|
1504
|
+
let s;
|
|
1505
|
+
let fetcher;
|
|
1506
|
+
if (typeof fetcherFn === "function") {
|
|
1507
|
+
s = typeof source === "function" ? source : () => source;
|
|
1508
|
+
fetcher = fetcherFn;
|
|
1509
|
+
} else {
|
|
1510
|
+
s = () => true;
|
|
1511
|
+
fetcher = source;
|
|
1512
|
+
if (fetcherFn && typeof fetcherFn === "object") options = fetcherFn;
|
|
1513
|
+
}
|
|
1514
|
+
const { initialValue, name } = options;
|
|
1515
|
+
const __ssrId = options.transport === false ? void 0 : nextResourceId();
|
|
1516
|
+
const __seed = __ssrId !== void 0 ? getServerData(__ssrId) : void 0;
|
|
1517
|
+
let skipFirstFetch = __seed !== void 0;
|
|
1518
|
+
const [value, setValue] = createSignal2(
|
|
1519
|
+
__seed !== void 0 ? __seed.value : options.initialValue,
|
|
1520
|
+
{ equals: false }
|
|
1521
|
+
);
|
|
1522
|
+
const [error, setError] = createSignal2(void 0, { equals: false });
|
|
1523
|
+
const [state, setState] = createSignal2(
|
|
1524
|
+
__seed !== void 0 || options.initialValue !== void 0 ? "ready" : "unresolved",
|
|
1525
|
+
{ equals: false }
|
|
1526
|
+
);
|
|
1527
|
+
const [promise, setPromise] = createSignal2(
|
|
1528
|
+
void 0,
|
|
1529
|
+
{ equals: false }
|
|
1530
|
+
);
|
|
1531
|
+
const [track, trigger] = createSignal2(void 0, { equals: false });
|
|
1532
|
+
const UNSET = /* @__PURE__ */ Symbol();
|
|
1533
|
+
let prevKey = UNSET;
|
|
1534
|
+
let manualRefetch = false;
|
|
1535
|
+
const saveToCache = (data) => {
|
|
1536
|
+
if (typeof localStorage === "undefined") return;
|
|
1537
|
+
try {
|
|
1538
|
+
if (data)
|
|
1539
|
+
localStorage.setItem(
|
|
1540
|
+
"storage",
|
|
1541
|
+
JSON.stringify({ data, timestamp: Date.now() })
|
|
1542
|
+
);
|
|
1543
|
+
} catch (error2) {
|
|
1544
|
+
console.error(`Failed to save resource to cache (${name}):`, error2);
|
|
1545
|
+
}
|
|
1546
|
+
};
|
|
1547
|
+
const dispose2 = createEffect2(() => {
|
|
1548
|
+
const val = s ? s() : source;
|
|
1549
|
+
track();
|
|
1550
|
+
if (val === false || val === null || val === void 0) {
|
|
1551
|
+
prevKey = UNSET;
|
|
1552
|
+
batch2(() => {
|
|
1553
|
+
setState("unresolved");
|
|
1554
|
+
setPromise(void 0);
|
|
1555
|
+
setError(void 0);
|
|
1556
|
+
});
|
|
1557
|
+
return;
|
|
1558
|
+
}
|
|
1559
|
+
const isManual = manualRefetch;
|
|
1560
|
+
manualRefetch = false;
|
|
1561
|
+
if (prevKey !== UNSET && val === prevKey && !isManual) return;
|
|
1562
|
+
prevKey = val;
|
|
1563
|
+
if (skipFirstFetch) {
|
|
1564
|
+
skipFirstFetch = false;
|
|
1565
|
+
return;
|
|
1566
|
+
}
|
|
1567
|
+
let cancelled = false;
|
|
1568
|
+
onCleanup2(() => cancelled = true);
|
|
1569
|
+
const currentState = untrack2(state);
|
|
1570
|
+
const currentValue = untrack2(value);
|
|
1571
|
+
const isRefreshing = currentState === "ready" || currentState === "refreshing";
|
|
1572
|
+
batch2(() => {
|
|
1573
|
+
setState(isRefreshing ? "refreshing" : "pending");
|
|
1574
|
+
setError(void 0);
|
|
1575
|
+
});
|
|
1576
|
+
try {
|
|
1577
|
+
const res = fetcher(val, {
|
|
1578
|
+
value: currentValue,
|
|
1579
|
+
refetching: isRefreshing
|
|
1580
|
+
});
|
|
1581
|
+
if (isPromise(res)) {
|
|
1582
|
+
setPromise(res);
|
|
1583
|
+
trackResourcePromise(res);
|
|
1584
|
+
res.then(
|
|
1585
|
+
(v) => {
|
|
1586
|
+
if (cancelled) return;
|
|
1587
|
+
if (__ssrId !== void 0) reportResourceData(__ssrId, v);
|
|
1588
|
+
batch2(() => {
|
|
1589
|
+
setValue(() => v);
|
|
1590
|
+
saveToCache(v);
|
|
1591
|
+
setState("ready");
|
|
1592
|
+
setPromise(void 0);
|
|
1593
|
+
});
|
|
1594
|
+
},
|
|
1595
|
+
(e) => {
|
|
1596
|
+
if (cancelled) return;
|
|
1597
|
+
batch2(() => {
|
|
1598
|
+
setError(e);
|
|
1599
|
+
setState("errored");
|
|
1600
|
+
setPromise(void 0);
|
|
1601
|
+
});
|
|
1602
|
+
}
|
|
1603
|
+
).catch((e) => {
|
|
1604
|
+
if (cancelled) return;
|
|
1605
|
+
batch2(() => {
|
|
1606
|
+
setError(e);
|
|
1607
|
+
setState("errored");
|
|
1608
|
+
setPromise(void 0);
|
|
1609
|
+
});
|
|
1610
|
+
});
|
|
1611
|
+
const suspenseCtx = _SuspenseContext && useContext(_SuspenseContext);
|
|
1612
|
+
if (suspenseCtx) {
|
|
1613
|
+
suspenseCtx.increment();
|
|
1614
|
+
res.finally(() => suspenseCtx.decrement());
|
|
1615
|
+
}
|
|
1616
|
+
} else {
|
|
1617
|
+
if (cancelled) return;
|
|
1618
|
+
batch2(() => {
|
|
1619
|
+
setValue(() => res);
|
|
1620
|
+
setState("ready");
|
|
1621
|
+
setPromise(void 0);
|
|
1622
|
+
});
|
|
1623
|
+
}
|
|
1624
|
+
} catch (e) {
|
|
1625
|
+
if (cancelled) return;
|
|
1626
|
+
batch2(() => {
|
|
1627
|
+
setError(e);
|
|
1628
|
+
setState("errored");
|
|
1629
|
+
setPromise(void 0);
|
|
1630
|
+
});
|
|
1631
|
+
}
|
|
1632
|
+
});
|
|
1633
|
+
onCleanup2(dispose2);
|
|
1634
|
+
const loading = () => {
|
|
1635
|
+
const s2 = state();
|
|
1636
|
+
return s2 === "pending" || s2 === "refreshing";
|
|
1637
|
+
};
|
|
1638
|
+
const resource = (() => {
|
|
1639
|
+
const e = error();
|
|
1640
|
+
if (e) throw e;
|
|
1641
|
+
if (loading()) {
|
|
1642
|
+
const p = promise();
|
|
1643
|
+
if (p) throw p;
|
|
1644
|
+
}
|
|
1645
|
+
return value();
|
|
1646
|
+
});
|
|
1647
|
+
Object.defineProperty(resource, $RESOURCE2, { value: true, enumerable: true });
|
|
1648
|
+
Object.defineProperty(resource, $SIGNAL3, { value: true, enumerable: true });
|
|
1649
|
+
Object.defineProperties(resource, {
|
|
1650
|
+
state: { get: state },
|
|
1651
|
+
loading: { get: () => loading() },
|
|
1652
|
+
error: { get: error },
|
|
1653
|
+
latest: { get: value }
|
|
1654
|
+
});
|
|
1655
|
+
return [
|
|
1656
|
+
resource,
|
|
1657
|
+
{
|
|
1658
|
+
mutate: setValue,
|
|
1659
|
+
refetch: () => {
|
|
1660
|
+
manualRefetch = true;
|
|
1661
|
+
trigger(void 0);
|
|
1662
|
+
}
|
|
1663
|
+
}
|
|
1664
|
+
];
|
|
1665
|
+
}
|
|
1666
|
+
function getOwner2() {
|
|
1667
|
+
return Owner;
|
|
1668
|
+
}
|
|
1669
|
+
function runWithOwner2(owner, fn) {
|
|
1670
|
+
const prevOwner = Owner;
|
|
1671
|
+
const prevListener = Listener;
|
|
1672
|
+
Owner = owner;
|
|
1673
|
+
Listener = null;
|
|
1674
|
+
try {
|
|
1675
|
+
return fn();
|
|
1676
|
+
} finally {
|
|
1677
|
+
Owner = prevOwner;
|
|
1678
|
+
Listener = prevListener;
|
|
1679
|
+
}
|
|
1680
|
+
}
|
|
1681
|
+
function createContext(defaultValue) {
|
|
1682
|
+
const id = /* @__PURE__ */ Symbol("context");
|
|
1683
|
+
const Provider = createProvider(id);
|
|
1684
|
+
return { id, Provider, defaultValue };
|
|
1685
|
+
}
|
|
1686
|
+
function createProvider(id) {
|
|
1687
|
+
return (props) => {
|
|
1688
|
+
let _node = Owner;
|
|
1689
|
+
while (_node) {
|
|
1690
|
+
if (!_node.contexts) _node.contexts = /* @__PURE__ */ new Map();
|
|
1691
|
+
if (!_node.contexts.has(id)) _node.contexts.set(id, props.value);
|
|
1692
|
+
_node = _node.owner;
|
|
1693
|
+
}
|
|
1694
|
+
let provider;
|
|
1695
|
+
createRenderEffect(() => {
|
|
1696
|
+
provider = untrack2(() => {
|
|
1697
|
+
const owner = Owner;
|
|
1698
|
+
if (owner) {
|
|
1699
|
+
if (!owner.contexts) owner.contexts = /* @__PURE__ */ new Map();
|
|
1700
|
+
owner.contexts.set(id, props.value);
|
|
1701
|
+
}
|
|
1702
|
+
return readChildren(() => props.children);
|
|
1703
|
+
});
|
|
1704
|
+
});
|
|
1705
|
+
return provider;
|
|
1706
|
+
};
|
|
1707
|
+
}
|
|
1708
|
+
function useContext(context) {
|
|
1709
|
+
let owner = Owner;
|
|
1710
|
+
while (owner) {
|
|
1711
|
+
if (owner.contexts && owner.contexts.has(context.id))
|
|
1712
|
+
return owner.contexts.get(context.id);
|
|
1713
|
+
owner = owner.owner;
|
|
1714
|
+
}
|
|
1715
|
+
if (!context) return;
|
|
1716
|
+
return context.defaultValue;
|
|
1717
|
+
}
|
|
1718
|
+
function flush() {
|
|
1719
|
+
return new Promise((resolve) => {
|
|
1720
|
+
queueMicrotask(() => {
|
|
1721
|
+
flushUpdates();
|
|
1722
|
+
resolve();
|
|
1723
|
+
});
|
|
1724
|
+
});
|
|
1725
|
+
}
|
|
1726
|
+
function startTransition(fn) {
|
|
1727
|
+
if (Transition && Transition.running) {
|
|
1728
|
+
fn();
|
|
1729
|
+
return Transition.done;
|
|
1730
|
+
}
|
|
1731
|
+
ensureTransPending();
|
|
1732
|
+
let resolve;
|
|
1733
|
+
const done = new Promise((res) => resolve = res);
|
|
1734
|
+
const t = { running: true, effects: [], resolve, done };
|
|
1735
|
+
Transition = t;
|
|
1736
|
+
try {
|
|
1737
|
+
fn();
|
|
1738
|
+
} finally {
|
|
1739
|
+
t.running = false;
|
|
1740
|
+
}
|
|
1741
|
+
if (!t.effects.length) {
|
|
1742
|
+
Transition = null;
|
|
1743
|
+
resolve();
|
|
1744
|
+
return done;
|
|
1745
|
+
}
|
|
1746
|
+
_setTransPending(true);
|
|
1747
|
+
Promise.resolve().then(() => {
|
|
1748
|
+
const effects = t.effects.splice(0);
|
|
1749
|
+
Transition = null;
|
|
1750
|
+
_setTransPending(false);
|
|
1751
|
+
if (effects.length)
|
|
1752
|
+
batch2(() => {
|
|
1753
|
+
for (const e of effects) {
|
|
1754
|
+
e.state = DIRTY2;
|
|
1755
|
+
updateComputation(e);
|
|
1756
|
+
}
|
|
1757
|
+
});
|
|
1758
|
+
resolve();
|
|
1759
|
+
});
|
|
1760
|
+
return done;
|
|
1761
|
+
}
|
|
1762
|
+
function useTransition() {
|
|
1763
|
+
ensureTransPending();
|
|
1764
|
+
return [_transPending, startTransition];
|
|
1765
|
+
}
|
|
1766
|
+
function on(deps, fn, options) {
|
|
1767
|
+
const defer = options?.defer ?? false;
|
|
1768
|
+
let isFirst = true;
|
|
1769
|
+
return (prev) => {
|
|
1770
|
+
const values = deps();
|
|
1771
|
+
if (defer && isFirst) {
|
|
1772
|
+
isFirst = false;
|
|
1773
|
+
return prev;
|
|
1774
|
+
}
|
|
1775
|
+
return untrack2(() => fn(values, prev));
|
|
1776
|
+
};
|
|
1777
|
+
}
|
|
1778
|
+
function createRenderEffect(fn, value, options) {
|
|
1779
|
+
const c = {
|
|
1780
|
+
fn,
|
|
1781
|
+
state: DIRTY2,
|
|
1782
|
+
sources: null,
|
|
1783
|
+
sourceSlots: null,
|
|
1784
|
+
value,
|
|
1785
|
+
owned: null,
|
|
1786
|
+
cleanups: null,
|
|
1787
|
+
owner: Owner,
|
|
1788
|
+
contexts: null,
|
|
1789
|
+
pure: false,
|
|
1790
|
+
updatedAt: null,
|
|
1791
|
+
renderEffect: true
|
|
1792
|
+
};
|
|
1793
|
+
if (Owner) {
|
|
1794
|
+
if (!Owner.owned) Owner.owned = [c];
|
|
1795
|
+
else Owner.owned.push(c);
|
|
1796
|
+
}
|
|
1797
|
+
const SC = _SuspenseContext && useContext(_SuspenseContext);
|
|
1798
|
+
if (SC) c.suspense = SC;
|
|
1799
|
+
runRenderComputation(c);
|
|
1800
|
+
return () => dispose(c);
|
|
1801
|
+
}
|
|
1802
|
+
function runRenderComputation(c) {
|
|
1803
|
+
if (c.sources) {
|
|
1804
|
+
for (const source of c.sources) {
|
|
1805
|
+
const observers = signalObservers.get(source);
|
|
1806
|
+
if (observers) observers.delete(c);
|
|
1807
|
+
}
|
|
1808
|
+
c.sources = null;
|
|
1809
|
+
c.sourceSlots = null;
|
|
1810
|
+
}
|
|
1811
|
+
if (c.cleanups) {
|
|
1812
|
+
for (let i = 0; i < c.cleanups.length; i++) c.cleanups[i]();
|
|
1813
|
+
c.cleanups = null;
|
|
1814
|
+
}
|
|
1815
|
+
if (c.owned) {
|
|
1816
|
+
for (let i = 0; i < c.owned.length; i++) dispose(c.owned[i]);
|
|
1817
|
+
c.owned = null;
|
|
1818
|
+
}
|
|
1819
|
+
const prevListener = Listener;
|
|
1820
|
+
const prevOwner = Owner;
|
|
1821
|
+
const prevUpdates = Updates;
|
|
1822
|
+
Listener = c;
|
|
1823
|
+
Owner = c;
|
|
1824
|
+
if (Updates === null) Updates = [];
|
|
1825
|
+
c.state = RUNNING;
|
|
1826
|
+
try {
|
|
1827
|
+
const result = c.fn(c.value);
|
|
1828
|
+
if (typeof result === "function") {
|
|
1829
|
+
if (!c.cleanups) c.cleanups = [];
|
|
1830
|
+
c.cleanups.push(result);
|
|
1831
|
+
}
|
|
1832
|
+
c.value = result;
|
|
1833
|
+
if (c.state === RUNNING) c.state = CLEAN2;
|
|
1834
|
+
} catch (err) {
|
|
1835
|
+
if (isPromise(err)) {
|
|
1836
|
+
const ctx = _SuspenseContext && useContext(_SuspenseContext);
|
|
1837
|
+
if (ctx) {
|
|
1838
|
+
ctx.increment();
|
|
1839
|
+
err.finally(() => ctx.decrement());
|
|
1840
|
+
if (c.suspense) ctx.effects.push(c);
|
|
1841
|
+
}
|
|
1842
|
+
return;
|
|
1843
|
+
}
|
|
1844
|
+
handleError(err);
|
|
1845
|
+
} finally {
|
|
1846
|
+
Listener = prevListener;
|
|
1847
|
+
Owner = prevOwner;
|
|
1848
|
+
const deferred = Updates;
|
|
1849
|
+
Updates = prevUpdates;
|
|
1850
|
+
if (deferred !== prevUpdates && deferred && deferred.length > 0) {
|
|
1851
|
+
const saved = Updates;
|
|
1852
|
+
runCascadeAndEffects(deferred);
|
|
1853
|
+
Updates = saved;
|
|
1854
|
+
}
|
|
1855
|
+
}
|
|
1856
|
+
}
|
|
1857
|
+
function createComputed(fn, value, options) {
|
|
1858
|
+
const c = {
|
|
1859
|
+
fn,
|
|
1860
|
+
state: DIRTY2,
|
|
1861
|
+
sources: null,
|
|
1862
|
+
sourceSlots: null,
|
|
1863
|
+
value,
|
|
1864
|
+
owned: null,
|
|
1865
|
+
cleanups: null,
|
|
1866
|
+
owner: Owner,
|
|
1867
|
+
contexts: null,
|
|
1868
|
+
pure: true,
|
|
1869
|
+
computed: true,
|
|
1870
|
+
updatedAt: null
|
|
1871
|
+
};
|
|
1872
|
+
if (Owner) {
|
|
1873
|
+
if (!Owner.owned) Owner.owned = [c];
|
|
1874
|
+
else Owner.owned.push(c);
|
|
1875
|
+
}
|
|
1876
|
+
if (Transition && Transition.running) {
|
|
1877
|
+
if (!Updates) Updates = [];
|
|
1878
|
+
if (Updates.indexOf(c) === -1) Updates.push(c);
|
|
1879
|
+
} else if (Updates) {
|
|
1880
|
+
if (Updates.indexOf(c) === -1) Updates.push(c);
|
|
1881
|
+
} else runComputation(c, value);
|
|
1882
|
+
}
|
|
1883
|
+
var _SuspenseContext;
|
|
1884
|
+
function getSuspenseContext() {
|
|
1885
|
+
return _SuspenseContext || (_SuspenseContext = createContext());
|
|
1886
|
+
}
|
|
1887
|
+
var _SuspenseListContext;
|
|
1888
|
+
function getSuspenseListContext() {
|
|
1889
|
+
return _SuspenseListContext || (_SuspenseListContext = createContext());
|
|
1890
|
+
}
|
|
1891
|
+
function resumeEffects(effects) {
|
|
1892
|
+
if (!effects.length) return;
|
|
1893
|
+
const queued = effects.slice();
|
|
1894
|
+
effects.length = 0;
|
|
1895
|
+
for (const c of queued) {
|
|
1896
|
+
c.state = DIRTY2;
|
|
1897
|
+
updateComputation(c);
|
|
1898
|
+
}
|
|
1899
|
+
}
|
|
1900
|
+
function onResolve(fn) {
|
|
1901
|
+
const ctx = _SuspenseContext && useContext(_SuspenseContext);
|
|
1902
|
+
if (ctx && ctx.inFallback())
|
|
1903
|
+
createEffect2(() => {
|
|
1904
|
+
if (!ctx.inFallback()) fn();
|
|
1905
|
+
});
|
|
1906
|
+
else fn();
|
|
1907
|
+
}
|
|
1908
|
+
function setScheduler2(scheduler) {
|
|
1909
|
+
Scheduler = scheduler;
|
|
1910
|
+
}
|
|
1911
|
+
function trackPromise(promise) {
|
|
1912
|
+
const ctx = _SuspenseContext && useContext(_SuspenseContext);
|
|
1913
|
+
if (!ctx) return promise;
|
|
1914
|
+
ctx.increment();
|
|
1915
|
+
promise.finally(() => ctx.decrement());
|
|
1916
|
+
return promise;
|
|
1917
|
+
}
|
|
1918
|
+
var signal_default = {
|
|
1919
|
+
createSignal: createSignal2,
|
|
1920
|
+
createEffect: createEffect2,
|
|
1921
|
+
createMemo: createMemo2,
|
|
1922
|
+
createComputed,
|
|
1923
|
+
createRoot: createRoot2,
|
|
1924
|
+
createSelector,
|
|
1925
|
+
createResource,
|
|
1926
|
+
batch: batch2,
|
|
1927
|
+
untrack: untrack2,
|
|
1928
|
+
onCleanup: onCleanup2,
|
|
1929
|
+
getOwner: getOwner2,
|
|
1930
|
+
runWithOwner: runWithOwner2,
|
|
1931
|
+
createContext,
|
|
1932
|
+
useContext,
|
|
1933
|
+
flush,
|
|
1934
|
+
startTransition,
|
|
1935
|
+
useTransition,
|
|
1936
|
+
isSignal,
|
|
1937
|
+
on,
|
|
1938
|
+
createRenderEffect,
|
|
1939
|
+
getSuspenseContext,
|
|
1940
|
+
getSuspenseListContext,
|
|
1941
|
+
resumeEffects,
|
|
1942
|
+
onResolve,
|
|
1943
|
+
setScheduler: setScheduler2,
|
|
1944
|
+
trackPromise
|
|
1945
|
+
};
|
|
1946
|
+
export {
|
|
1947
|
+
$MEMO3 as $MEMO,
|
|
1948
|
+
$PROXY,
|
|
1949
|
+
$RESOURCE2 as $RESOURCE,
|
|
1950
|
+
$SIGNAL3 as $SIGNAL,
|
|
1951
|
+
__DEV__,
|
|
1952
|
+
batch2 as batch,
|
|
1953
|
+
createComputed,
|
|
1954
|
+
createContext,
|
|
1955
|
+
createDebounce,
|
|
1956
|
+
createDeferred,
|
|
1957
|
+
createEffect2 as createEffect,
|
|
1958
|
+
createMemo2 as createMemo,
|
|
1959
|
+
createProvider,
|
|
1960
|
+
createRenderEffect,
|
|
1961
|
+
createResource,
|
|
1962
|
+
createRoot2 as createRoot,
|
|
1963
|
+
createSelector,
|
|
1964
|
+
createSignal2 as createSignal,
|
|
1965
|
+
signal_default as default,
|
|
1966
|
+
flush,
|
|
1967
|
+
getOwner2 as getOwner,
|
|
1968
|
+
getServerData,
|
|
1969
|
+
getSharedConfig,
|
|
1970
|
+
getSuspenseContext,
|
|
1971
|
+
getSuspenseListContext,
|
|
1972
|
+
isComponent,
|
|
1973
|
+
isMemo,
|
|
1974
|
+
isProvider,
|
|
1975
|
+
isResource,
|
|
1976
|
+
isSignal,
|
|
1977
|
+
isSuspense,
|
|
1978
|
+
makeArrayFlat,
|
|
1979
|
+
nextResourceId,
|
|
1980
|
+
on,
|
|
1981
|
+
onCleanup2 as onCleanup,
|
|
1982
|
+
onResolve,
|
|
1983
|
+
readChildren,
|
|
1984
|
+
reportResourceData,
|
|
1985
|
+
resumeEffects,
|
|
1986
|
+
runWithOwner2 as runWithOwner,
|
|
1987
|
+
setOwner2 as setOwner,
|
|
1988
|
+
setResourceDataSink,
|
|
1989
|
+
setResourceIdSource,
|
|
1990
|
+
setResourceTracker,
|
|
1991
|
+
setScheduler2 as setScheduler,
|
|
1992
|
+
setServerDataGetter,
|
|
1993
|
+
sharedConfig,
|
|
1994
|
+
startTransition,
|
|
1995
|
+
trackPromise,
|
|
1996
|
+
trackResourcePromise,
|
|
1997
|
+
untrack2 as untrack,
|
|
1998
|
+
useContext,
|
|
1999
|
+
useTransition
|
|
2000
|
+
};
|