@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.
Files changed (167) hide show
  1. package/dist/cdn/reactive.cjs +2673 -1
  2. package/dist/cdn/reactive.global.js +2 -1
  3. package/dist/cdn/reactive.mjs +2657 -1
  4. package/dist/cdn/signal.cjs +299 -1
  5. package/dist/cdn/signal.d.ts +1 -1
  6. package/dist/cdn/signal.global.js +2 -1
  7. package/dist/cdn/signal.js +1 -1
  8. package/dist/cdn/signal.mjs +276 -1
  9. package/dist/index.cjs +2673 -1
  10. package/dist/index.mjs +2657 -1
  11. package/dist/lib/index.cjs +2674 -1
  12. package/dist/lib/index.js +1 -1
  13. package/dist/lib/index.mjs +2659 -1
  14. package/dist/lib/observable/index.cjs +386 -1
  15. package/dist/lib/observable/index.mjs +364 -1
  16. package/dist/lib/observable/observable.cjs +384 -1
  17. package/dist/lib/observable/observable.d.ts +0 -137
  18. package/dist/lib/observable/observable.d.ts.map +1 -1
  19. package/dist/lib/observable/observable.js +0 -71
  20. package/dist/lib/observable/observable.mjs +361 -1
  21. package/dist/lib/observable/subscription.cjs +180 -1
  22. package/dist/lib/observable/subscription.d.ts +0 -12
  23. package/dist/lib/observable/subscription.d.ts.map +1 -1
  24. package/dist/lib/observable/subscription.js +0 -12
  25. package/dist/lib/observable/subscription.mjs +157 -1
  26. package/dist/lib/observable/types.cjs +18 -1
  27. package/dist/lib/observable/types.d.ts.map +1 -1
  28. package/dist/lib/predicates.cjs +44 -1
  29. package/dist/lib/predicates.d.ts +2 -2
  30. package/dist/lib/predicates.js +2 -2
  31. package/dist/lib/predicates.mjs +23 -1
  32. package/dist/lib/signal/api.cjs +571 -1
  33. package/dist/lib/signal/api.d.ts +211 -1
  34. package/dist/lib/signal/api.d.ts.map +1 -1
  35. package/dist/lib/signal/api.js +207 -12
  36. package/dist/lib/signal/api.mjs +548 -1
  37. package/dist/lib/signal/cached-resource.cjs +672 -1
  38. package/dist/lib/signal/cached-resource.d.ts +28 -16
  39. package/dist/lib/signal/cached-resource.d.ts.map +1 -1
  40. package/dist/lib/signal/cached-resource.js +35 -29
  41. package/dist/lib/signal/cached-resource.mjs +650 -1
  42. package/dist/lib/signal/graph/children.cjs +325 -1
  43. package/dist/lib/signal/graph/children.js +1 -1
  44. package/dist/lib/signal/graph/children.mjs +302 -1
  45. package/dist/lib/signal/graph/compat.cjs +578 -1
  46. package/dist/lib/signal/graph/compat.d.ts +13 -13
  47. package/dist/lib/signal/graph/compat.d.ts.map +1 -1
  48. package/dist/lib/signal/graph/compat.js +33 -31
  49. package/dist/lib/signal/graph/compat.mjs +556 -1
  50. package/dist/lib/signal/graph/core.cjs +295 -1
  51. package/dist/lib/signal/graph/core.d.ts +28 -24
  52. package/dist/lib/signal/graph/core.d.ts.map +1 -1
  53. package/dist/lib/signal/graph/core.js +38 -31
  54. package/dist/lib/signal/graph/core.mjs +273 -1
  55. package/dist/lib/signal/graph/debounced.cjs +668 -1
  56. package/dist/lib/signal/graph/debounced.d.ts +5 -5
  57. package/dist/lib/signal/graph/debounced.d.ts.map +1 -1
  58. package/dist/lib/signal/graph/debounced.js +5 -5
  59. package/dist/lib/signal/graph/debounced.mjs +645 -1
  60. package/dist/lib/signal/graph/derived.cjs +496 -1
  61. package/dist/lib/signal/graph/derived.d.ts +1 -1
  62. package/dist/lib/signal/graph/derived.js +1 -1
  63. package/dist/lib/signal/graph/derived.mjs +473 -1
  64. package/dist/lib/signal/graph/detect.cjs +66 -1
  65. package/dist/lib/signal/graph/detect.mjs +45 -1
  66. package/dist/lib/signal/graph/error-boundary.cjs +301 -1
  67. package/dist/lib/signal/graph/error-boundary.js +3 -3
  68. package/dist/lib/signal/graph/error-boundary.mjs +278 -1
  69. package/dist/lib/signal/graph/index.cjs +305 -1
  70. package/dist/lib/signal/graph/index.d.ts +7 -6
  71. package/dist/lib/signal/graph/index.d.ts.map +1 -1
  72. package/dist/lib/signal/graph/index.js +7 -6
  73. package/dist/lib/signal/graph/index.mjs +283 -1
  74. package/dist/lib/signal/graph/observe.cjs +163 -1
  75. package/dist/lib/signal/graph/observe.d.ts +8 -8
  76. package/dist/lib/signal/graph/observe.js +5 -5
  77. package/dist/lib/signal/graph/observe.mjs +140 -1
  78. package/dist/lib/signal/graph/resource.cjs +620 -1
  79. package/dist/lib/signal/graph/resource.d.ts +1 -1
  80. package/dist/lib/signal/graph/resource.js +7 -8
  81. package/dist/lib/signal/graph/resource.mjs +597 -1
  82. package/dist/lib/signal/graph/runtime.cjs +501 -1
  83. package/dist/lib/signal/graph/runtime.d.ts +7 -7
  84. package/dist/lib/signal/graph/runtime.d.ts.map +1 -1
  85. package/dist/lib/signal/graph/runtime.js +34 -30
  86. package/dist/lib/signal/graph/runtime.mjs +478 -1
  87. package/dist/lib/signal/graph/signal-next.cjs +1208 -1
  88. package/dist/lib/signal/graph/signal-next.d.ts +5 -5
  89. package/dist/lib/signal/graph/signal-next.d.ts.map +1 -1
  90. package/dist/lib/signal/graph/signal-next.js +14 -12
  91. package/dist/lib/signal/graph/signal-next.mjs +1186 -1
  92. package/dist/lib/signal/graph/ssr-hooks.cjs +60 -1
  93. package/dist/lib/signal/graph/ssr-hooks.d.ts +6 -7
  94. package/dist/lib/signal/graph/ssr-hooks.d.ts.map +1 -1
  95. package/dist/lib/signal/graph/ssr-hooks.js +6 -7
  96. package/dist/lib/signal/graph/ssr-hooks.mjs +39 -1
  97. package/dist/lib/signal/graph/state.cjs +72 -1
  98. package/dist/lib/signal/graph/state.d.ts +41 -10
  99. package/dist/lib/signal/graph/state.d.ts.map +1 -1
  100. package/dist/lib/signal/graph/state.js +83 -22
  101. package/dist/lib/signal/graph/state.mjs +49 -1
  102. package/dist/lib/signal/graph/suspense.cjs +301 -1
  103. package/dist/lib/signal/graph/suspense.js +4 -4
  104. package/dist/lib/signal/graph/suspense.mjs +278 -1
  105. package/dist/lib/signal/index-legacy.cjs +2540 -1
  106. package/dist/lib/signal/index-legacy.d.ts +1 -1
  107. package/dist/lib/signal/index-legacy.js +1 -1
  108. package/dist/lib/signal/index-legacy.mjs +2518 -1
  109. package/dist/lib/signal/index.cjs +1275 -1
  110. package/dist/lib/signal/index.d.ts +3 -2
  111. package/dist/lib/signal/index.d.ts.map +1 -1
  112. package/dist/lib/signal/index.js +7 -4
  113. package/dist/lib/signal/index.mjs +1253 -1
  114. package/dist/lib/signal/list.cjs +549 -1
  115. package/dist/lib/signal/list.d.ts +5 -5
  116. package/dist/lib/signal/list.js +5 -5
  117. package/dist/lib/signal/list.mjs +526 -1
  118. package/dist/lib/signal/resource-api.cjs +626 -1
  119. package/dist/lib/signal/resource-api.d.ts +5 -5
  120. package/dist/lib/signal/resource-api.js +5 -5
  121. package/dist/lib/signal/resource-api.mjs +603 -1
  122. package/dist/lib/signal/signal.cjs +2023 -1
  123. package/dist/lib/signal/signal.d.ts +4 -4
  124. package/dist/lib/signal/signal.d.ts.map +1 -1
  125. package/dist/lib/signal/signal.js +22 -23
  126. package/dist/lib/signal/signal.mjs +2000 -1
  127. package/dist/lib/signal/types.cjs +38 -1
  128. package/dist/lib/signal/types.d.ts.map +1 -1
  129. package/dist/lib/signal/types.js +2 -2
  130. package/dist/lib/signal/types.mjs +17 -1
  131. package/dist/lib/signal/utilities.cjs +1012 -1
  132. package/dist/lib/signal/utilities.d.ts +0 -108
  133. package/dist/lib/signal/utilities.d.ts.map +1 -1
  134. package/dist/lib/signal/utilities.js +0 -158
  135. package/dist/lib/signal/utilities.mjs +990 -1
  136. package/dist/lib/store/api.cjs +612 -1
  137. package/dist/lib/store/api.d.ts +33 -0
  138. package/dist/lib/store/api.d.ts.map +1 -1
  139. package/dist/lib/store/api.js +41 -8
  140. package/dist/lib/store/api.mjs +596 -1
  141. package/dist/lib/store/index.cjs +691 -1
  142. package/dist/lib/store/index.js +1 -1
  143. package/dist/lib/store/index.mjs +676 -1
  144. package/dist/lib/store/setter.types.cjs +18 -1
  145. package/dist/lib/store/setter.types.d.ts +43 -3
  146. package/dist/lib/store/setter.types.d.ts.map +1 -1
  147. package/dist/lib/store/store.cjs +658 -1
  148. package/dist/lib/store/store.d.ts +72 -0
  149. package/dist/lib/store/store.d.ts.map +1 -1
  150. package/dist/lib/store/store.js +148 -5
  151. package/dist/lib/store/store.mjs +644 -1
  152. package/dist/lib/store/types.cjs +18 -1
  153. package/dist/lib/store/types.d.ts +1 -1
  154. package/dist/lib/store/types.d.ts.map +1 -1
  155. package/dist/lib/store/utils.cjs +43 -1
  156. package/dist/lib/store/utils.d.ts +1 -1
  157. package/dist/lib/store/utils.js +1 -1
  158. package/dist/lib/store/utils.mjs +22 -1
  159. package/dist/lib/subject.cjs +450 -1
  160. package/dist/lib/subject.js +3 -91
  161. package/dist/lib/subject.mjs +427 -1
  162. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  163. package/dist/version.generated.cjs +27 -1
  164. package/dist/version.generated.d.ts +1 -1
  165. package/dist/version.generated.js +2 -2
  166. package/dist/version.generated.mjs +7 -1
  167. package/package.json +5 -4
