@fluixi/reactive 1.0.0-alpha.83 → 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/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 +33 -31
- 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 +38 -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 -1
- package/dist/lib/signal/graph/observe.d.ts +8 -8
- package/dist/lib/signal/graph/observe.js +5 -5
- package/dist/lib/signal/graph/observe.mjs +140 -1
- 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 +7 -7
- package/dist/lib/signal/graph/runtime.d.ts.map +1 -1
- package/dist/lib/signal/graph/runtime.js +34 -30
- 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 +41 -10
- package/dist/lib/signal/graph/state.d.ts.map +1 -1
- package/dist/lib/signal/graph/state.js +83 -22
- 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 +3 -2
- package/dist/lib/signal/index.d.ts.map +1 -1
- package/dist/lib/signal/index.js +7 -4
- 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 +5 -5
- 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 +148 -5
- 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,672 @@
|
|
|
1
|
-
"use strict";var ce=Object.defineProperty;var nn=Object.getOwnPropertyDescriptor;var tn=Object.getOwnPropertyNames;var rn=Object.prototype.hasOwnProperty;var on=(e,n)=>{for(var t in n)ce(e,t,{get:n[t],enumerable:!0})},sn=(e,n,t,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of tn(n))!rn.call(e,r)&&r!==t&&ce(e,r,{get:()=>n[r],enumerable:!(o=nn(n,r))||o.enumerable});return e};var un=e=>sn(ce({},"__esModule",{value:!0}),e);var Mn={};on(Mn,{clearAllCachedResources:()=>Ln,clearCachedResourceNamespace:()=>Un,createCachedResource:()=>In});module.exports=un(Mn);function fe(e){return typeof e=="function"&&!/^class\s/.test(Function.prototype.toString.call(e))}function ke(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 de(e){return e instanceof Promise||!!e&&(typeof e=="object"||typeof e=="function")&&"then"in e}var j=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(fe(o)&&!(o instanceof e))try{o()}catch(r){console.error("Error in unsubscribe function:",r)}else if(ke(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(fe(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 K=class extends j{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 K{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 Y=class extends j{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 K?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 an=typeof window>"u"?!1:window.__FLUIXI_PROD__===!0,X=typeof process>"u"?an:!1,ln=Symbol.for("signal");function ve(e){return typeof e=="function"&&e[ln]===!0}var cn="__fluixi_signal_next_state__",fn=e=>{typeof queueMicrotask=="function"?queueMicrotask(e):Promise.resolve().then(e)},a=globalThis[cn]??={consumer:null,untracked:!1,owner:null,queue:[],scheduled:!1,flushing:!1,batchDepth:0,hostSchedule:fn,onSuspend:null,onError:null,observer:null};var _e="1.0.0-alpha.83";function dn(e){return a.observer=e,()=>{a.observer===e&&(a.observer=null)}}var he=[],pn;function Ee(e){let n=a.observer;n&&n.created(e.parents===void 0?{...e,parents:he,origin:e.origin??pn}:e)}function Pe(e){return a.observer?(he.push(e),!0):!1}function Fe(){he.pop()}function De(e){a.observer?.ran?.(e)}function qe(e){a.observer?.disposed?.(e)}var vn="__FLUIXI_DEVTOOLS_HOOK__",Ae=globalThis[vn];if(typeof Ae?.inject=="function")try{Ae.inject({observeReactiveNodes:dn,version:_e})}catch{}function Ne(){return a.observer!=null}var Ie=0,Ue=1,J=2,be=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))}};var Q=class extends be{constructor(t,o){super();this._threw=!1;this._initialized=!1;this.state=J;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===Ue&&this.sources){for(let t of this.sources)if(t.updateIfNecessary(),this.state===J)break}(this.state===J||!this._initialized)&&this.recompute(),this.state=Ie}recompute(){if(this.sources){for(let v of this.sources)v.observers?.delete(this);this.sources.clear()}let t=a.consumer,o=a.untracked,r=Pe(this);a.consumer=this,a.untracked=!1;let s,l=!1,d;try{s=this._fn()}catch(v){l=!0,d=v,s=this._value}finally{a.consumer=t,a.untracked=o,r&&Fe()}let b=!this._initialized||this._threw!==l||(l?d!==this._error:!this._equals(this._value,s));if(this._initialized=!0,this._threw=l,this._error=d,this._value=s,De(this),b){if(this.version++,this.observers)for(let v of[...this.observers])v.markDirty(J);Le(this)}}markDirty(t){if(this.state>=t)return;let o=this.state===Ie;if(this.state=t,o){if(this.observers)for(let r of[...this.observers])r.markDirty(Ue);Le(this)}}peek(){if(this.updateIfNecessary(),this._threw)throw this._error;return this._value}};function Le(e){if(e.watchers)for(let n of[...e.watchers])n._notify(e)}function Me(e){return a.onSuspend?(a.onSuspend(e,a.owner),!0):!1}function Be(){return a.owner}function je(e,n){let t=a.owner;a.owner=e;try{return n()}finally{a.owner=t}}function Ve(e){if(a.owner){if(a.owner.disposed){e();return}(a.owner.cleanups??=[]).push(e)}}function Ge(e){a.hostSchedule=e??(n=>{Promise.resolve().then(n)})}function hn(e){return!!e&&typeof e.then=="function"}Ge(()=>{});var bn=Symbol.for("signal"),Tn=Symbol.for("memo");function Z(e,n,t){let o=n,r=Be(),s=new Q(()=>je(r,()=>{try{return o=e(o)}catch(d){if(hn(d))return Me(d),o;throw d}}),{equals:t?.equals}),l=(()=>s.get());return Object.defineProperty(l,bn,{value:!0,enumerable:!0}),Object.defineProperty(l,Tn,{value:!0,enumerable:!0}),Ee({kind:"memo",node:s,handle:l,name:t?.name}),Ne()&&Ve(()=>qe(s)),l}function ee(e){if(typeof e=="function"&&!e.length){let n=e();return ve(n)?n:ee(n)}if(Array.isArray(e)){let n=[];for(let t=0;t<e.length;t++){let o=ee(e[t]);Array.isArray(o)?n.push.apply(n,o):n.push(o)}return n}return e}function $e(e){let n=Z(e);return X?Z(()=>ee(n()),void 0,{name:"children"}):Z(()=>ee(n()))}var We=null;function Te(e){We&&We(e)}var yn=Symbol.for("signal");var He=Symbol("fluixi-proxy"),mn=Symbol.for("signal-node"),V=0,me=1,oe=2,I=3,f=null,h=null,i=null,te=null,re=0,wn=!1,ye=!1,N=0,xn=1e6,O=new WeakMap,ne=null;var gn=new Map,Sn=0;function On(){return`node_${++Sn}_${Date.now()}`}function Rn(e){X&&gn.set(e.id,new WeakRef(e))}function Cn(e,n,t){let o={id:On(),type:e,value:n,version:0,equals:t?.equals,name:t?.name,created:Date.now(),updated:Date.now()};return Rn(o),o}function kn(e,n){return e===n}function Ke(e){throw typeof console<"u"&&console.error("Reactive error:",e),e}function _n(e){if(i)i.indexOf(e)===-1&&i.push(e);else if(ne&&ne.running&&!e.pure)ne.effects.indexOf(e)===-1&&ne.effects.push(e);else if(!e.pure||e.computed)xe(e);else if(e.pure&&!e.computed&&e.accessor){let n=h,t=i;h=null,i=[],e.accessor(),h=n;let o=i;if(i=t,o.length>0){let r=i;se(o),i=r}}}function ze(e,n){for(let t=0;t<e.length;t++)n(e[t])}function C(e,n){let t=e;typeof t=="object"&&t&&He in t&&delete t[He];let o=Cn("signal",t,{equals:n?.equals===!1?void 0:n?.equals,name:n?.name}),r=[l,d];O.set(r,new Set);let s;function l(){let b=h;if(b){b.sources?b.sources.indexOf(r)===-1&&b.sources.push(r):b.sources=[r];let v=O.get(r);v&&!v.has(b)&&v.add(b)}return t}function d(b){let v=typeof b=="function"?b(t):b,B=o.equals||kn;if(n?.equals===!1||!B(t,v)){t=v,o.value=v,o.version++,o.updated=Date.now();let R=O.get(r);if(R&&R.size>0){let P=function(c,ie=!1){let m=c.state;if(!(m===I&&c===h)){if(ie&&!c.pure){m===V&&(c.state=me,wn&&(i!==null&&i.indexOf(c)===-1?i.push(c):x.push(c)));return}if(!g.has(c)&&(g.add(c),c.state=oe,m===V||m===me?x.push(c):!c.pure&&i!==null&&i.indexOf(c)===-1&&i.push(c),c.pure&&c.accessor)){let $=O.get(c.accessor);$&&ze(Array.from($),F=>P(F,!0))}}};var G=P;let E=Array.from(R),x=[],g=new Set;ze(E,P);for(let c of x)_n(c)}}}return l.toObservable=()=>new Y(b=>{let v=!0;return we(()=>{let G=l();v?v=!1:b.next(G)})}),Object.defineProperty(l,yn,{value:!0,enumerable:!0}),Object.defineProperty(l,mn,{value:o,enumerable:!1}),r}function we(e,n,t){let o={fn:e,state:oe,sources:null,sourceSlots:null,owned:null,cleanups:null,owner:f,contexts:null,pure:!1,updatedAt:null};f&&(f.owned?f.owned.push(o):f.owned=[o]);let r=w&&M(w);return r&&(o.suspense=r),Ye(o,n),()=>U(o)}function Ye(e,n){if(e.sources){for(let r of e.sources){let s=O.get(r);s&&s.delete(e)}e.sources=null,e.sourceSlots=null}if(e.owned){for(let r=0;r<e.owned.length;r++)U(e.owned[r]);e.owned=null}let t=h,o=f;if(h=e,f=e,re++,re>xn)throw re=0,h=t,f=o,new Error("Potential infinite loop detected. Exceeded maximum iterations.");try{e.state=I;let r=e.fn(n);typeof r=="function"&&(e.cleanups?e.cleanups.push(r):e.cleanups=[r]),e.state===I&&(e.state=V)}catch(r){if(de(r)){let s=w&&M(w);s&&(s.increment(),r.finally(()=>s.decrement()),e.suspense&&s.effects.push(e));return}Ke(r)}finally{h=t,f=o}}function xe(e){if(!(e.disposed||!e.fn||e.state===V)&&(e.state===oe||e.state===me||e.state===I)){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++)U(e.owned[n]);e.owned=null}e.renderEffect?Je(e):Ye(e,e.value)}}function U(e){if(e.disposed=!0,e.sources)for(let n of e.sources){let t=O.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++)U(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 se(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=O.get(r.accessor);if(s&&s.size>0){let d=h;h=null,r.accessor(),h=d}let l=i.splice(0);for(let d of l)d.pure&&!d.computed&&d.accessor?n.indexOf(d)===-1&&n.push(d):(d.computed||!d.pure)&&t.indexOf(d)===-1&&t.push(d)}i=null;for(let r of t)(r.computed||!r.pure)&&xe(r)}function k(e){if(i&&N>0)return e();if(i&&N===0){let n=i,t=[];i=t,N++;let o;try{o=e()}finally{N--,i=n}let r=i;return se(t),i=r,o}N++,i=[],te=[];try{return e()}finally{N--,An()}}function An(){if(!ye){ye=!0,re=0;try{for(;i&&i.length>0;){let e=i;i=null,se(e)}if(i=null,te){let e=te;te=null;for(let n=0;n<e.length;n++)xe(e[n])}}finally{ye=!1}}}function L(e){let n=h;h=null;try{return e()}finally{h=n}}function Xe(e){f&&(f.cleanups?f.cleanups.push(e):f.cleanups=[e])}function En(e){let n=Symbol("context"),t=Pn(n);return{id:n,Provider:t,defaultValue:e}}function Pn(e){return n=>{let t=f;for(;t;)t.contexts||(t.contexts=new Map),t.contexts.has(e)||t.contexts.set(e,n.value),t=t.owner;let o;return Fn(()=>{o=L(()=>{let r=f;return r&&(r.contexts||(r.contexts=new Map),r.contexts.set(e,n.value)),$e(()=>n.children)})}),o}}function M(e){let n=f;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 Fn(e,n,t){let o={fn:e,state:oe,sources:null,sourceSlots:null,value:n,owned:null,cleanups:null,owner:f,contexts:null,pure:!1,updatedAt:null,renderEffect:!0};f&&(f.owned?f.owned.push(o):f.owned=[o]);let r=w&&M(w);return r&&(o.suspense=r),Je(o),()=>U(o)}function Je(e){if(e.sources){for(let r of e.sources){let s=O.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++)U(e.owned[r]);e.owned=null}let n=h,t=f,o=i;h=e,f=e,i===null&&(i=[]),e.state=I;try{let r=e.fn(e.value);typeof r=="function"&&(e.cleanups||(e.cleanups=[]),e.cleanups.push(r)),e.value=r,e.state===I&&(e.state=V)}catch(r){if(de(r)){let s=w&&M(w);s&&(s.increment(),r.finally(()=>s.decrement()),e.suspense&&s.effects.push(e));return}Ke(r)}finally{h=n,f=t;let r=i;if(i=o,r!==o&&r&&r.length>0){let s=i;se(r),i=s}}}var w;function Qe(){return w||(w=En())}var A=new Map,_=new Map,Dn=0,qn=Symbol.for("signal"),Nn=Symbol.for("resource");function In(e,n,t={}){let o,r,s;typeof n=="function"?(o=e,r=n,s=t):(o=()=>!0,r=e,s=n??t);let{ttl:l=1/0,name:d=`_auto_${Dn++}`,staleWhileRevalidate:b=!0}=s,v=d,B=u=>`${v}:${JSON.stringify(u)}`,G=u=>l===1/0||Date.now()-u.timestamp<=l,[R,E]=C(void 0,{equals:!1}),[x,g]=C("unresolved",{equals:!1}),[P,c]=C(void 0,{equals:!1}),[ie,m]=C(void 0,{equals:!1}),[$,F]=C(!1),[Ze,ge]=C(0,{equals:!1}),ue=Symbol("unset"),W=ue,ae=!1,le=!1;function Se(u,T,y,S){if(_.has(T)){_.get(T).then(p=>{S()||Oe(p,y)},p=>{!S()&&!y&&Re(p)}),y||m(_.get(T));return}let D=Promise.resolve(r(u)).then(p=>(A.set(T,{value:p,timestamp:Date.now()}),_.delete(T),p),p=>{throw _.delete(T),p});if(_.set(T,D),!y){Te(D),m(D);let p=H&&M(H);p&&(p.increment(),D.finally(()=>p.decrement()))}D.then(p=>{S()||Oe(p,y)},p=>{!S()&&!y&&Re(p)})}function Oe(u,T){k(()=>{E(()=>u),g("ready"),F(!1),m(void 0),c(void 0)})}function Re(u){k(()=>{c(u),g("errored"),m(void 0)})}let H;we(()=>{H===void 0&&(H=Qe());let u=o();if(Ze(),u===!1||u===null||u===void 0){W=ue,k(()=>{g("unresolved"),m(void 0),c(void 0)});return}let T=ae,y=le;ae=!1,le=!1;let S=B(u);y&&A.delete(S);let D=W===ue||u!==W;W=u;let p=!1;Xe(()=>{p=!0});let q=A.get(S);if(q&&G(q)&&!T&&!y){(L(x)!=="ready"||L(R)!==q.value)&&k(()=>{E(()=>q.value),g("ready"),F(!1),c(void 0)});return}if(q&&b&&!y){k(()=>{E(()=>q.value),g("ready"),F(!0),c(void 0),m(void 0)}),Se(u,S,!0,()=>p);return}let Ce=L(x),en=Ce==="ready"||Ce==="refreshing";k(()=>{g(en?"refreshing":"pending"),c(void 0),F(!1)}),Se(u,S,!1,()=>p)});let z=(()=>{let u=P();if(u)throw u;if(x()==="pending"){let y=ie();if(y)throw y}return R()});return Object.defineProperty(z,Nn,{value:!0,enumerable:!0}),Object.defineProperty(z,qn,{value:!0,enumerable:!0}),Object.defineProperties(z,{state:{get:x},loading:{get:()=>{let u=x();return u==="pending"||u==="refreshing"}},error:{get:P},latest:{get:R},stale:{get:$}}),[z,{mutate:E,refetch:()=>{ae=!0,ge(u=>u+1)},invalidate:()=>{let u=L(o);u!=null&&u!==!1&&A.delete(B(u)),le=!0,ge(T=>T+1)}}]}function Un(e){let n=`${e}:`;for(let t of A.keys())t.startsWith(n)&&A.delete(t)}function Ln(){A.clear(),_.clear()}
|
|
1
|
+
/*! @fluixi/reactive v1.0.0-alpha.84 | (c) 2026 Ibrahima Touré and Fluixi contributors | MIT */
|
|
2
|
+
"use strict";
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// src/lib/signal/cached-resource.ts
|
|
22
|
+
var cached_resource_exports = {};
|
|
23
|
+
__export(cached_resource_exports, {
|
|
24
|
+
clearAllCachedResources: () => clearAllCachedResources,
|
|
25
|
+
clearCachedResourceNamespace: () => clearCachedResourceNamespace,
|
|
26
|
+
createCachedResource: () => createCachedResource
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(cached_resource_exports);
|
|
29
|
+
|
|
30
|
+
// src/version.generated.ts
|
|
31
|
+
var VERSION = "1.0.0-alpha.84";
|
|
32
|
+
|
|
33
|
+
// src/lib/signal/graph/state.ts
|
|
34
|
+
var MAJOR = VERSION.split(".")[0];
|
|
35
|
+
var KEY = `__fluixi_signal_state_v${MAJOR}__`;
|
|
36
|
+
var VERSIONS_KEY = `__fluixi_signal_builds_v${MAJOR}__`;
|
|
37
|
+
var defaultSchedule = (run) => {
|
|
38
|
+
if (typeof queueMicrotask === "function") queueMicrotask(run);
|
|
39
|
+
else void Promise.resolve().then(run);
|
|
40
|
+
};
|
|
41
|
+
function defaults() {
|
|
42
|
+
return {
|
|
43
|
+
consumer: null,
|
|
44
|
+
untracked: false,
|
|
45
|
+
owner: null,
|
|
46
|
+
queue: [],
|
|
47
|
+
scheduled: false,
|
|
48
|
+
flushing: false,
|
|
49
|
+
batchDepth: 0,
|
|
50
|
+
hostSchedule: defaultSchedule,
|
|
51
|
+
onSuspend: null,
|
|
52
|
+
onError: null,
|
|
53
|
+
observer: null
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
var realm = globalThis;
|
|
57
|
+
function backfillState(existing) {
|
|
58
|
+
const fresh = defaults();
|
|
59
|
+
const target = existing;
|
|
60
|
+
for (const field of Object.keys(fresh)) {
|
|
61
|
+
if (!(field in existing)) target[field] = fresh[field];
|
|
62
|
+
}
|
|
63
|
+
return existing;
|
|
64
|
+
}
|
|
65
|
+
function claim() {
|
|
66
|
+
const existing = realm[KEY];
|
|
67
|
+
return existing ? backfillState(existing) : realm[KEY] = defaults();
|
|
68
|
+
}
|
|
69
|
+
var G = claim();
|
|
70
|
+
(realm[VERSIONS_KEY] ??= []).push(VERSION);
|
|
71
|
+
|
|
72
|
+
// src/lib/signal/graph/observe.ts
|
|
73
|
+
function observeReactiveNodes(next) {
|
|
74
|
+
G.observer = next;
|
|
75
|
+
return () => {
|
|
76
|
+
if (G.observer === next) G.observer = null;
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
var running = [];
|
|
80
|
+
var origin;
|
|
81
|
+
function reportReactiveNode(report) {
|
|
82
|
+
const observer = G.observer;
|
|
83
|
+
if (observer) {
|
|
84
|
+
observer.created(
|
|
85
|
+
report.parents === void 0 ? { ...report, parents: running, origin: report.origin ?? origin } : report
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
function enterReactiveRun(node) {
|
|
90
|
+
if (!G.observer) return false;
|
|
91
|
+
running.push(node);
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
function exitReactiveRun() {
|
|
95
|
+
running.pop();
|
|
96
|
+
}
|
|
97
|
+
function reportReactiveRun(node) {
|
|
98
|
+
G.observer?.ran?.(node);
|
|
99
|
+
}
|
|
100
|
+
function reportReactiveWrite(node, by) {
|
|
101
|
+
G.observer?.wrote?.(node, by);
|
|
102
|
+
}
|
|
103
|
+
function reportReactiveDispose(node) {
|
|
104
|
+
G.observer?.disposed?.(node);
|
|
105
|
+
}
|
|
106
|
+
var HOOK = "__FLUIXI_DEVTOOLS_HOOK__";
|
|
107
|
+
var hook = globalThis[HOOK];
|
|
108
|
+
if (typeof hook?.inject === "function") {
|
|
109
|
+
try {
|
|
110
|
+
hook.inject({ observeReactiveNodes, version: VERSION });
|
|
111
|
+
} catch {
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
function isObserved() {
|
|
115
|
+
return G.observer != null;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// src/lib/signal/graph/core.ts
|
|
119
|
+
var CLEAN = 0;
|
|
120
|
+
var CHECK = 1;
|
|
121
|
+
var DIRTY = 2;
|
|
122
|
+
var Source = class {
|
|
123
|
+
constructor() {
|
|
124
|
+
/** Computeds, and watched leaves, that read this node. */
|
|
125
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
126
|
+
this.observers = null;
|
|
127
|
+
/** Watchers eagerly observing this node, which is how `runtime.ts` schedules effects. */
|
|
128
|
+
this.watchers = null;
|
|
129
|
+
/** Bumped whenever this node's value actually changes (equality-gated). */
|
|
130
|
+
this.version = 0;
|
|
131
|
+
}
|
|
132
|
+
/** Settle this node so a reader sees a current value/version. Overridden by Computed. */
|
|
133
|
+
updateIfNecessary() {
|
|
134
|
+
}
|
|
135
|
+
/** Link the current consumer (if any) as an observer of this node. */
|
|
136
|
+
track() {
|
|
137
|
+
if (G.untracked) return;
|
|
138
|
+
const consumer = G.consumer;
|
|
139
|
+
if (!consumer) return;
|
|
140
|
+
(this.observers ??= /* @__PURE__ */ new Set()).add(consumer);
|
|
141
|
+
(consumer.sources ??= /* @__PURE__ */ new Set()).add(this);
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
var State = class extends Source {
|
|
145
|
+
constructor(value, options) {
|
|
146
|
+
super();
|
|
147
|
+
this._value = value;
|
|
148
|
+
this._equals = options?.equals === false ? () => false : options?.equals ?? Object.is;
|
|
149
|
+
}
|
|
150
|
+
get() {
|
|
151
|
+
this.track();
|
|
152
|
+
return this._value;
|
|
153
|
+
}
|
|
154
|
+
set(next) {
|
|
155
|
+
if (this._equals(this._value, next)) return;
|
|
156
|
+
this._value = next;
|
|
157
|
+
this.version++;
|
|
158
|
+
reportReactiveWrite(this, G.consumer);
|
|
159
|
+
if (this.observers) for (const o of [...this.observers]) o.markDirty(DIRTY);
|
|
160
|
+
notifyWatchers(this);
|
|
161
|
+
}
|
|
162
|
+
/** Read without subscribing (peek). */
|
|
163
|
+
peek() {
|
|
164
|
+
return this._value;
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
var Computed = class extends Source {
|
|
168
|
+
constructor(fn, options) {
|
|
169
|
+
super();
|
|
170
|
+
this._threw = false;
|
|
171
|
+
this._initialized = false;
|
|
172
|
+
this.state = DIRTY;
|
|
173
|
+
/** Nodes this computation read on its last run. Rebuilt on every run. */
|
|
174
|
+
this.sources = null;
|
|
175
|
+
this._fn = fn;
|
|
176
|
+
this._equals = options?.equals === false ? () => false : options?.equals ?? Object.is;
|
|
177
|
+
}
|
|
178
|
+
get() {
|
|
179
|
+
if (G.consumer === this) {
|
|
180
|
+
throw new Error("Signal.Computed cannot read itself");
|
|
181
|
+
}
|
|
182
|
+
this.track();
|
|
183
|
+
this.updateIfNecessary();
|
|
184
|
+
if (this._threw) throw this._error;
|
|
185
|
+
return this._value;
|
|
186
|
+
}
|
|
187
|
+
/** Settle, if CHECK, verify sources; if DIRTY (or never run), recompute. */
|
|
188
|
+
updateIfNecessary() {
|
|
189
|
+
if (this.state === CHECK) {
|
|
190
|
+
if (this.sources) {
|
|
191
|
+
for (const s of this.sources) {
|
|
192
|
+
s.updateIfNecessary();
|
|
193
|
+
if (this.state === DIRTY) break;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
if (this.state === DIRTY || !this._initialized) this.recompute();
|
|
198
|
+
this.state = CLEAN;
|
|
199
|
+
}
|
|
200
|
+
recompute() {
|
|
201
|
+
if (this.sources) {
|
|
202
|
+
for (const s of this.sources) s.observers?.delete(this);
|
|
203
|
+
this.sources.clear();
|
|
204
|
+
}
|
|
205
|
+
const prevConsumer = G.consumer;
|
|
206
|
+
const prevUntracked = G.untracked;
|
|
207
|
+
const watched = enterReactiveRun(this);
|
|
208
|
+
G.consumer = this;
|
|
209
|
+
G.untracked = false;
|
|
210
|
+
let next;
|
|
211
|
+
let threw = false;
|
|
212
|
+
let err;
|
|
213
|
+
try {
|
|
214
|
+
next = this._fn();
|
|
215
|
+
} catch (e) {
|
|
216
|
+
threw = true;
|
|
217
|
+
err = e;
|
|
218
|
+
next = this._value;
|
|
219
|
+
} finally {
|
|
220
|
+
G.consumer = prevConsumer;
|
|
221
|
+
G.untracked = prevUntracked;
|
|
222
|
+
if (watched) exitReactiveRun();
|
|
223
|
+
}
|
|
224
|
+
const changed = !this._initialized || this._threw !== threw || (threw ? err !== this._error : !this._equals(this._value, next));
|
|
225
|
+
this._initialized = true;
|
|
226
|
+
this._threw = threw;
|
|
227
|
+
this._error = err;
|
|
228
|
+
this._value = next;
|
|
229
|
+
reportReactiveRun(this);
|
|
230
|
+
if (changed) {
|
|
231
|
+
this.version++;
|
|
232
|
+
if (this.observers) for (const o of [...this.observers]) o.markDirty(DIRTY);
|
|
233
|
+
notifyWatchers(this);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Push a maybe-dirty mark. A direct observer of a changed node gets DIRTY; its
|
|
238
|
+
* own observers get CHECK (recurse), stopping where already marked, so the
|
|
239
|
+
* push is O(newly-dirtied) and never recomputes.
|
|
240
|
+
*/
|
|
241
|
+
markDirty(level) {
|
|
242
|
+
if (this.state >= level) return;
|
|
243
|
+
const wasClean = this.state === CLEAN;
|
|
244
|
+
this.state = level;
|
|
245
|
+
if (wasClean) {
|
|
246
|
+
if (this.observers) for (const o of [...this.observers]) o.markDirty(CHECK);
|
|
247
|
+
notifyWatchers(this);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
peek() {
|
|
251
|
+
this.updateIfNecessary();
|
|
252
|
+
if (this._threw) throw this._error;
|
|
253
|
+
return this._value;
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
function notifyWatchers(node) {
|
|
257
|
+
if (!node.watchers) return;
|
|
258
|
+
for (const w of [...node.watchers]) w._notify(node);
|
|
259
|
+
}
|
|
260
|
+
var Watcher = class {
|
|
261
|
+
constructor(notify) {
|
|
262
|
+
this._watched = /* @__PURE__ */ new Set();
|
|
263
|
+
this._pending = /* @__PURE__ */ new Set();
|
|
264
|
+
this._notifyFn = notify;
|
|
265
|
+
}
|
|
266
|
+
watch(...nodes) {
|
|
267
|
+
for (const n of nodes) {
|
|
268
|
+
this._watched.add(n);
|
|
269
|
+
(n.watchers ??= /* @__PURE__ */ new Set()).add(this);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
unwatch(...nodes) {
|
|
273
|
+
for (const n of nodes) {
|
|
274
|
+
this._watched.delete(n);
|
|
275
|
+
n.watchers?.delete(this);
|
|
276
|
+
this._pending.delete(n);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
/** Watched nodes that may have changed since the last getPending(). */
|
|
280
|
+
getPending() {
|
|
281
|
+
const out = [...this._pending];
|
|
282
|
+
this._pending.clear();
|
|
283
|
+
return out;
|
|
284
|
+
}
|
|
285
|
+
/** @internal, a watched node became non-clean. Edge-triggered: notify once. */
|
|
286
|
+
_notify(node) {
|
|
287
|
+
if (!this._watched.has(node) || this._pending.has(node)) return;
|
|
288
|
+
const wasEmpty = this._pending.size === 0;
|
|
289
|
+
this._pending.add(node);
|
|
290
|
+
if (wasEmpty) this._notifyFn();
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
function untrack(fn) {
|
|
294
|
+
if (G.untracked) return fn();
|
|
295
|
+
G.untracked = true;
|
|
296
|
+
try {
|
|
297
|
+
return fn();
|
|
298
|
+
} finally {
|
|
299
|
+
G.untracked = false;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
// src/lib/signal/graph/runtime.ts
|
|
304
|
+
function makeOwner(parent) {
|
|
305
|
+
return { cleanups: null, owned: null, parent, contexts: null };
|
|
306
|
+
}
|
|
307
|
+
function runWithOwner(owner, fn) {
|
|
308
|
+
const prev = G.owner;
|
|
309
|
+
G.owner = owner;
|
|
310
|
+
try {
|
|
311
|
+
return fn();
|
|
312
|
+
} finally {
|
|
313
|
+
G.owner = prev;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
function onCleanup(fn) {
|
|
317
|
+
if (!G.owner) return;
|
|
318
|
+
if (G.owner.disposed) {
|
|
319
|
+
fn();
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
(G.owner.cleanups ??= []).push(fn);
|
|
323
|
+
}
|
|
324
|
+
function disposeOwner(owner, final = true) {
|
|
325
|
+
if (owner.disposed) return;
|
|
326
|
+
if (owner.owned) {
|
|
327
|
+
for (let i = owner.owned.length - 1; i >= 0; i--) disposeOwner(owner.owned[i]);
|
|
328
|
+
owner.owned = null;
|
|
329
|
+
}
|
|
330
|
+
if (owner.cleanups) {
|
|
331
|
+
for (let i = owner.cleanups.length - 1; i >= 0; i--) owner.cleanups[i]();
|
|
332
|
+
owner.cleanups = null;
|
|
333
|
+
}
|
|
334
|
+
if (final) owner.disposed = true;
|
|
335
|
+
}
|
|
336
|
+
function setScheduler(fn) {
|
|
337
|
+
G.hostSchedule = fn ?? ((run) => void Promise.resolve().then(run));
|
|
338
|
+
}
|
|
339
|
+
function enqueue(e) {
|
|
340
|
+
if (e.queued) return;
|
|
341
|
+
e.queued = true;
|
|
342
|
+
G.queue.push(e);
|
|
343
|
+
if (!G.scheduled && G.batchDepth === 0) {
|
|
344
|
+
G.scheduled = true;
|
|
345
|
+
G.hostSchedule(flushSync);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
function flushSync() {
|
|
349
|
+
G.scheduled = false;
|
|
350
|
+
if (G.flushing) return;
|
|
351
|
+
G.flushing = true;
|
|
352
|
+
let guard = 0;
|
|
353
|
+
try {
|
|
354
|
+
while (G.queue.length) {
|
|
355
|
+
if (++guard > 1e5) throw new Error("[fluixi] effect flush did not settle (cycle?)");
|
|
356
|
+
const batchOf = G.queue;
|
|
357
|
+
G.queue = [];
|
|
358
|
+
for (const e of batchOf) {
|
|
359
|
+
e.queued = false;
|
|
360
|
+
if (!e.disposed) e.run();
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
} finally {
|
|
364
|
+
G.flushing = false;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
function afterWrite() {
|
|
368
|
+
if (G.batchDepth === 0) flushSync();
|
|
369
|
+
}
|
|
370
|
+
function batch(fn) {
|
|
371
|
+
G.batchDepth++;
|
|
372
|
+
try {
|
|
373
|
+
return fn();
|
|
374
|
+
} finally {
|
|
375
|
+
if (--G.batchDepth === 0) flushSync();
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
var EffectNode = class {
|
|
379
|
+
constructor(fn, report = false) {
|
|
380
|
+
this.queued = false;
|
|
381
|
+
this.disposed = false;
|
|
382
|
+
this.owner = makeOwner(G.owner);
|
|
383
|
+
if (G.owner) (G.owner.cleanups ??= []).push(() => this.dispose());
|
|
384
|
+
this.computed = new Computed(() => {
|
|
385
|
+
disposeOwner(this.owner, false);
|
|
386
|
+
runWithOwner(this.owner, () => {
|
|
387
|
+
const r = fn();
|
|
388
|
+
if (typeof r === "function") (this.owner.cleanups ??= []).push(r);
|
|
389
|
+
});
|
|
390
|
+
});
|
|
391
|
+
reportReactiveNode({ kind: "effect", node: this.computed, handle: this, internal: !report });
|
|
392
|
+
this.watcher = new Watcher(() => enqueue(this));
|
|
393
|
+
this.run();
|
|
394
|
+
this.watcher.watch(this.computed);
|
|
395
|
+
}
|
|
396
|
+
run() {
|
|
397
|
+
if (this.disposed) return;
|
|
398
|
+
this.watcher.getPending();
|
|
399
|
+
try {
|
|
400
|
+
this.computed.get();
|
|
401
|
+
} catch (e) {
|
|
402
|
+
if (e && typeof e.then === "function" && G.onSuspend) {
|
|
403
|
+
G.onSuspend(e, this.owner);
|
|
404
|
+
return;
|
|
405
|
+
}
|
|
406
|
+
if (G.onError && G.onError(e, this.owner)) return;
|
|
407
|
+
throw e;
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
dispose() {
|
|
411
|
+
if (this.disposed) return;
|
|
412
|
+
this.disposed = true;
|
|
413
|
+
reportReactiveDispose(this.computed);
|
|
414
|
+
this.watcher.unwatch(this.computed);
|
|
415
|
+
disposeOwner(this.owner);
|
|
416
|
+
}
|
|
417
|
+
};
|
|
418
|
+
function effect(fn, report = false) {
|
|
419
|
+
const node = new EffectNode(fn, report);
|
|
420
|
+
return () => node.dispose();
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
// src/lib/signal/graph/compat.ts
|
|
424
|
+
setScheduler(() => {
|
|
425
|
+
});
|
|
426
|
+
var $SIGNAL = /* @__PURE__ */ Symbol.for("signal");
|
|
427
|
+
var $NODE = /* @__PURE__ */ Symbol.for("signal-node");
|
|
428
|
+
function createSignal(value, options) {
|
|
429
|
+
const state = new State(value, { equals: options?.equals });
|
|
430
|
+
const read = (() => state.get());
|
|
431
|
+
const write = ((next) => {
|
|
432
|
+
const v = typeof next === "function" ? next(state.peek()) : next;
|
|
433
|
+
state.set(v);
|
|
434
|
+
afterWrite();
|
|
435
|
+
return v;
|
|
436
|
+
});
|
|
437
|
+
Object.defineProperty(read, $SIGNAL, { value: true, enumerable: true });
|
|
438
|
+
Object.defineProperty(read, $NODE, {
|
|
439
|
+
value: {
|
|
440
|
+
get value() {
|
|
441
|
+
return state.peek();
|
|
442
|
+
},
|
|
443
|
+
get version() {
|
|
444
|
+
return state.version;
|
|
445
|
+
}
|
|
446
|
+
},
|
|
447
|
+
enumerable: false
|
|
448
|
+
});
|
|
449
|
+
reportReactiveNode({
|
|
450
|
+
kind: "signal",
|
|
451
|
+
node: state,
|
|
452
|
+
handle: read,
|
|
453
|
+
name: options?.name,
|
|
454
|
+
set: write
|
|
455
|
+
});
|
|
456
|
+
if (isObserved()) onCleanup(() => reportReactiveDispose(state));
|
|
457
|
+
return [read, write];
|
|
458
|
+
}
|
|
459
|
+
function createEffect(fn, value) {
|
|
460
|
+
let prev = value;
|
|
461
|
+
return effect(() => {
|
|
462
|
+
const r = fn(prev);
|
|
463
|
+
prev = r;
|
|
464
|
+
}, true);
|
|
465
|
+
}
|
|
466
|
+
function batch2(fn) {
|
|
467
|
+
return batch(fn);
|
|
468
|
+
}
|
|
469
|
+
function untrack2(fn) {
|
|
470
|
+
return untrack(fn);
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
// src/lib/signal/graph/ssr-hooks.ts
|
|
474
|
+
var _resourceTracker = null;
|
|
475
|
+
function trackResourcePromise(p) {
|
|
476
|
+
if (_resourceTracker) _resourceTracker(p);
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
// src/lib/signal/cached-resource.ts
|
|
480
|
+
var ttlCache = /* @__PURE__ */ new Map();
|
|
481
|
+
var inflight = /* @__PURE__ */ new Map();
|
|
482
|
+
var _autoId = 0;
|
|
483
|
+
var $SIGNAL2 = /* @__PURE__ */ Symbol.for("signal");
|
|
484
|
+
var $RESOURCE = /* @__PURE__ */ Symbol.for("resource");
|
|
485
|
+
function createCachedResource(sourceOrFetcher, fetcherOrOptions, opts = {}) {
|
|
486
|
+
let sourceFn;
|
|
487
|
+
let fetchFn;
|
|
488
|
+
let options;
|
|
489
|
+
if (typeof fetcherOrOptions === "function") {
|
|
490
|
+
sourceFn = sourceOrFetcher;
|
|
491
|
+
fetchFn = fetcherOrOptions;
|
|
492
|
+
options = opts;
|
|
493
|
+
} else {
|
|
494
|
+
sourceFn = () => true;
|
|
495
|
+
fetchFn = sourceOrFetcher;
|
|
496
|
+
options = fetcherOrOptions ?? opts;
|
|
497
|
+
}
|
|
498
|
+
const {
|
|
499
|
+
ttl = Infinity,
|
|
500
|
+
name = `_auto_${_autoId++}`,
|
|
501
|
+
staleWhileRevalidate = true
|
|
502
|
+
} = options;
|
|
503
|
+
const ns = name;
|
|
504
|
+
const buildKey = (key) => `${ns}:${JSON.stringify(key)}`;
|
|
505
|
+
const isFresh = (entry) => ttl === Infinity || Date.now() - entry.timestamp <= ttl;
|
|
506
|
+
const [value, setValue] = createSignal(void 0, { equals: false });
|
|
507
|
+
const [resourceState, setResourceState] = createSignal("unresolved", { equals: false });
|
|
508
|
+
const [resourceError, setResourceError] = createSignal(void 0, { equals: false });
|
|
509
|
+
const [pendingP, setPendingP] = createSignal(void 0, { equals: false });
|
|
510
|
+
const [isStale, setIsStale] = createSignal(false);
|
|
511
|
+
const [tick, setTick] = createSignal(0, { equals: false });
|
|
512
|
+
const UNSET = /* @__PURE__ */ Symbol("unset");
|
|
513
|
+
let prevKey = UNSET;
|
|
514
|
+
let flagRefetch = false;
|
|
515
|
+
let flagInvalidate = false;
|
|
516
|
+
function doFetch(key, ck, background, isCancelled) {
|
|
517
|
+
if (inflight.has(ck)) {
|
|
518
|
+
inflight.get(ck).then(
|
|
519
|
+
(v) => {
|
|
520
|
+
if (!isCancelled()) settle(v, background);
|
|
521
|
+
},
|
|
522
|
+
(e) => {
|
|
523
|
+
if (!isCancelled() && !background) fail(e);
|
|
524
|
+
}
|
|
525
|
+
);
|
|
526
|
+
if (!background) setPendingP(inflight.get(ck));
|
|
527
|
+
return;
|
|
528
|
+
}
|
|
529
|
+
const promise = Promise.resolve(fetchFn(key)).then(
|
|
530
|
+
(v) => {
|
|
531
|
+
ttlCache.set(ck, { value: v, timestamp: Date.now() });
|
|
532
|
+
inflight.delete(ck);
|
|
533
|
+
return v;
|
|
534
|
+
},
|
|
535
|
+
(e) => {
|
|
536
|
+
inflight.delete(ck);
|
|
537
|
+
throw e;
|
|
538
|
+
}
|
|
539
|
+
);
|
|
540
|
+
inflight.set(ck, promise);
|
|
541
|
+
if (!background) {
|
|
542
|
+
trackResourcePromise(promise);
|
|
543
|
+
setPendingP(promise);
|
|
544
|
+
}
|
|
545
|
+
promise.then(
|
|
546
|
+
(v) => {
|
|
547
|
+
if (!isCancelled()) settle(v, background);
|
|
548
|
+
},
|
|
549
|
+
(e) => {
|
|
550
|
+
if (!isCancelled() && !background) fail(e);
|
|
551
|
+
}
|
|
552
|
+
);
|
|
553
|
+
}
|
|
554
|
+
function settle(v, background) {
|
|
555
|
+
batch2(() => {
|
|
556
|
+
setValue(() => v);
|
|
557
|
+
setResourceState("ready");
|
|
558
|
+
setIsStale(false);
|
|
559
|
+
setPendingP(void 0);
|
|
560
|
+
setResourceError(void 0);
|
|
561
|
+
});
|
|
562
|
+
}
|
|
563
|
+
function fail(e) {
|
|
564
|
+
batch2(() => {
|
|
565
|
+
setResourceError(e);
|
|
566
|
+
setResourceState("errored");
|
|
567
|
+
setPendingP(void 0);
|
|
568
|
+
});
|
|
569
|
+
}
|
|
570
|
+
createEffect(() => {
|
|
571
|
+
const key = sourceFn();
|
|
572
|
+
tick();
|
|
573
|
+
if (key === false || key === null || key === void 0) {
|
|
574
|
+
prevKey = UNSET;
|
|
575
|
+
batch2(() => {
|
|
576
|
+
setResourceState("unresolved");
|
|
577
|
+
setPendingP(void 0);
|
|
578
|
+
setResourceError(void 0);
|
|
579
|
+
});
|
|
580
|
+
return;
|
|
581
|
+
}
|
|
582
|
+
const doRefetch = flagRefetch;
|
|
583
|
+
const doInvalidate = flagInvalidate;
|
|
584
|
+
flagRefetch = false;
|
|
585
|
+
flagInvalidate = false;
|
|
586
|
+
const ck = buildKey(key);
|
|
587
|
+
if (doInvalidate) ttlCache.delete(ck);
|
|
588
|
+
const keyChanged = prevKey === UNSET || key !== prevKey;
|
|
589
|
+
prevKey = key;
|
|
590
|
+
let cancelled = false;
|
|
591
|
+
onCleanup(() => {
|
|
592
|
+
cancelled = true;
|
|
593
|
+
});
|
|
594
|
+
const cached = ttlCache.get(ck);
|
|
595
|
+
if (cached && isFresh(cached) && !doRefetch && !doInvalidate) {
|
|
596
|
+
const cur2 = untrack2(resourceState);
|
|
597
|
+
if (cur2 !== "ready" || untrack2(value) !== cached.value) {
|
|
598
|
+
batch2(() => {
|
|
599
|
+
setValue(() => cached.value);
|
|
600
|
+
setResourceState("ready");
|
|
601
|
+
setIsStale(false);
|
|
602
|
+
setResourceError(void 0);
|
|
603
|
+
});
|
|
604
|
+
}
|
|
605
|
+
return;
|
|
606
|
+
}
|
|
607
|
+
if (cached && staleWhileRevalidate && !doInvalidate) {
|
|
608
|
+
batch2(() => {
|
|
609
|
+
setValue(() => cached.value);
|
|
610
|
+
setResourceState("ready");
|
|
611
|
+
setIsStale(true);
|
|
612
|
+
setResourceError(void 0);
|
|
613
|
+
setPendingP(void 0);
|
|
614
|
+
});
|
|
615
|
+
doFetch(key, ck, true, () => cancelled);
|
|
616
|
+
return;
|
|
617
|
+
}
|
|
618
|
+
const cur = untrack2(resourceState);
|
|
619
|
+
const isReload = cur === "ready" || cur === "refreshing";
|
|
620
|
+
batch2(() => {
|
|
621
|
+
setResourceState(isReload ? "refreshing" : "pending");
|
|
622
|
+
setResourceError(void 0);
|
|
623
|
+
setIsStale(false);
|
|
624
|
+
});
|
|
625
|
+
doFetch(key, ck, false, () => cancelled);
|
|
626
|
+
});
|
|
627
|
+
const resource = (() => {
|
|
628
|
+
const e = resourceError();
|
|
629
|
+
if (e) throw e;
|
|
630
|
+
const s = resourceState();
|
|
631
|
+
if (s === "pending") {
|
|
632
|
+
const p = pendingP();
|
|
633
|
+
if (p) throw p;
|
|
634
|
+
}
|
|
635
|
+
return value();
|
|
636
|
+
});
|
|
637
|
+
Object.defineProperty(resource, $RESOURCE, { value: true, enumerable: true });
|
|
638
|
+
Object.defineProperty(resource, $SIGNAL2, { value: true, enumerable: true });
|
|
639
|
+
Object.defineProperties(resource, {
|
|
640
|
+
state: { get: resourceState },
|
|
641
|
+
loading: { get: () => {
|
|
642
|
+
const s = resourceState();
|
|
643
|
+
return s === "pending" || s === "refreshing";
|
|
644
|
+
} },
|
|
645
|
+
error: { get: resourceError },
|
|
646
|
+
latest: { get: value },
|
|
647
|
+
stale: { get: isStale }
|
|
648
|
+
});
|
|
649
|
+
const refetch = () => {
|
|
650
|
+
flagRefetch = true;
|
|
651
|
+
setTick((v) => v + 1);
|
|
652
|
+
};
|
|
653
|
+
const invalidate = () => {
|
|
654
|
+
const key = untrack2(sourceFn);
|
|
655
|
+
if (key !== null && key !== void 0 && key !== false) {
|
|
656
|
+
ttlCache.delete(buildKey(key));
|
|
657
|
+
}
|
|
658
|
+
flagInvalidate = true;
|
|
659
|
+
setTick((v) => v + 1);
|
|
660
|
+
};
|
|
661
|
+
return [resource, { mutate: setValue, refetch, invalidate }];
|
|
662
|
+
}
|
|
663
|
+
function clearCachedResourceNamespace(name) {
|
|
664
|
+
const prefix = `${name}:`;
|
|
665
|
+
for (const key of ttlCache.keys()) {
|
|
666
|
+
if (key.startsWith(prefix)) ttlCache.delete(key);
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
function clearAllCachedResources() {
|
|
670
|
+
ttlCache.clear();
|
|
671
|
+
inflight.clear();
|
|
672
|
+
}
|