@@ -1 +1,620 @@
1
- "use strict";var A=Object.defineProperty;var me=Object.getOwnPropertyDescriptor;var ye=Object.getOwnPropertyNames;var ge=Object.prototype.hasOwnProperty;var ke=(e,n)=>{for(var t in n)A(e,t,{get:n[t],enumerable:!0})},xe=(e,n,t,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let i of ye(n))!ge.call(e,i)&&i!==t&&A(e,i,{get:()=>n[i],enumerable:!(o=me(n,i))||o.enumerable});return e};var Re=e=>xe(A({},"__esModule",{value:!0}),e);var je={};ke(je,{createResource:()=>Ve});module.exports=Re(je);var Se="__fluixi_signal_next_state__",Oe=e=>{typeof queueMicrotask=="function"?queueMicrotask(e):Promise.resolve().then(e)},r=globalThis[Se]??={consumer:null,untracked:!1,owner:null,queue:[],scheduled:!1,flushing:!1,batchDepth:0,hostSchedule:Oe,onSuspend:null,onError:null,observer:null};var U="1.0.0-alpha.83";function _e(e){return r.observer=e,()=>{r.observer===e&&(r.observer=null)}}var I=[],Pe;function O(e){let n=r.observer;n&&n.created(e.parents===void 0?{...e,parents:I,origin:e.origin??Pe}:e)}function $(e){return r.observer?(I.push(e),!0):!1}function B(){I.pop()}function X(e){r.observer?.ran?.(e)}function J(e,n){r.observer?.wrote?.(e,n)}function _(e){r.observer?.disposed?.(e)}var qe="__FLUIXI_DEVTOOLS_HOOK__",Y=globalThis[qe];if(typeof Y?.inject=="function")try{Y.inject({observeReactiveNodes:_e,version:U})}catch{}function Q(){return r.observer!=null}var Z=0,ee=1,T=2,P=class{constructor(){this.observers=null;this.watchers=null;this.version=0}updateIfNecessary(){}track(){if(r.untracked)return;let n=r.consumer;n&&((this.observers??=new Set).add(n),(n.sources??=new Set).add(this))}},q=class extends P{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++,J(this,r.consumer),this.observers)for(let t of[...this.observers])t.markDirty(T);V(this)}}peek(){return this._value}},b=class extends P{constructor(t,o){super();this._threw=!1;this._initialized=!1;this.state=T;this.sources=null;this._fn=t,this._equals=o?.equals===!1?()=>!1:o?.equals??Object.is}get(){if(r.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===ee&&this.sources){for(let t of this.sources)if(t.updateIfNecessary(),this.state===T)break}(this.state===T||!this._initialized)&&this.recompute(),this.state=Z}recompute(){if(this.sources){for(let c of this.sources)c.observers?.delete(this);this.sources.clear()}let t=r.consumer,o=r.untracked,i=$(this);r.consumer=this,r.untracked=!1;let s,u=!1,f;try{s=this._fn()}catch(c){u=!0,f=c,s=this._value}finally{r.consumer=t,r.untracked=o,i&&B()}let w=!this._initialized||this._threw!==u||(u?f!==this._error:!this._equals(this._value,s));if(this._initialized=!0,this._threw=u,this._error=f,this._value=s,X(this),w){if(this.version++,this.observers)for(let c of[...this.observers])c.markDirty(T);V(this)}}markDirty(t){if(this.state>=t)return;let o=this.state===Z;if(this.state=t,o){if(this.observers)for(let i of[...this.observers])i.markDirty(ee);V(this)}}peek(){if(this.updateIfNecessary(),this._threw)throw this._error;return this._value}};function V(e){if(e.watchers)for(let n of[...e.watchers])n._notify(e)}var C=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 ne(e){if(r.untracked)return e();r.untracked=!0;try{return e()}finally{r.untracked=!1}}function Ce(e){return{cleanups:null,owned:null,parent:e,contexts:null}}function G(e,n){let t=r.owner;r.owner=e;try{return n()}finally{r.owner=t}}function m(e){if(r.owner){if(r.owner.disposed){e();return}(r.owner.cleanups??=[]).push(e)}}function j(e,n=!0){if(!e.disposed){if(e.owned){for(let t=e.owned.length-1;t>=0;t--)j(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 te(e){r.hostSchedule=e??(n=>{Promise.resolve().then(n)})}function De(e){e.queued||(e.queued=!0,r.queue.push(e),!r.scheduled&&r.batchDepth===0&&(r.scheduled=!0,r.hostSchedule(D)))}function D(){if(r.scheduled=!1,r.flushing)return;r.flushing=!0;let e=0;try{for(;r.queue.length;){if(++e>1e5)throw new Error("[fluixi] effect flush did not settle (cycle?)");let n=r.queue;r.queue=[];for(let t of n)t.queued=!1,t.disposed||t.run()}}finally{r.flushing=!1}}function re(){r.batchDepth===0&&D()}function oe(e){r.batchDepth++;try{return e()}finally{--r.batchDepth===0&&D()}}var M=class{constructor(n,t=!1){this.queued=!1;this.disposed=!1;this.owner=Ce(r.owner),r.owner&&(r.owner.cleanups??=[]).push(()=>this.dispose()),this.computed=new b(()=>{j(this.owner,!1),G(this.owner,()=>{let o=n();typeof o=="function"&&(this.owner.cleanups??=[]).push(o)})}),O({kind:"effect",node:this.computed,handle:this,internal:!t}),this.watcher=new C(()=>De(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"&&r.onSuspend){r.onSuspend(n,this.owner);return}if(r.onError&&r.onError(n,this.owner))return;throw n}}}dispose(){this.disposed||(this.disposed=!0,_(this.computed),this.watcher.unwatch(this.computed),j(this.owner))}};function ie(e,n=!1){let t=new M(e,n);return()=>t.dispose()}te(()=>{});var Ee=Symbol.for("signal");var Ae=Symbol.for("signal-node");function h(e,n){let t=new q(e,{equals:n?.equals}),o=(()=>t.get()),i=(s=>{let u=typeof s=="function"?s(t.peek()):s;return t.set(u),re(),u});return Object.defineProperty(o,Ee,{value:!0,enumerable:!0}),Object.defineProperty(o,Ae,{value:{get value(){return t.peek()},get version(){return t.version}},enumerable:!1}),O({kind:"signal",node:t,handle:o,name:n?.name,set:i}),Q()&&m(()=>_(t)),[o,i]}function se(e,n){let t=n;return ie(()=>{t=e(t)},!0)}function d(e){return oe(e)}function W(e){return ne(e)}var ue=null;function de(e){ue&&ue(e)}var ae=null;function fe(e){return ae?ae(e):void 0}var ce=null;function pe(){return ce?ce():void 0}var le=null;function ve(e,n){le&&le(e,n)}function Ie(e){return!!e&&typeof e.then=="function"}var H=Symbol();function Ve(e,n,t={}){let o,i;typeof n=="function"?(o=typeof e=="function"?e:()=>e,i=n):(o=()=>!0,i=e,n&&typeof n=="object"&&(t=n));let s=t.transport===!1?void 0:pe(),u=s!==void 0?fe(s):void 0,f=u!==void 0,[w,c]=h(u!==void 0?u.value:t.initialValue,{equals:!1}),[K,y]=h(void 0,{equals:!1}),[N,p]=h(u!==void 0||t.initialValue!==void 0?"ready":"unresolved",{equals:!1}),[he,v]=h(void 0,{equals:!1}),[we,Te]=h(void 0,{equals:!1}),g=H,E=!1;se(()=>{let a=o();if(we(),a===!1||a===null||a===void 0){g=H,d(()=>{p("unresolved"),v(void 0),y(void 0)});return}let x=E;if(E=!1,g!==H&&a===g&&!x)return;if(g=a,f){f=!1;return}let R=!1;m(()=>R=!0);let F=W(N),be=W(w),L=F==="ready"||F==="refreshing";d(()=>{p(L?"refreshing":"pending"),y(void 0)});try{let l=i(a,{value:be,refetching:L});Ie(l)?(v(l),de(l),l.then(S=>{R||(s!==void 0&&ve(s,S),d(()=>{c(()=>S),p("ready"),v(void 0)}))},S=>{R||d(()=>{y(S),p("errored"),v(void 0)})})):d(()=>{c(()=>l),p("ready"),v(void 0)})}catch(l){if(R)return;d(()=>{y(l),p("errored"),v(void 0)})}});let z=()=>{let a=N();return a==="pending"||a==="refreshing"},k=(()=>{let a=K();if(a)throw a;if(z()){let x=he();if(x)throw x}return w()});return Object.defineProperties(k,{state:{get:N},loading:{get:z},error:{get:K},latest:{get:w}}),Object.defineProperty(k,Symbol.for("resource"),{value:!0,enumerable:!0}),Object.defineProperty(k,Symbol.for("signal"),{value:!0,enumerable:!0}),[k,{mutate:c,refetch:()=>{E=!0,Te(void 0)}}]}
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/lib/signal/graph/resource.ts
21
+ var resource_exports = {};
22
+ __export(resource_exports, {
23
+ createResource: () => createResource
24
+ });
25
+ module.exports = __toCommonJS(resource_exports);
26
+
27
+ // src/version.generated.ts
28
+ var VERSION = "1.0.0-alpha.84";
29
+
30
+ // src/lib/signal/graph/state.ts
31
+ var MAJOR = VERSION.split(".")[0];
32
+ var KEY = `__fluixi_signal_state_v${MAJOR}__`;
33
+ var VERSIONS_KEY = `__fluixi_signal_builds_v${MAJOR}__`;
34
+ var defaultSchedule = (run) => {
35
+ if (typeof queueMicrotask === "function") queueMicrotask(run);
36
+ else void Promise.resolve().then(run);
37
+ };
38
+ function defaults() {
39
+ return {
40
+ consumer: null,
41
+ untracked: false,
42
+ owner: null,
43
+ queue: [],
44
+ scheduled: false,
45
+ flushing: false,
46
+ batchDepth: 0,
47
+ hostSchedule: defaultSchedule,
48
+ onSuspend: null,
49
+ onError: null,
50
+ observer: null
51
+ };
52
+ }
53
+ var realm = globalThis;
54
+ function backfillState(existing) {
55
+ const fresh = defaults();
56
+ const target = existing;
57
+ for (const field of Object.keys(fresh)) {
58
+ if (!(field in existing)) target[field] = fresh[field];
59
+ }
60
+ return existing;
61
+ }
62
+ function claim() {
63
+ const existing = realm[KEY];
64
+ return existing ? backfillState(existing) : realm[KEY] = defaults();
65
+ }
66
+ var G = claim();
67
+ (realm[VERSIONS_KEY] ??= []).push(VERSION);
68
+
69
+ // src/lib/signal/graph/observe.ts
70
+ function observeReactiveNodes(next) {
71
+ G.observer = next;
72
+ return () => {
73
+ if (G.observer === next) G.observer = null;
74
+ };
75
+ }
76
+ var running = [];
77
+ var origin;
78
+ function reportReactiveNode(report) {
79
+ const observer = G.observer;
80
+ if (observer) {
81
+ observer.created(
82
+ report.parents === void 0 ? { ...report, parents: running, origin: report.origin ?? origin } : report
83
+ );
84
+ }
85
+ }
86
+ function enterReactiveRun(node) {
87
+ if (!G.observer) return false;
88
+ running.push(node);
89
+ return true;
90
+ }
91
+ function exitReactiveRun() {
92
+ running.pop();
93
+ }
94
+ function reportReactiveRun(node) {
95
+ G.observer?.ran?.(node);
96
+ }
97
+ function reportReactiveWrite(node, by) {
98
+ G.observer?.wrote?.(node, by);
99
+ }
100
+ function reportReactiveDispose(node) {
101
+ G.observer?.disposed?.(node);
102
+ }
103
+ var HOOK = "__FLUIXI_DEVTOOLS_HOOK__";
104
+ var hook = globalThis[HOOK];
105
+ if (typeof hook?.inject === "function") {
106
+ try {
107
+ hook.inject({ observeReactiveNodes, version: VERSION });
108
+ } catch {
109
+ }
110
+ }
111
+ function isObserved() {
112
+ return G.observer != null;
113
+ }
114
+
115
+ // src/lib/signal/graph/core.ts
116
+ var CLEAN = 0;
117
+ var CHECK = 1;
118
+ var DIRTY = 2;
119
+ var Source = class {
120
+ constructor() {
121
+ /** Computeds, and watched leaves, that read this node. */
122
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
123
+ this.observers = null;
124
+ /** Watchers eagerly observing this node, which is how `runtime.ts` schedules effects. */
125
+ this.watchers = null;
126
+ /** Bumped whenever this node's value actually changes (equality-gated). */
127
+ this.version = 0;
128
+ }
129
+ /** Settle this node so a reader sees a current value/version. Overridden by Computed. */
130
+ updateIfNecessary() {
131
+ }
132
+ /** Link the current consumer (if any) as an observer of this node. */
133
+ track() {
134
+ if (G.untracked) return;
135
+ const consumer = G.consumer;
136
+ if (!consumer) return;
137
+ (this.observers ??= /* @__PURE__ */ new Set()).add(consumer);
138
+ (consumer.sources ??= /* @__PURE__ */ new Set()).add(this);
139
+ }
140
+ };
141
+ var State = class extends Source {
142
+ constructor(value, options) {
143
+ super();
144
+ this._value = value;
145
+ this._equals = options?.equals === false ? () => false : options?.equals ?? Object.is;
146
+ }
147
+ get() {
148
+ this.track();
149
+ return this._value;
150
+ }
151
+ set(next) {
152
+ if (this._equals(this._value, next)) return;
153
+ this._value = next;
154
+ this.version++;
155
+ reportReactiveWrite(this, G.consumer);
156
+ if (this.observers) for (const o of [...this.observers]) o.markDirty(DIRTY);
157
+ notifyWatchers(this);
158
+ }
159
+ /** Read without subscribing (peek). */
160
+ peek() {
161
+ return this._value;
162
+ }
163
+ };
164
+ var Computed = class extends Source {
165
+ constructor(fn, options) {
166
+ super();
167
+ this._threw = false;
168
+ this._initialized = false;
169
+ this.state = DIRTY;
170
+ /** Nodes this computation read on its last run. Rebuilt on every run. */
171
+ this.sources = null;
172
+ this._fn = fn;
173
+ this._equals = options?.equals === false ? () => false : options?.equals ?? Object.is;
174
+ }
175
+ get() {
176
+ if (G.consumer === this) {
177
+ throw new Error("Signal.Computed cannot read itself");
178
+ }
179
+ this.track();
180
+ this.updateIfNecessary();
181
+ if (this._threw) throw this._error;
182
+ return this._value;
183
+ }
184
+ /** Settle, if CHECK, verify sources; if DIRTY (or never run), recompute. */
185
+ updateIfNecessary() {
186
+ if (this.state === CHECK) {
187
+ if (this.sources) {
188
+ for (const s of this.sources) {
189
+ s.updateIfNecessary();
190
+ if (this.state === DIRTY) break;
191
+ }
192
+ }
193
+ }
194
+ if (this.state === DIRTY || !this._initialized) this.recompute();
195
+ this.state = CLEAN;
196
+ }
197
+ recompute() {
198
+ if (this.sources) {
199
+ for (const s of this.sources) s.observers?.delete(this);
200
+ this.sources.clear();
201
+ }
202
+ const prevConsumer = G.consumer;
203
+ const prevUntracked = G.untracked;
204
+ const watched = enterReactiveRun(this);
205
+ G.consumer = this;
206
+ G.untracked = false;
207
+ let next;
208
+ let threw = false;
209
+ let err;
210
+ try {
211
+ next = this._fn();
212
+ } catch (e) {
213
+ threw = true;
214
+ err = e;
215
+ next = this._value;
216
+ } finally {
217
+ G.consumer = prevConsumer;
218
+ G.untracked = prevUntracked;
219
+ if (watched) exitReactiveRun();
220
+ }
221
+ const changed = !this._initialized || this._threw !== threw || (threw ? err !== this._error : !this._equals(this._value, next));
222
+ this._initialized = true;
223
+ this._threw = threw;
224
+ this._error = err;
225
+ this._value = next;
226
+ reportReactiveRun(this);
227
+ if (changed) {
228
+ this.version++;
229
+ if (this.observers) for (const o of [...this.observers]) o.markDirty(DIRTY);
230
+ notifyWatchers(this);
231
+ }
232
+ }
233
+ /**
234
+ * Push a maybe-dirty mark. A direct observer of a changed node gets DIRTY; its
235
+ * own observers get CHECK (recurse), stopping where already marked, so the
236
+ * push is O(newly-dirtied) and never recomputes.
237
+ */
238
+ markDirty(level) {
239
+ if (this.state >= level) return;
240
+ const wasClean = this.state === CLEAN;
241
+ this.state = level;
242
+ if (wasClean) {
243
+ if (this.observers) for (const o of [...this.observers]) o.markDirty(CHECK);
244
+ notifyWatchers(this);
245
+ }
246
+ }
247
+ peek() {
248
+ this.updateIfNecessary();
249
+ if (this._threw) throw this._error;
250
+ return this._value;
251
+ }
252
+ };
253
+ function notifyWatchers(node) {
254
+ if (!node.watchers) return;
255
+ for (const w of [...node.watchers]) w._notify(node);
256
+ }
257
+ var Watcher = class {
258
+ constructor(notify) {
259
+ this._watched = /* @__PURE__ */ new Set();
260
+ this._pending = /* @__PURE__ */ new Set();
261
+ this._notifyFn = notify;
262
+ }
263
+ watch(...nodes) {
264
+ for (const n of nodes) {
265
+ this._watched.add(n);
266
+ (n.watchers ??= /* @__PURE__ */ new Set()).add(this);
267
+ }
268
+ }
269
+ unwatch(...nodes) {
270
+ for (const n of nodes) {
271
+ this._watched.delete(n);
272
+ n.watchers?.delete(this);
273
+ this._pending.delete(n);
274
+ }
275
+ }
276
+ /** Watched nodes that may have changed since the last getPending(). */
277
+ getPending() {
278
+ const out = [...this._pending];
279
+ this._pending.clear();
280
+ return out;
281
+ }
282
+ /** @internal, a watched node became non-clean. Edge-triggered: notify once. */
283
+ _notify(node) {
284
+ if (!this._watched.has(node) || this._pending.has(node)) return;
285
+ const wasEmpty = this._pending.size === 0;
286
+ this._pending.add(node);
287
+ if (wasEmpty) this._notifyFn();
288
+ }
289
+ };
290
+ function untrack(fn) {
291
+ if (G.untracked) return fn();
292
+ G.untracked = true;
293
+ try {
294
+ return fn();
295
+ } finally {
296
+ G.untracked = false;
297
+ }
298
+ }
299
+
300
+ // src/lib/signal/graph/runtime.ts
301
+ function makeOwner(parent) {
302
+ return { cleanups: null, owned: null, parent, contexts: null };
303
+ }
304
+ function runWithOwner(owner, fn) {
305
+ const prev = G.owner;
306
+ G.owner = owner;
307
+ try {
308
+ return fn();
309
+ } finally {
310
+ G.owner = prev;
311
+ }
312
+ }
313
+ function onCleanup(fn) {
314
+ if (!G.owner) return;
315
+ if (G.owner.disposed) {
316
+ fn();
317
+ return;
318
+ }
319
+ (G.owner.cleanups ??= []).push(fn);
320
+ }
321
+ function disposeOwner(owner, final = true) {
322
+ if (owner.disposed) return;
323
+ if (owner.owned) {
324
+ for (let i = owner.owned.length - 1; i >= 0; i--) disposeOwner(owner.owned[i]);
325
+ owner.owned = null;
326
+ }
327
+ if (owner.cleanups) {
328
+ for (let i = owner.cleanups.length - 1; i >= 0; i--) owner.cleanups[i]();
329
+ owner.cleanups = null;
330
+ }
331
+ if (final) owner.disposed = true;
332
+ }
333
+ function setScheduler(fn) {
334
+ G.hostSchedule = fn ?? ((run) => void Promise.resolve().then(run));
335
+ }
336
+ function enqueue(e) {
337
+ if (e.queued) return;
338
+ e.queued = true;
339
+ G.queue.push(e);
340
+ if (!G.scheduled && G.batchDepth === 0) {
341
+ G.scheduled = true;
342
+ G.hostSchedule(flushSync);
343
+ }
344
+ }
345
+ function flushSync() {
346
+ G.scheduled = false;
347
+ if (G.flushing) return;
348
+ G.flushing = true;
349
+ let guard = 0;
350
+ try {
351
+ while (G.queue.length) {
352
+ if (++guard > 1e5) throw new Error("[fluixi] effect flush did not settle (cycle?)");
353
+ const batchOf = G.queue;
354
+ G.queue = [];
355
+ for (const e of batchOf) {
356
+ e.queued = false;
357
+ if (!e.disposed) e.run();
358
+ }
359
+ }
360
+ } finally {
361
+ G.flushing = false;
362
+ }
363
+ }
364
+ function afterWrite() {
365
+ if (G.batchDepth === 0) flushSync();
366
+ }
367
+ function batch(fn) {
368
+ G.batchDepth++;
369
+ try {
370
+ return fn();
371
+ } finally {
372
+ if (--G.batchDepth === 0) flushSync();
373
+ }
374
+ }
375
+ var EffectNode = class {
376
+ constructor(fn, report = false) {
377
+ this.queued = false;
378
+ this.disposed = false;
379
+ this.owner = makeOwner(G.owner);
380
+ if (G.owner) (G.owner.cleanups ??= []).push(() => this.dispose());
381
+ this.computed = new Computed(() => {
382
+ disposeOwner(this.owner, false);
383
+ runWithOwner(this.owner, () => {
384
+ const r = fn();
385
+ if (typeof r === "function") (this.owner.cleanups ??= []).push(r);
386
+ });
387
+ });
388
+ reportReactiveNode({ kind: "effect", node: this.computed, handle: this, internal: !report });
389
+ this.watcher = new Watcher(() => enqueue(this));
390
+ this.run();
391
+ this.watcher.watch(this.computed);
392
+ }
393
+ run() {
394
+ if (this.disposed) return;
395
+ this.watcher.getPending();
396
+ try {
397
+ this.computed.get();
398
+ } catch (e) {
399
+ if (e && typeof e.then === "function" && G.onSuspend) {
400
+ G.onSuspend(e, this.owner);
401
+ return;
402
+ }
403
+ if (G.onError && G.onError(e, this.owner)) return;
404
+ throw e;
405
+ }
406
+ }
407
+ dispose() {
408
+ if (this.disposed) return;
409
+ this.disposed = true;
410
+ reportReactiveDispose(this.computed);
411
+ this.watcher.unwatch(this.computed);
412
+ disposeOwner(this.owner);
413
+ }
414
+ };
415
+ function effect(fn, report = false) {
416
+ const node = new EffectNode(fn, report);
417
+ return () => node.dispose();
418
+ }
419
+
420
+ // src/lib/signal/graph/compat.ts
421
+ setScheduler(() => {
422
+ });
423
+ var $SIGNAL = /* @__PURE__ */ Symbol.for("signal");
424
+ var $NODE = /* @__PURE__ */ Symbol.for("signal-node");
425
+ function createSignal(value, options) {
426
+ const state = new State(value, { equals: options?.equals });
427
+ const read = (() => state.get());
428
+ const write = ((next) => {
429
+ const v = typeof next === "function" ? next(state.peek()) : next;
430
+ state.set(v);
431
+ afterWrite();
432
+ return v;
433
+ });
434
+ Object.defineProperty(read, $SIGNAL, { value: true, enumerable: true });
435
+ Object.defineProperty(read, $NODE, {
436
+ value: {
437
+ get value() {
438
+ return state.peek();
439
+ },
440
+ get version() {
441
+ return state.version;
442
+ }
443
+ },
444
+ enumerable: false
445
+ });
446
+ reportReactiveNode({
447
+ kind: "signal",
448
+ node: state,
449
+ handle: read,
450
+ name: options?.name,
451
+ set: write
452
+ });
453
+ if (isObserved()) onCleanup(() => reportReactiveDispose(state));
454
+ return [read, write];
455
+ }
456
+ function createEffect(fn, value) {
457
+ let prev = value;
458
+ return effect(() => {
459
+ const r = fn(prev);
460
+ prev = r;
461
+ }, true);
462
+ }
463
+ function batch2(fn) {
464
+ return batch(fn);
465
+ }
466
+ function untrack2(fn) {
467
+ return untrack(fn);
468
+ }
469
+
470
+ // src/lib/signal/graph/ssr-hooks.ts
471
+ var _resourceTracker = null;
472
+ function trackResourcePromise(p) {
473
+ if (_resourceTracker) _resourceTracker(p);
474
+ }
475
+ var _serverDataGetter = null;
476
+ function getServerData(id) {
477
+ return _serverDataGetter ? _serverDataGetter(id) : void 0;
478
+ }
479
+ var _resourceIdSource = null;
480
+ function nextResourceId() {
481
+ return _resourceIdSource ? _resourceIdSource() : void 0;
482
+ }
483
+ var _resourceDataSink = null;
484
+ function reportResourceData(id, value) {
485
+ if (_resourceDataSink) _resourceDataSink(id, value);
486
+ }
487
+
488
+ // src/lib/signal/graph/resource.ts
489
+ function isPromise(v) {
490
+ return !!v && typeof v.then === "function";
491
+ }
492
+ var UNSET = /* @__PURE__ */ Symbol();
493
+ function createResource(source, fetcherFn, options = {}) {
494
+ let s;
495
+ let fetcher;
496
+ if (typeof fetcherFn === "function") {
497
+ s = typeof source === "function" ? source : () => source;
498
+ fetcher = fetcherFn;
499
+ } else {
500
+ s = () => true;
501
+ fetcher = source;
502
+ if (fetcherFn && typeof fetcherFn === "object") options = fetcherFn;
503
+ }
504
+ const ssrId = options.transport === false ? void 0 : nextResourceId();
505
+ const seed = ssrId !== void 0 ? getServerData(ssrId) : void 0;
506
+ let skipFirstFetch = seed !== void 0;
507
+ const [value, setValue] = createSignal(
508
+ seed !== void 0 ? seed.value : options.initialValue,
509
+ { equals: false }
510
+ );
511
+ const [error, setError] = createSignal(void 0, { equals: false });
512
+ const [state, setState] = createSignal(
513
+ seed !== void 0 || options.initialValue !== void 0 ? "ready" : "unresolved",
514
+ { equals: false }
515
+ );
516
+ const [promise, setPromise] = createSignal(void 0, { equals: false });
517
+ const [track, trigger] = createSignal(void 0, { equals: false });
518
+ let prevKey = UNSET;
519
+ let manualRefetch = false;
520
+ createEffect(() => {
521
+ const val = s();
522
+ track();
523
+ if (val === false || val === null || val === void 0) {
524
+ prevKey = UNSET;
525
+ batch2(() => {
526
+ setState("unresolved");
527
+ setPromise(void 0);
528
+ setError(void 0);
529
+ });
530
+ return;
531
+ }
532
+ const isManual = manualRefetch;
533
+ manualRefetch = false;
534
+ if (prevKey !== UNSET && val === prevKey && !isManual) return;
535
+ prevKey = val;
536
+ if (skipFirstFetch) {
537
+ skipFirstFetch = false;
538
+ return;
539
+ }
540
+ let cancelled = false;
541
+ onCleanup(() => cancelled = true);
542
+ const currentState = untrack2(state);
543
+ const currentValue = untrack2(value);
544
+ const isRefreshing = currentState === "ready" || currentState === "refreshing";
545
+ batch2(() => {
546
+ setState(isRefreshing ? "refreshing" : "pending");
547
+ setError(void 0);
548
+ });
549
+ try {
550
+ const res = fetcher(val, { value: currentValue, refetching: isRefreshing });
551
+ if (isPromise(res)) {
552
+ setPromise(res);
553
+ trackResourcePromise(res);
554
+ res.then(
555
+ (v) => {
556
+ if (cancelled) return;
557
+ if (ssrId !== void 0) reportResourceData(ssrId, v);
558
+ batch2(() => {
559
+ setValue(() => v);
560
+ setState("ready");
561
+ setPromise(void 0);
562
+ });
563
+ },
564
+ (e) => {
565
+ if (cancelled) return;
566
+ batch2(() => {
567
+ setError(e);
568
+ setState("errored");
569
+ setPromise(void 0);
570
+ });
571
+ }
572
+ );
573
+ } else {
574
+ batch2(() => {
575
+ setValue(() => res);
576
+ setState("ready");
577
+ setPromise(void 0);
578
+ });
579
+ }
580
+ } catch (e) {
581
+ if (cancelled) return;
582
+ batch2(() => {
583
+ setError(e);
584
+ setState("errored");
585
+ setPromise(void 0);
586
+ });
587
+ }
588
+ });
589
+ const loading = () => {
590
+ const st = state();
591
+ return st === "pending" || st === "refreshing";
592
+ };
593
+ const resource = (() => {
594
+ const e = error();
595
+ if (e) throw e;
596
+ if (loading()) {
597
+ const p = promise();
598
+ if (p) throw p;
599
+ }
600
+ return value();
601
+ });
602
+ Object.defineProperties(resource, {
603
+ state: { get: state },
604
+ loading: { get: loading },
605
+ error: { get: error },
606
+ latest: { get: value }
607
+ });
608
+ Object.defineProperty(resource, /* @__PURE__ */ Symbol.for("resource"), { value: true, enumerable: true });
609
+ Object.defineProperty(resource, /* @__PURE__ */ Symbol.for("signal"), { value: true, enumerable: true });
610
+ return [
611
+ resource,
612
+ {
613
+ mutate: setValue,
614
+ refetch: () => {
615
+ manualRefetch = true;
616
+ trigger(void 0);
617
+ }
618
+ }
619
+ ];
620
+ }
@@ -16,7 +16,7 @@ export type ResourceReturn<T> = [
16
16
  * createResource(fetcher, options?) or createResource(source, fetcher, options?).
17
17
  * Matches the legacy state machine + SSR seeding (no first fetch when seeded).
18
18
  *
19
- * The two typed overloads infer `T` from the fetcher's return without them the
19
+ * The two typed overloads infer `T` from the fetcher's return: without them the
20
20
  * `unknown` implementation signature gives every call site `ResourceReturn<{}>`,
21
21
  * so the accessor loses its type (the regression seen after the TC39-core switch).
22
22
  */
@@ -1,19 +1,19 @@
1
1
  /**
2
- * createResource ported onto the TC39 core (L0+L1 via the compat layer). This is
3
- * ADDITIVE the legacy `createResource` in ../signal.ts stays intact; this is the
2
+ * createResource, on the TC39 core by way of the compat layer. This is
3
+ * Additive, the legacy `createResource` in ../signal.ts stays intact; this is the
4
4
  * parallel implementation that runs on the new graph.
5
5
  *
6
6
  * Resources are the one part of the surface that touches framework-coupled bits, so
7
7
  * they're ported by hand. The SSR transport hooks (`nextResourceId`/`getServerData`/
8
8
  * `trackResourcePromise`/`reportResourceData`) are standalone module functions, so we
9
- * REUSE them from ../signal.ts same `__FX_DATA__` seeding + async-SSR drain as legacy.
9
+ * Reuse them from ../signal.ts, same `__FX_DATA__` seeding + async-SSR drain as legacy.
10
10
  *
11
11
  * Suspense boundary integration (throwing the pending promise to a boundary that
12
12
  * increments/decrements) lands with the Suspense port; the throwing getter is here so
13
13
  * a boundary built on the new effect can catch it.
14
14
  */
15
15
  import { createSignal, createEffect, batch, untrack, onCleanup, } from './compat.js';
16
- // Standalone SSR hooks graph-agnostic injectables.
16
+ // Standalone SSR hooks: graph-agnostic injectables.
17
17
  import { nextResourceId, getServerData, trackResourcePromise, reportResourceData, } from './ssr-hooks.js';
18
18
  function isPromise(v) {
19
19
  return !!v && typeof v.then === 'function';
@@ -33,14 +33,13 @@ export function createResource(source, fetcherFn, options = {}) {
33
33
  options = fetcherFn;
34
34
  }
35
35
  // SSR data transport: stable id; on the client seed from server-serialized value.
36
- //
37
36
  // `transport: false` opts out, and takes the id with it. The id is a position in
38
37
  // a per-render sequence that the client re-derives by counting resources in the
39
38
  // same order, so a resource that exists on one side and not the other shifts
40
39
  // every id after it. `lazy()` is exactly that: on the server the first request
41
40
  // for a route creates a resource for the module import and later requests find
42
41
  // it cached and create none, so the page's own resource was r1 for the first
43
- // visitor after a restart and r0 for everyone else while the client, which
42
+ // visitor after a restart and r0 for everyone else, while the client, which
44
43
  // preloads routes before hydrating, always said r0. Its value is a component
45
44
  // function and was never transportable anyway.
46
45
  const ssrId = options.transport === false ? undefined : nextResourceId();
@@ -72,7 +71,7 @@ export function createResource(source, fetcherFn, options = {}) {
72
71
  prevKey = val;
73
72
  if (skipFirstFetch) {
74
73
  skipFirstFetch = false;
75
- return; // seeded source tracked, but no first fetch (no flash on hydration)
74
+ return; // seeded: source tracked, but no first fetch (no flash on hydration)
76
75
  }
77
76
  let cancelled = false;
78
77
  onCleanup(() => (cancelled = true));
@@ -137,7 +136,7 @@ export function createResource(source, fetcherFn, options = {}) {
137
136
  if (loading()) {
138
137
  const p = promise();
139
138
  if (p)
140
- throw p; // suspends a boundary on the new effect catches this
139
+ throw p; // suspends, a boundary on the new effect catches this
141
140
  }
142
141
  return value();
143
142
  });