@volynets/reflex 0.1.0 → 0.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
- # `@volynetstyle/reflex`
1
+ # `@volynets/reflex`
2
2
 
3
- [![npm version](https://img.shields.io/npm/v/%40volynetstyle%2Freflex?logo=npm)](https://www.npmjs.com/package/@volynetstyle/reflex)
4
- [![npm downloads](https://img.shields.io/npm/dm/%40volynetstyle%2Freflex?logo=npm)](https://www.npmjs.com/package/@volynetstyle/reflex)
3
+ [![npm version](https://img.shields.io/npm/v/%40volynets%2Freflex?logo=npm)](https://www.npmjs.com/package/@volynets/reflex)
4
+ [![npm downloads](https://img.shields.io/npm/dm/%40volynets%2Freflex?logo=npm)](https://www.npmjs.com/package/@volynets/reflex)
5
5
  [![license: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/volynetstyle/Reflex/blob/main/packages/reflex/LICENSE)
6
6
  [![typed with TypeScript](https://img.shields.io/badge/typed-TypeScript-3178C6?logo=typescript&logoColor=white)](https://www.typescriptlang.org/)
7
7
  [![runtime: Reflex](https://img.shields.io/badge/runtime-Reflex-111827)](https://github.com/volynetstyle/Reflex)
@@ -12,7 +12,7 @@
12
12
 
13
13
  Small signal-style reactivity on top of the Reflex runtime.
14
14
 
15
- `@volynetstyle/reflex` is the product-facing API for building reactive state, derived values, effects, and event-driven state without dropping down to the lower-level runtime primitives.
15
+ `@volynets/reflex` is the product-facing API for building reactive state, derived values, effects, and event-driven state without dropping down to the lower-level runtime primitives.
16
16
 
17
17
  It gives you:
18
18
 
@@ -24,18 +24,17 @@ It gives you:
24
24
  Under the hood it is built on:
25
25
 
26
26
  - [`@reflex/runtime`](https://github.com/volynetstyle/Reflex/tree/main/packages/%40reflex/runtime) for reactive execution
27
- - [`@reflex/core`](https://github.com/volynetstyle/Reflex/tree/main/packages/%40reflex/core) for lower-level infrastructure
28
27
 
29
28
  ## Install
30
29
 
31
30
  ```bash
32
- npm install @volynetstyle/reflex
31
+ npm install @volynets/reflex
33
32
  ```
34
33
 
35
34
  ## Quick Start
36
35
 
37
36
  ```ts
38
- import { computed, createRuntime, effect, signal } from "@volynetstyle/reflex";
37
+ import { computed, createRuntime, effect, signal } from "@volynets/reflex";
39
38
 
40
39
  const rt = createRuntime();
41
40
 
@@ -83,7 +82,7 @@ The top-level primitives are not methods on `rt`, but they are still runtime-bac
83
82
  ### Signals and derived values
84
83
 
85
84
  ```ts
86
- import { computed, createRuntime, memo, signal } from "@volynetstyle/reflex";
85
+ import { computed, createRuntime, memo, signal } from "@volynets/reflex";
87
86
 
88
87
  createRuntime();
89
88
 
@@ -106,7 +105,7 @@ console.log(warmed()); // 290
106
105
  ### Events and accumulated state
107
106
 
108
107
  ```ts
109
- import { computed, createRuntime, effect, hold, scan } from "@volynetstyle/reflex";
108
+ import { computed, createRuntime, effect, hold, scan } from "@volynets/reflex";
110
109
 
111
110
  const rt = createRuntime();
112
111
  const updates = rt.event<number>();
@@ -141,7 +140,7 @@ import {
141
140
  map,
142
141
  merge,
143
142
  subscribeOnce,
144
- } from "@volynetstyle/reflex";
143
+ } from "@volynets/reflex";
145
144
 
146
145
  const rt = createRuntime();
147
146
  const clicks = rt.event<number>();
@@ -164,10 +163,11 @@ subscribeOnce(labels, (value) => {
164
163
  - `computed(fn)` is cached. Repeated clean reads reuse the last value.
165
164
  - `memo(fn)` is `computed(fn)` plus one eager warm-up read.
166
165
  - `effect(fn)` runs once immediately on creation.
167
- - If an effect returns cleanup, that cleanup runs before the next effect run and on dispose.
168
- - With the default runtime, invalidated effects run on `rt.flush()`.
169
- - With `createRuntime({ effectStrategy: "eager" })`, invalidated effects flush automatically.
170
- - Pure signal and computed reads do not require `flush()`.
166
+ - If an effect returns cleanup, that cleanup runs before the next effect run and on dispose.
167
+ - With the default runtime, invalidated effects run on `rt.flush()`.
168
+ - With `createRuntime({ effectStrategy: "sab" })`, invalidated effects stay lazy during a batch and auto-deliver when the outermost batch exits.
169
+ - With `createRuntime({ effectStrategy: "eager" })`, invalidated effects flush automatically.
170
+ - Pure signal and computed reads do not require `flush()`.
171
171
  - Same-value signal writes do not force recomputation.
172
172
  - Derived events created with `map()`, `filter()`, and `merge()` are lazy and subscribe upstream only while observed.
173
173
  - `scan()` and `hold()` update only from event deliveries.
@@ -178,20 +178,20 @@ subscribeOnce(labels, (value) => {
178
178
  `createRuntime()` returns an object with the runtime-facing pieces of the model:
179
179
 
180
180
  ```ts
181
- const rt = createRuntime({
182
- effectStrategy: "flush", // or "eager"
183
- hooks: {
184
- onEffectInvalidated(node) {
185
- // low-level integration hook
181
+ const rt = createRuntime({
182
+ effectStrategy: "flush", // or "sab" / "eager"
183
+ hooks: {
184
+ onEffectInvalidated(node) {
185
+ // low-level integration hook
186
186
  },
187
187
  },
188
188
  });
189
189
  ```
190
190
 
191
- Options:
192
-
193
- - `effectStrategy: "flush" | "eager"` controls whether invalidated effects wait for `rt.flush()` or run automatically
194
- - `hooks.onEffectInvalidated(node)` is a low-level hook for integrations that want to observe effect invalidation
191
+ Options:
192
+
193
+ - `effectStrategy: "flush" | "sab" | "eager"` controls whether invalidated effects wait for `rt.flush()`, stabilize after `batch()`, or run automatically
194
+ - `hooks.onEffectInvalidated(node)` is a low-level hook for integrations that want to observe effect invalidation
195
195
 
196
196
  Returned API:
197
197
 
@@ -334,7 +334,7 @@ They are exported as top-level functions, but they run against the currently con
334
334
 
335
335
  ### Do I always need to call `flush()`?
336
336
 
337
- No. You need `flush()` for scheduled effects when using the default `effectStrategy: "flush"`. You do not need `flush()` just to read up-to-date `signal()` or `computed()` values.
337
+ No. You need `flush()` for scheduled effects when using the default `effectStrategy: "flush"`. In `effectStrategy: "sab"`, effects auto-deliver after the outermost `batch()`. You do not need `flush()` just to read up-to-date `signal()` or `computed()` values.
338
338
 
339
339
  ### Is `computed()` lazy or eager?
340
340
 
@@ -346,7 +346,7 @@ Lazy. It does not run until the first read. After that it behaves like a cached
346
346
 
347
347
  ### Does `effect()` run immediately?
348
348
 
349
- Yes. It runs once on creation. Future re-runs happen after invalidation, either on `rt.flush()` or automatically when using the eager effect strategy.
349
+ Yes. It runs once on creation. Future re-runs happen after invalidation, either on `rt.flush()`, at the end of an outermost batch in `sab`, or automatically when using the eager effect strategy.
350
350
 
351
351
  ### Why do `scan()` and `hold()` return tuples instead of only an accessor?
352
352
 
@@ -1 +1 @@
1
- class ReactiveEdge{constructor(t,n,i,e,s,r){this.from=t,this.to=n,this.prevOut=i,this.nextOut=e,this.prevIn=s,this.nextIn=r}}function t(t){t.prevOut=null,t.nextOut=null,t.prevIn=null,t.nextIn=null}var n;(t=>{t[t.Producer=1]="Producer",t[t.Consumer=2]="Consumer",t[t.Watcher=4]="Watcher",t[t.Invalid=8]="Invalid",t[t.Changed=16]="Changed",t[t.Visited=32]="Visited",t[t.Disposed=64]="Disposed",t[t.Computing=128]="Computing",t[t.Scheduled=256]="Scheduled",t[t.Tracking=512]="Tracking"})(n||(n={}));const i=n.Producer|n.Consumer|n.Watcher,e=n.Invalid|n.Changed,s=n.Producer,r=n.Changed|n.Consumer,u=n.Changed|n.Watcher;function o(t){t.state&=~n.Computing}function l(t){t.state&=~e}function c(t){return 0!==(t.state&n.Disposed)}function f(t,n,i){const e=i?i.nextIn:t.firstIn;n.prevIn=i,n.nextIn=e,e?e.prevIn=n:t.lastIn=n,i?i.nextIn=n:t.firstIn=n}function h(t,n){const{prevIn:i,nextIn:e}=n;i?i.nextIn=e:t.firstIn=e,e?e.prevIn=i:t.lastIn=i}function a(t,n){const{prevOut:i,nextOut:e}=n;i?i.nextOut=e:t.firstOut=e,e?e.prevOut=i:t.lastOut=i}function d(t,n,i=n.lastIn){const e=t.lastOut,s=i?i.nextIn:n.firstIn,r=new ReactiveEdge(t,n,e,null,i,s);return e?e.nextOut=r:t.firstOut=r,t.lastOut=r,s?s.prevIn=r:n.lastIn=r,i?i.nextIn=r:n.firstIn=r,r}function v(t,n,i,e){for(let s=e?e.nextIn:n.firstIn;null!==s;s=s.nextIn)if(s.from===t)return s.prevIn!==i&&(h(n,s),f(n,s,i)),s;return d(t,n,i)}function p(e){c(e)||((t=>{t.state=t.state&i|n.Disposed})(e),e.depsTail=null,(n=>{let i=n.firstIn;for(n.firstIn=n.lastIn=n.depsTail=null;i;){const n=i.nextIn;a(i.from,i),t(i),i=n}})(e),(n=>{let i=n.firstOut;for(n.firstOut=n.lastOut=null;i;){const n=i.nextOut;i.to.depsTail===i&&(i.to.depsTail=i.prevIn),h(i.to,i),t(i),i=n}})(e),e.compute=null)}const y=Symbol.for("UNINITIALIZED");class ReactiveNode{constructor(t,n,i){this.state=i,this.compute=n,this.firstOut=null,this.firstIn=null,this.lastOut=null,this.lastIn=null,this.depsTail=null,this.payload=t}}function x(t,n){if(!Object.hasOwn(t,n))return;const i=t[n];return"function"==typeof i?i:void 0}class ExecutionContext{constructor(t={}){this.activeComputed=null,this.propagationDepth=0,this.cleanupRegistrar=null,this.onEffectInvalidatedHook=void 0,this.onReactiveSettledHook=void 0,this.hookMask=0,this.hooks={},Object.defineProperties(this.hooks,{onEffectInvalidated:{enumerable:!0,get:()=>this.onEffectInvalidatedHook,set:t=>{this.setOnEffectInvalidatedHook(t)}},onReactiveSettled:{enumerable:!0,get:()=>this.onReactiveSettledHook,set:t=>{this.setOnReactiveSettledHook(t)}}}),this.setHooks(t)}dispatchWatcherEvent(t){const n=this.onEffectInvalidatedHook;void 0!==n&&n?.(t)}maybeNotifySettled(){if(!(2&this.hookMask))return;if(0!==this.propagationDepth||null!==this.activeComputed)return;const t=this.onReactiveSettledHook;t?.()}enterPropagation(){++this.propagationDepth}leavePropagation(){this.propagationDepth>0&&--this.propagationDepth,this.maybeNotifySettled()}resetState(){this.activeComputed=null,this.propagationDepth=0,this.cleanupRegistrar=null}setHooks(t={}){const n=x(t,"onEffectInvalidated"),i=x(t,"onReactiveSettled");this.hooks.onEffectInvalidated=n,this.hooks.onReactiveSettled=i}registerWatcherCleanup(t){this.cleanupRegistrar?.(t)}withCleanupRegistrar(t,n){const i=this.cleanupRegistrar;this.cleanupRegistrar=t;try{return n()}finally{this.cleanupRegistrar=i}}setOnEffectInvalidatedHook(t){this.onEffectInvalidatedHook="function"==typeof t?t:void 0,this.updateHookMask(1,void 0!==this.onEffectInvalidatedHook)}setOnReactiveSettledHook(t){this.onReactiveSettledHook="function"==typeof t?t:void 0,this.updateHookMask(2,void 0!==this.onReactiveSettledHook)}updateHookMask(t,n){this.hookMask=n?this.hookMask|t:this.hookMask&~t}}let b=E(void 0);function E(t={}){return new ExecutionContext(t)}function g(){return b}const S=Object.is;function I(t,n=g()){const i=n.activeComputed;if(!i)return;const e=c(t),s=c(i);if(e||s)return;const r=i.depsTail;if(null===r){const n=i.firstIn;return null===n?void(i.depsTail=d(t,i,null)):n.from===t?void(i.depsTail=n):void(i.depsTail=v(t,i,null,n))}if(r.from===t)return;const u=r.nextIn;i.depsTail=null===u||u.from!==t?v(t,i,r,u):u}function w(n,i=g()){const e=n.depsTail,s=null===e?n.firstIn:e.nextIn;null!==s&&(null===e?(n.firstIn=null,n.lastIn=null):(e.nextIn=null,n.lastIn=e),(n=>{for(;n;){const i=n.nextIn;a(n.from,n),t(n),n=i}})(s))}function N(t,i){t.depsTail=null,t.state=t.state&~n.Visited|n.Tracking,(t=>{t.state|=n.Computing})(t);const e=i.activeComputed;i.activeComputed=t;let s=!1;return()=>{s||(s=!0,i.activeComputed=e)}}function R(t,i=g()){if(c(t))return!1;const e=t.payload;let s=e,r=!1;return s=((t,i=g())=>{const e=t.compute,s=N(t,i);let r;try{return r=e(),s(),w(t,i),r}catch(t){throw s(),t}finally{t.state&=~n.Tracking,o(t),i.maybeNotifySettled()}})(t,i),c(t)||(r=!S(e,s),t.payload=s),l(t),r}const k=n.Invalid,m=n.Changed,C=n.Invalid|n.Changed|n.Disposed|n.Visited|n.Tracking;function O(t,n,i){const e=i.onEffectInvalidatedHook;if(void 0===e)return n;try{e(t)}catch(t){return n??t}return n}function D(t,i=g()){if(0!==(t.state&n.Disposed))return;let s=null;for(let r=t.firstOut;null!==r;r=r.nextOut){const t=r.to,u=t.state;if((u&e)!==n.Invalid)continue;const o=u&~n.Invalid|n.Changed;t.state=o,0!==(o&n.Watcher)&&(s=O(t,s,i))}if(null!==s)throw s}const H=[],P=[];function j(t,i,s){return 0!==(i&(e|n.Disposed))?0:0===(i&n.Tracking)?i&~n.Visited|s:((t,n)=>{if(null===n)return!1;for(let i=t.prevIn;null!==i;i=i.prevIn)if(i===n)return!1;return!0})(t,t.to.depsTail)?i|n.Visited|n.Invalid:0}function A(t,i,e,s,r){const u=H,o=P,l=u.length;let c=l,f=k;for(;;){const h=t.to,a=h.state;let d=0;if(d=0===(a&C)?a|f:j(t,a,f),0!==d)if(h.state=d,0!==(d&n.Watcher))s=O(h,s,r);else{const n=h.firstOut;if(null!==n){null!==i&&(u[c]=i,o[c++]=e),t=n,i=n.nextOut,f=e=k;continue}}if(null!==i)t=i,f=e;else{if(l>=c)return u.length=o.length=l,s;t=u[--c],f=e=o[c]}i=t.nextOut}}function T(t,i,s){return 0!==(i&(e|n.Disposed))?0:0===(i&n.Tracking)?i&~n.Visited|s:((t,n)=>{if(null===n)return!1;if(t===n)return!0;for(let i=t.prevIn;null!==i;i=i.prevIn)if(i===n)return!1;return!0})(t,t.to.depsTail)?i|n.Visited|n.Invalid:0}function W(t,n,i){const e=R(n,i);return!e||null===t.prevOut&&null===t.nextOut||D(n,i),e}function B(t,i,s,r,u,o){let l=!1;t:for(;;){const c=t.from,f=c.state;if(0!==(i.state&n.Changed))l=!0;else if(0!==(f&n.Changed))l=W(t,c,s);else if(0!==(f&e)){const n=c.firstIn;if(null!==n){r[u++]=t,t=n,i=c;continue}l=W(t,c,s)}if(!l){const e=t.nextIn;if(null!==e){t=e;continue}i.state&=~n.Invalid}for(;u>o;){const e=r[--u];if(l?l=W(e,i,s):i.state&=~n.Invalid,i=e.to,!l){const n=e.nextIn;if(null!==n){t=n;continue t}}}return l}}const L=[],U=n.Producer|n.Disposed,Z=n.Invalid|n.Visited;function q(t){const i=t.state;if(0!==(i&U))return!1;if(0!==(i&n.Changed)||(i&Z)===Z)return!0;const s=t.firstIn;return null===s?(t.state=i&~n.Invalid,!1):((t,i,s)=>{const r=L,u=r.length;let o=u,l=i,c=t,f=!1;for(;;){if(null!==l.nextIn)return B(l,c,s,r,o,u);if(0!==(c.state&n.Changed)){f=!0;break}const t=l.from,i=t.state;if(0!==(i&n.Changed)&&(f=W(l,t,s),f||null===l.nextIn))break;if(0!==(i&e)){const n=t.firstIn;if(null!==n){if(null!==n.nextIn){r[o++]=l;const i=B(n,t,s,r,o,u);return r.length=u,i}r[o++]=l,l=n,c=t;continue}f=W(l,t,s);break}if(c.state&=~n.Invalid,o===u)return!1;l=r[--o],c=l.to}for(;o>u;){const t=r[--o];f?f=W(t,c,s):c.state&=~n.Invalid,c=t.to}return f||(c.state&=~n.Invalid),r.length=u,f})(t,s,g())}var z;function F(t,n=g()){return c(t)||I(t,n),t.payload}function M(t,i){const s=t.state;return 0!==(s&n.Disposed)||0!==(s&e)&&(0!==(s&n.Changed)||q(t)?R(t,i)&&D(t,i):l(t)),t.payload}function V(t,n=z.lazy,i=g()){if(n===z.eager){const n=i.activeComputed;let e;i.activeComputed=null;try{e=M(t,i)}finally{i.activeComputed=n}return e}const e=M(t,i);return c(t)||I(t,i),e}function G(t,i,e=S,s=g()){if(c(t))return;if(e(t.payload,i))return;t.payload=i;const r=t.firstOut;if(null!==r){s.enterPropagation();try{((t,i=k,e=g())=>{if(0!==(t.from.state&n.Disposed))return;const s=((t,i,e,s)=>{for(;;){const r=t.to,u=r.state;let o=0;o=0===(u&C)?u|i:T(t,u,i);const l=t.nextOut;if(o)if(r.state=o,0!==(o&n.Watcher))e=O(r,e,s);else{const n=r.firstOut;if(null!==n){if(null!==l)return A(n,l,i,e,s);t=n,i=k;continue}}if(null===l)return e;t=l}})(t,i,null,e);if(null!==s)throw s})(r,m,s)}finally{s.leavePropagation()}}}function J(t,i=g()){const s=t.state;if(0!==(s&n.Disposed))return;if(0===(s&e)||0===(s&n.Changed)&&!q(t))return void l(t);const r="function"==typeof t.payload?t.payload:null;if(t.payload=y,(t=>{t.state&=~n.Visited})(t),l(t),r?.(),c(t))return;let u=!1;((t,i,e=g())=>{const s=t.compute,r=N(t,e);let u;try{return u=s(),r(),w(t,e),i(u)}catch(t){throw r(),t}finally{t.state&=~n.Tracking,o(t),e.maybeNotifySettled()}})(t,n=>{c(t)||(u="function"==typeof n,u&&(t.payload=n))},i)}(t=>{t[t.lazy=1]="lazy",t[t.eager=2]="eager"})(z||(z={}));class EventSource{constructor(){this.dispatchDepth=0,this.head=null,this.tail=null,this.pendingHead=null}}const K=Symbol("EventSubscriber.owner");function Q(t){return t[K]}function X(t,n){t[K]=n}function Y(t){return t()}function $(t,n){const i=n.prev,e=n.next;null===i?t.head=e:i.next=e,null===e?t.tail=i:e.prev=i,n.prev=null,n.next=null,n.unlinkNext=null,X(n,null)}function _(t,n,i=Y){i(()=>{const i=t.tail;if(null!==i){++t.dispatchDepth;try{let e=t.head;for(;null!==e;){const t=e===i?null:e.next;1&e.state&&e.fn(n),e=t}}finally{--t.dispatchDepth,0===t.dispatchDepth&&null!==t.pendingHead&&(t=>{let n=t.pendingHead;for(t.pendingHead=null;null!==n;){const i=n.unlinkNext;n.unlinkNext=null,$(t,n),n=i}})(t)}}})}const tt=Symbol("UNINITIALIZED");function nt(t){return new ReactiveNode(tt,t,r)}function it(t){t.state&=~n.Scheduled}class EffectScheduler{constructor(t,n){this.queue=[],this.head=0,this.batchDepth=0,this.phase=0,this.mode=t,this.context=n}getContext(){return this.context??g()}enqueue(t){this.isNodeIgnored(t)||((t=>{t.state|=n.Scheduled})(t),this.queue.push(t),this.shouldAutoFlush()&&this.flush())}batch(t){this.enterBatch();try{return t()}finally{this.leaveBatch()}}flush(){if(2&this.phase)return;if(!this.hasPending())return;this.phase=2;const t=this.getContext();try{for(;this.queue.length>this.head;){const n=this.queue[this.head++];it(n),this.shouldSkipNode(n)||J(n,t)}}finally{this.queue.length=0,this.head=0,this.phase=this.batchDepth>0?1:0,0===this.phase&&this.shouldAutoFlush()&&this.flush()}}reset(){this.queue.length=0,this.head=0,this.batchDepth=0,this.phase=0}notifySettled(){this.shouldAutoFlush()&&this.flush()}hasPending(){return this.queue.length>this.head}isNodeIgnored(t){return 0!==(t.state&n.Disposed)||0!==(t.state&n.Scheduled)}shouldSkipNode(t){return 0!==(t.state&n.Disposed)||0===(t.state&e)}shouldAutoFlush(){const t=this.getContext();return 1===this.mode&&0===this.phase&&0===t.propagationDepth&&null===t.activeComputed&&this.hasPending()}enterBatch(){++this.batchDepth,2!==this.phase&&(this.phase=1)}leaveBatch(){--this.batchDepth,0===this.batchDepth&&2!==this.phase&&(this.phase=0,this.shouldAutoFlush()&&this.flush())}}class EventDispatcher{constructor(t=Y){this.queue=[],this.head=0,this.flushing=!1,this.flush=()=>{if(!this.flushing){this.flushing=!0;try{const t=this.queue;for(;t.length>this.head;)_(t[this.head++],t[this.head++])}finally{this.queue.length=0,this.head=0,this.flushing=!1}}},this.runBoundary=t}emit(t,n){this.queue.push(t,n),this.flushing||this.runBoundary(this.flush)}}function et(t){return{subscribe:t}}function st(t,n,i){const e=new ReactiveNode(n,null,s);let r=t.subscribe(t=>{c(e)||G(e,i(e.payload,t))});return[()=>c(e)?e.payload:F(e),()=>{(t=>{p(t)})(e);const t=r;r=void 0,t?.()}]}exports.computed=t=>{const n=nt(t);return()=>V(n)},exports.createRuntime=t=>{const{scheduler:n,dispatcher:i,executionContext:e}=(t=>{const n=t?.hooks,i=E(),e=new EffectScheduler((s=t?.effectStrategy,"eager"===s?1:0),i);var s;const r=new EventDispatcher(t=>e.batch(t));return i.setHooks({...n,onEffectInvalidated(t){e.enqueue(t),n?.onEffectInvalidated?.(t)},onReactiveSettled(){e.notifySettled(),n?.onReactiveSettled?.()}}),{scheduler:e,dispatcher:r,executionContext:i}})(t);return e.resetState(),(t=>{b=t})(e),{get ctx(){return e},event(){const t=new EventSource;return{subscribe(n){return((t,n)=>{const i={fn:n,next:null,prev:null,state:1,unlinkNext:null};return((t,n)=>{if(!(1&n.state))return;if(null!=Q(n))return;const i=t.tail;n.prev=i,n.next=null,n.unlinkNext=null,X(n,t),null!==i?(i.next=n,t.tail=n):t.head=t.tail=n})(t,i),()=>{((t,n)=>{Q(n)===t&&1&n.state&&(n.state&=-2,0===t.dispatchDepth?(n.state|=2,$(t,n)):((t,n)=>{2&n.state||(n.state|=2,n.unlinkNext=t.pendingHead,t.pendingHead=n)})(t,n))})(t,i)}})(t,n)},emit(n){i.emit(t,n)}}},flush(){n.flush()}}},exports.effect=t=>{const n=new ReactiveNode(null,t,u),i=g();J(n,i);const e=()=>(t=>{p(t);const n="function"==typeof t.payload?t.payload:null;n?.(),t.payload=y})(n);return i.registerWatcherCleanup(e),e},exports.filter=(t,n)=>et(i=>t.subscribe(t=>{n(t)&&i(t)})),exports.hold=(t,n)=>st(t,n,(t,n)=>n),exports.map=(t,n)=>et(i=>t.subscribe(t=>{i(n(t))})),exports.memo=t=>{const n=nt(t);return V(n,z.eager),()=>V(n)},exports.merge=(...t)=>et(n=>{const i=t.map(t=>t.subscribe(t=>{n(t)}));return()=>{for(const t of i)t()}}),exports.scan=(t,n,i)=>st(t,n,i),exports.signal=(t,n)=>{const i=new ReactiveNode(t,null,s);return[()=>F(i),t=>{const n="function"!=typeof t?t:t(i.payload);return G(i,n),n}]},exports.subscribeOnce=(t,n)=>{let i,e=!0,s=!1;const r=()=>{if(!e)return;e=!1;const t=i;void 0!==t?(i=void 0,t()):s=!0};if(i=t.subscribe(t=>{e&&(r(),n(t))}),s){const t=i;i=void 0,t?.()}return r};
1
+ class ReactiveEdge{constructor(t,n,i,r,u,e,o){this.version=t,this.prevOut=n,this.nextOut=i,this.from=r,this.to=u,this.prevIn=e,this.nextIn=o}}function t(t){t.prevOut=t.nextOut=t.prevIn=t.nextIn=null}const n=24;function i(t){t.state&=-25}function r(t){return!!(64&t.state)}const u=Symbol.for("UNINITIALIZED");class ReactiveNode{constructor(t,n,i){this.state=0|i,this.firstOut=null,this.firstIn=null,this.lastOut=null,this.lastIn=null,this.depsTail=null,this.compute=n,this.payload=t}}let e;function o(t,n,i){const r=i?i.nextIn:t.firstIn;n.prevIn=i,n.nextIn=r,r?r.prevIn=n:t.lastIn=n,i?i.nextIn=n:t.firstIn=n}function l(t,n){const{prevIn:i,nextIn:r}=n;i?i.nextIn=r:t.firstIn=r,r?r.prevIn=i:t.lastIn=i}function s(t,n){const{prevOut:i,nextOut:r}=n;i?i.nextOut=r:t.firstOut=r,r?r.prevOut=i:t.lastOut=i}function c(t,n,i=n.lastIn,r=0){const u=t.lastOut,e=i?i.nextIn:n.firstIn,o=new ReactiveEdge(r,u,null,t,n,i,e);return u?u.nextOut=o:t.firstOut=o,t.lastOut=o,e?e.prevIn=o:n.lastIn=o,i?i.nextIn=o:n.firstIn=o,o}function f(t,n,i,r,u=0){const e=t.lastOut;if(null!=e&&e.version===u&&e.to===n)return e;for(let e=r?r.nextIn:n.firstIn;null!==e;e=e.nextIn)if(e.from===t)return e.prevIn!==i&&(l(n,e),o(n,e,i)),e.version=u,e;return c(t,n,i,u)}function h(n){r(n)||((t=>{t.state=7&t.state|64})(n),n.depsTail=null,(n=>{let i=n.firstIn;for(n.firstIn=n.lastIn=n.depsTail=null;i;){const n=i.nextIn;s(i.from,i),t(i),i=n}})(n),(n=>{let i=n.firstOut;for(n.firstOut=n.lastOut=null;i;){const n=i.nextOut;i.to.depsTail===i&&(i.to.depsTail=i.prevIn),l(i.to,i),t(i),i=n}})(n),n.compute=null,n.payload=u)}let a=f;class ExecutionContext{constructor(t={},n={}){this.activeComputed=null,this.trackingVersion=0,this.propagationDepth=0,this.cleanupRegistrar=null,this.trackReadFallback=f,this.onEffectInvalidated=void 0,this.onReactiveSettled=void 0,this.runtimeOnEffectInvalidated=void 0,this.runtimeOnReactiveSettled=void 0,this.effectInvalidatedDispatch=void 0,this.settledDispatch=void 0,this.setHooks(t),this.setOptions(n)}dispatchWatcherEvent(t){this.effectInvalidatedDispatch?.(t)}maybeNotifySettled(){0===this.propagationDepth&&null===this.activeComputed&&this.settledDispatch?.()}enterPropagation(){++this.propagationDepth}leavePropagation(){this.propagationDepth>0&&--this.propagationDepth,this.maybeNotifySettled()}resetState(){this.activeComputed=null,this.trackingVersion=0,this.propagationDepth=0,this.cleanupRegistrar=null}setOptions(t={}){this.trackReadFallback=a="function"==typeof t.trackReadFallback?t.trackReadFallback:f}setHooks(t={}){this.onEffectInvalidated="function"==typeof t.onEffectInvalidated?t.onEffectInvalidated:void 0,this.onReactiveSettled="function"==typeof t.onReactiveSettled?t.onReactiveSettled:void 0,this.refreshDispatchers()}setRuntimeHooks(t,n){this.runtimeOnEffectInvalidated="function"==typeof t?t:void 0,this.runtimeOnReactiveSettled="function"==typeof n?n:void 0,this.refreshDispatchers()}registerWatcherCleanup(t){this.cleanupRegistrar?.(t)}withCleanupRegistrar(t,n){const i=this.cleanupRegistrar;this.cleanupRegistrar=t;try{return n()}finally{this.cleanupRegistrar=i}}refreshDispatchers(){const t=this.runtimeOnEffectInvalidated,n=this.onEffectInvalidated,i=this.runtimeOnReactiveSettled,r=this.onReactiveSettled;this.effectInvalidatedDispatch=e=t&&n?i=>{t(i),n(i)}:t??n,this.settledDispatch=i&&r?()=>{i(),r()}:i??r}}let v=new ExecutionContext;function d(){return v}const p=Object.is;function y(t,n){const i=n.depsTail,r=v.trackingVersion,u=t.lastOut;if(null!=u&&u.version===r&&u.to===n)return!0;if(null!=i){if(i.from===t)return i.version=r,!0;const u=i.nextIn;return null!=u&&u.from===t&&(u.version=r,n.depsTail=u,!0)}const e=n.firstIn;return null!=e&&e.from===t&&(e.version=r,n.depsTail=e,!0)}function x(t,n){const i=v.trackingVersion,u=r(t),e=r(n);if(u||e)return;const o=n.depsTail;if(null===o){const r=n.firstIn;return null===r?void(n.depsTail=c(t,n,null,i)):r.from===t?(r.version=i,void(n.depsTail=r)):null===r.nextIn?void(n.depsTail=c(t,n,null,i)):void(n.depsTail=a(t,n,null,r,i))}if(o.from===t)return void(o.version=i);const l=o.nextIn;return null===l?void(n.depsTail=c(t,n,o,i)):l.from===t?(l.version=i,void(n.depsTail=l)):null===l.nextIn?void(n.depsTail=c(t,n,o,i)):void(n.depsTail=a(t,n,o,l,i))}function b(t,n){v.activeComputed=n,t.state&=-513,(t=>{t.state&=-129})(t)}function w(n){const i=n.compute,r=(t=>{const n=v,i=n.trackingVersion+1>>>0;t.depsTail=null,t.state=-33&t.state|512,(t=>{t.state|=128})(t),n.trackingVersion=0===i?1:i;const r=n.activeComputed;return n.activeComputed=t,r})(n);let u;try{return u=i(),b(n,r),n.depsTail!==n.lastIn&&(n=>{const i=n.depsTail,r=null===i?n.firstIn:i.nextIn;if(null===r)return;const u=r;null===i?(n.firstIn=null,n.lastIn=null):(i.nextIn=null,n.lastIn=i),(n=>{for(;n;){const i=n.nextIn;s(n.from,n),t(n),n=i}})(u)})(n),u}catch(t){throw b(n,r),t}}function g(t){if(r(t))return!1;const n=t.payload;let u=n,e=!1;return u=w(t),r(t)||(e=!p(n,u),t.payload=u),i(t),e}function E(t){if(64&t.state)return;let i=null;const r=e;for(let u=t.firstOut;null!==u;u=u.nextOut){const e=u.to,o=e.state;if(8!==(o&n))continue;const l=o^n;if(e.state=l,4&l&&void 0!==r)try{r(e)}catch(t){null===i&&(i=t)}}if(null!==i)throw i}const N=[];function R(t){return g(t)}function S(t){return null!==t.prevOut||null!==t.nextOut}function m(t,n){const i=R(t);return i&&n&&E(t),i}function C(t,n){const i=R(t);return i&&n&&E(t),i}function k(t,i,r,u,e){let o=!1;t:for(;;){if(16&i.state)o=!0;else{const e=t.from,l=e.state;if(16&l)o=C(e,S(t));else if(0!==(l&n)){const n=e.firstIn;if(null!==n){r[u++]=t,t=n,i=e;continue}o=C(e,S(t))}}if(!o){const n=t.nextIn;if(null!==n){t=n;continue}i.state&=-9}for(;u>e;){const n=r[--u],e=S(n);if(o?o=C(i,e):i.state&=-9,i=n.to,!o){const i=n.nextIn;if(null!==i){t=i;continue t}}}return o}}function D(t,i){const r=N,u=r.length;let e=u,o=i,l=t,s=!1;for(;;){if(null!==o.nextIn)return k(o,l,r,e,u);if(16&l.state){s=!0;break}const t=o.from,i=t.state;if(16&i){s=m(t,S(o));break}if(0!==(i&n)){const n=t.firstIn;if(null!==n){if(null!==n.nextIn){r[e++]=o;const i=k(n,t,r,e,u);return r.length=u,i}r[e++]=o,o=n,l=t;continue}s=m(t,S(o));break}if(l.state&=-9,e===u)return r.length=u,!1;o=r[--e],l=o.to}for(;e>u;){const t=r[--e],n=S(t);s?s=C(l,n):l.state&=-9,l=t.to}return s||(l.state&=-9),r.length=u,s}function I(t){return"function"==typeof t?t:null}function O(t){const r=t.state;if(64&r)return;if(0===(r&n))return;if(!((t,n)=>{if(16&n)return!0;if(!(40&~n))return!0;const i=t.firstIn;return null===i?(t.state=-9&n,!1):D(t,i)})(t,r))return void i(t);const e=I(t.payload);if(t.payload=u,(t=>{t.state&=-33})(t),null!==e&&e(),64&t.state)return;const o=w(t);"function"==typeof o&&(t.payload=o),32&t.state?t.state=-17&t.state|8:i(t)}function q(t){const n=I(t.payload);h(t),null!==n&&n(),t.payload=u}const A=[],B=[];function H(t,n,i){if(void 0!==n)try{n(t)}catch(t){if(null===i)return t}return i}function P(t,i,r,u){const e=-33&r|u,o=40|r;if(!(600&r))return e;if(64&r)return 0;if(512&r){const n=i.depsTail;if(null===n)return 0;if(t===n)return o;const r=t.prevIn;if(null===r)return o;if(r===n)return 0;let u=r.prevIn;for(;null!==u&&u!==n;)u=u.prevIn;return u===n?0:o}return 0!==(r&n)?0:e}function W(t,n,i,r,u){const o=A,l=B,s=o.length;let c=s,f=t.nextOut,h=n;const a=e;for(null!==r&&(o[c]=r,l[c++]=u);;){const r=t.to,u=r.state,e=600&u?P(t,r,u,n):-33&u|n;if(0!==e)if(r.state=e,4&e)i=H(r,a,i);else{const i=r.firstOut;if(null!==i){null!==f&&(o[c]=f,l[c++]=h),f=(t=i).nextOut,n=h=8;continue}}if(null===f){if(c===s)return o.length=s,l.length=s,i;t=o[--c],n=h=l[c],f=t.nextOut}else n=h,f=(t=f).nextOut}}function j(t){if(r(t))return t.payload;const n=v.activeComputed;return null!==n&&(y(t,n)||x(t,n)),t.payload}function z(t){const r=t.state;return 64&r||0===(r&n)||(((t,n)=>{if(16&n)return!0;if(!(40&~n))return!0;const i=t.firstIn;return null===i?(t.state=-9&n,!1):D(t,i)})(t,r)?g(t)&&null!==t.firstOut&&E(t):i(t)),t.payload}function L(t){const i=t.state;if(64&i)return t.payload;const u=0!==(i&n)?z(t):t.payload;if(0!==(i&n)&&r(t))return u;const e=v.activeComputed;return null!==e&&(y(t,e)||x(t,e)),u}function T(t,n,i=p){if(r(t))return;if(i(t.payload,n))return;t.payload=n;const u=t.firstOut;if(null===u)return;const o=v;o.enterPropagation();try{((t,n=8)=>{if(64&t.from.state)return;const i=((t,n)=>{let i=null;const r=e;for(;;){const u=t.to,e=t.nextOut,o=u.state,l=600&o?P(t,u,o,n):-33&o|n;if(0!==l)if(u.state=l,4&l)i=H(u,r,i);else{const r=u.firstOut;if(null!==r){if(t=r,null!==e)return W(t,8,i,e,n);n=8;continue}}if(null===e)return i;t=e}})(t,n);if(null!==i)throw i})(u,16)}finally{o.leavePropagation()}}class EventSource{constructor(){this.dispatchDepth=0,this.head=null,this.tail=null,this.pendingHead=null}}const U=Symbol("EventSubscriber.owner");function Z(t){return t[U]}function _(t,n){t[U]=n}function F(t){return t()}function G(t,n){const i=n.prev,r=n.next;null===i?t.head=r:i.next=r,null===r?t.tail=i:r.prev=i,n.prev=null,n.next=null,n.unlinkNext=null,_(n,null)}function J(t,n,i=F){i(()=>{const i=t.tail;if(null!==i){++t.dispatchDepth;try{let r=t.head;for(;null!==r;){const t=r===i?null:r.next;1&r.state&&r.fn(n),r=t}}finally{--t.dispatchDepth,0===t.dispatchDepth&&null!==t.pendingHead&&(t=>{let n=t.pendingHead;for(t.pendingHead=null;null!==n;){const i=n.unlinkNext;n.unlinkNext=null,G(t,n),n=i}})(t)}}})}const K=t=>new ReactiveNode(void 0,t,18);class EventDispatcher{constructor(t=F){this.queue=[],this.head=0,this.flushing=!1,this.runBoundary=t,this.flush=()=>this._flush(),this.flush=this._flush.bind(this)}emit(t,n){this.queue.push(t,n),this.flushing||this.runBoundary(this.flush)}_flush(){if(!this.flushing){this.flushing=!0;try{const t=this.queue;for(;t.length>this.head;)J(t[this.head++],t[this.head++])}finally{this.queue.length=0,this.head=0,this.flushing=!1}}}}function M(t){const n=this.ring;this.size===n.length&&(t=>{const n=t.ring,i=n.length;if(0===i)return void(n.length=16);const r=t.size,u=t.head,e=i-1,o=i<<1,l=Array(o);for(let t=0;r>t;++t)l[t]=n[u+t&e];n.length=o;for(let t=0;r>t;++t)n[t]=l[t];t.head=0,t.tail=r})(this);const i=this.tail;n[i]=t,this.tail=i+1&n.length-1,++this.size}function Q(){if(0===this.size)return null;const t=this.ring,n=this.head,i=t[n];return t[n]=void 0,this.head=n+1&t.length-1,--this.size,i}function V(){this.head=0,this.tail=0,this.size=0}const X=O.bind(null);function Y(t){return 0===t.propagationDepth&&null===t.activeComputed}function $(t,n){return 0===n.phase&&0===n.batchDepth&&Y(t)}function tt(){const t={ring:[],head:0,tail:0,size:0,push:M,shift:Q,clear:V};let n=0,i=0;return{queue:t,flush(){if(2!==i&&0!==t.size){i=2;try{for(;0!==t.size;){const n=t.shift();n.state=-257&n.state,X(n)}}finally{t.clear(),i=n>0?1:0}}},enterBatch(){1===++n&&2!==i&&(i=1)},leaveBatch(){return 0===--n&&2!==i&&(i=0,!0)},reset(){for(;0!==t.size;)t.shift().state&=-257;t.clear(),n=0,i=0},get batchDepth(){return n},get phase(){return i}}}function nt(t,n){const i=n,r=i.state;return!(320&r||(i.state=256|r,t.push(i),0))}function it(t,n,i,r,u,e,o){return{ring:i.queue.ring,mode:t,context:n,runtimeNotifySettled:o,enqueue:r,batch:u,flush:i.flush,notifySettled:e,reset:i.reset,get head(){return i.queue.head},get batchDepth(){return i.batchDepth},get phase(){return i.phase}}}function rt(){}const ut={eager:1,sab:2,flush:0};function et(t){return{subscribe:t}}function ot(t,n,i){const u=new ReactiveNode(n,null,1);let e=n,o=t.subscribe(t=>{r(u)||(e=i(e,t),T(u,e))});return[()=>r(u)?e:j(u),()=>{(t=>{h(t)})(u);const t=o;o=void 0,t?.()}]}exports.computed=t=>{const n=K(t);return L.bind(null,n)},exports.createRuntime=t=>{const{scheduler:n,dispatcher:i,executionContext:r}=(t=>{const n=((t={},n={})=>new ExecutionContext(t,n))(t?.hooks),i=((t=0,n=d())=>{switch(t){case 1:return(t=>{const n=tt(),i=n.queue,r=()=>{$(t,n)&&0!==i.size&&n.flush()},u=nt.bind(null,i);return it(1,t,n,i=>{u(i)&&$(t,n)&&n.flush()},t=>{n.enterBatch();try{return t()}finally{n.leaveBatch()&&0!==i.size&&n.flush()}},r,r)})(n);case 2:return(t=>{const n=tt(),i=n.queue,r=nt.bind(null,i);return it(2,t,n,r,r=>{n.enterBatch();try{return r()}finally{n.leaveBatch()&&0!==i.size&&Y(t)&&n.flush()}},rt,void 0)})(n);default:return(t=>{const n=tt(),i=nt.bind(null,n.queue);return it(0,t,n,i,t=>{n.enterBatch();try{return t()}finally{n.leaveBatch()}},rt,void 0)})(n)}})((r=t?.effectStrategy,r?ut[r]:0),n);var r;const u=new EventDispatcher(i.batch);return n.setRuntimeHooks(i.enqueue,i.runtimeNotifySettled),n.resetState(),(t=>{v=t})(n),{scheduler:i,dispatcher:u,executionContext:n}})(t);return{ctx:r,batch:n.batch,event(){const t=new EventSource;return{subscribe(n){return((t,n)=>{const i={fn:n,next:null,prev:null,state:1,unlinkNext:null};return((t,n)=>{if(!(1&n.state))return;if(null!=Z(n))return;const i=t.tail;n.prev=i,n.next=null,n.unlinkNext=null,_(n,t),null!==i?(i.next=n,t.tail=n):t.head=t.tail=n})(t,i),()=>{((t,n)=>{Z(n)===t&&1&n.state&&(n.state&=-2,0===t.dispatchDepth?(n.state|=2,G(t,n)):((t,n)=>{2&n.state||(n.state|=2,n.unlinkNext=t.pendingHead,t.pendingHead=n)})(t,n))})(t,i)}})(t,n)},emit(n){i.emit(t,n)}}},flush:n.flush}},exports.effect=t=>{const n=d(),i=new ReactiveNode(void 0,t,20);O(i);const r=q.bind(null,i);return n.registerWatcherCleanup(r),r},exports.filter=(t,n)=>et(i=>t.subscribe(t=>{n(t)&&i(t)})),exports.hold=(t,n)=>ot(t,n,(t,n)=>n),exports.map=(t,n)=>et(i=>t.subscribe(t=>{i(n(t))})),exports.memo=t=>{const i=K(t);return(t=>{const i=t.state;64&i||0!==(i&n)&&z(t)})(i),L.bind(null,i)},exports.merge=(...t)=>et(n=>{const i=t.map(t=>t.subscribe(t=>{n(t)}));return()=>{for(const t of i)t()}}),exports.scan=(t,n,i)=>ot(t,n,i),exports.signal=t=>{const n=new ReactiveNode(t,null,1);return[j.bind(null,n),t=>{const i="function"==typeof t?t(n.payload):t;T(n,i)}]},exports.subscribeOnce=(t,n)=>{let i,r=!0,u=!1;const e=()=>{if(!r)return;r=!1;const t=i;void 0!==t?(i=void 0,t()):u=!0};if(i=t.subscribe(t=>{r&&(e(),n(t))}),u){const t=i;i=void 0,t?.()}return e},exports.withEffectCleanupRegistrar=(t,n)=>d().withCleanupRegistrar(t,n);
@@ -1 +1 @@
1
- class ReactiveEdge{constructor(t,n,i,e,s,r){this.from=t,this.to=n,this.prevOut=i,this.nextOut=e,this.prevIn=s,this.nextIn=r}}function t(t){t.prevOut=null,t.nextOut=null,t.prevIn=null,t.nextIn=null}var n;(t=>{t[t.Producer=1]="Producer",t[t.Consumer=2]="Consumer",t[t.Watcher=4]="Watcher",t[t.Invalid=8]="Invalid",t[t.Changed=16]="Changed",t[t.Visited=32]="Visited",t[t.Disposed=64]="Disposed",t[t.Computing=128]="Computing",t[t.Scheduled=256]="Scheduled",t[t.Tracking=512]="Tracking"})(n||(n={}));const i=n.Producer|n.Consumer|n.Watcher,e=n.Invalid|n.Changed,s=n.Producer,r=n.Changed|n.Watcher;function o(t){t.state&=~n.Computing}function l(t){t.state&=~e}function u(t){return 0!==(t.state&n.Disposed)}function c(t,n,i){const e=i?i.nextIn:t.firstIn;n.prevIn=i,n.nextIn=e,e?e.prevIn=n:t.lastIn=n,i?i.nextIn=n:t.firstIn=n}function h(t,n){const{prevIn:i,nextIn:e}=n;i?i.nextIn=e:t.firstIn=e,e?e.prevIn=i:t.lastIn=i}function f(t,n){const{prevOut:i,nextOut:e}=n;i?i.nextOut=e:t.firstOut=e,e?e.prevOut=i:t.lastOut=i}function a(t,n,i=n.lastIn){const e=t.lastOut,s=i?i.nextIn:n.firstIn,r=new ReactiveEdge(t,n,e,null,i,s);return e?e.nextOut=r:t.firstOut=r,t.lastOut=r,s?s.prevIn=r:n.lastIn=r,i?i.nextIn=r:n.firstIn=r,r}function d(t,n,i,e){for(let s=e?e.nextIn:n.firstIn;null!==s;s=s.nextIn)if(s.from===t)return s.prevIn!==i&&(h(n,s),c(n,s,i)),s;return a(t,n,i)}function v(e){u(e)||((t=>{t.state=t.state&i|n.Disposed})(e),e.depsTail=null,(n=>{let i=n.firstIn;for(n.firstIn=n.lastIn=n.depsTail=null;i;){const n=i.nextIn;f(i.from,i),t(i),i=n}})(e),(n=>{let i=n.firstOut;for(n.firstOut=n.lastOut=null;i;){const n=i.nextOut;i.to.depsTail===i&&(i.to.depsTail=i.prevIn),h(i.to,i),t(i),i=n}})(e),e.compute=null)}const p=Symbol.for("UNINITIALIZED");class ReactiveNode{constructor(t,n,i){this.state=i,this.compute=n,this.firstOut=null,this.firstIn=null,this.lastOut=null,this.lastIn=null,this.depsTail=null,this.payload=t}}function y(t,n){if(!Object.hasOwn(t,n))return;const i=t[n];return"function"==typeof i?i:void 0}class ExecutionContext{constructor(t={}){this.activeComputed=null,this.propagationDepth=0,this.cleanupRegistrar=null,this.onEffectInvalidatedHook=void 0,this.onReactiveSettledHook=void 0,this.hookMask=0,this.hooks={},Object.defineProperties(this.hooks,{onEffectInvalidated:{enumerable:!0,get:()=>this.onEffectInvalidatedHook,set:t=>{this.setOnEffectInvalidatedHook(t)}},onReactiveSettled:{enumerable:!0,get:()=>this.onReactiveSettledHook,set:t=>{this.setOnReactiveSettledHook(t)}}}),this.setHooks(t)}dispatchWatcherEvent(t){const n=this.onEffectInvalidatedHook;void 0!==n&&n?.(t)}maybeNotifySettled(){if(!(2&this.hookMask))return;if(0!==this.propagationDepth||null!==this.activeComputed)return;const t=this.onReactiveSettledHook;t?.()}enterPropagation(){++this.propagationDepth}leavePropagation(){this.propagationDepth>0&&--this.propagationDepth,this.maybeNotifySettled()}resetState(){this.activeComputed=null,this.propagationDepth=0,this.cleanupRegistrar=null}setHooks(t={}){const n=y(t,"onEffectInvalidated"),i=y(t,"onReactiveSettled");this.hooks.onEffectInvalidated=n,this.hooks.onReactiveSettled=i}registerWatcherCleanup(t){this.cleanupRegistrar?.(t)}withCleanupRegistrar(t,n){const i=this.cleanupRegistrar;this.cleanupRegistrar=t;try{return n()}finally{this.cleanupRegistrar=i}}setOnEffectInvalidatedHook(t){this.onEffectInvalidatedHook="function"==typeof t?t:void 0,this.updateHookMask(1,void 0!==this.onEffectInvalidatedHook)}setOnReactiveSettledHook(t){this.onReactiveSettledHook="function"==typeof t?t:void 0,this.updateHookMask(2,void 0!==this.onReactiveSettledHook)}updateHookMask(t,n){this.hookMask=n?this.hookMask|t:this.hookMask&~t}}let R=((t={})=>new ExecutionContext(t))(void 0);function g(){return R}const b=Object.is;function k(n,i=g()){const e=n.depsTail,s=null===e?n.firstIn:e.nextIn;null!==s&&(null===e?(n.firstIn=null,n.lastIn=null):(e.nextIn=null,n.lastIn=e),(n=>{for(;n;){const i=n.nextIn;f(n.from,n),t(n),n=i}})(s))}function w(t,i){t.depsTail=null,t.state=t.state&~n.Visited|n.Tracking,(t=>{t.state|=n.Computing})(t);const e=i.activeComputed;i.activeComputed=t;let s=!1;return()=>{s||(s=!0,i.activeComputed=e)}}function I(t,i=g()){if(u(t))return!1;const e=t.payload;let s=e,r=!1;return s=((t,i=g())=>{const e=t.compute,s=w(t,i);let r;try{return r=e(),s(),k(t,i),r}catch(t){throw s(),t}finally{t.state&=~n.Tracking,o(t),i.maybeNotifySettled()}})(t,i),u(t)||(r=!b(e,s),t.payload=s),l(t),r}const C=n.Invalid,E=n.Changed,x=n.Invalid|n.Changed|n.Disposed|n.Visited|n.Tracking;function S(t,n,i){const e=i.onEffectInvalidatedHook;if(void 0===e)return n;try{e(t)}catch(t){return n??t}return n}function j(t,i=g()){if(0!==(t.state&n.Disposed))return;let s=null;for(let r=t.firstOut;null!==r;r=r.nextOut){const t=r.to,o=t.state;if((o&e)!==n.Invalid)continue;const l=o&~n.Invalid|n.Changed;t.state=l,0!==(l&n.Watcher)&&(s=S(t,s,i))}if(null!==s)throw s}const m=[],O=[];function N(t,i,s){return 0!==(i&(e|n.Disposed))?0:0===(i&n.Tracking)?i&~n.Visited|s:((t,n)=>{if(null===n)return!1;for(let i=t.prevIn;null!==i;i=i.prevIn)if(i===n)return!1;return!0})(t,t.to.depsTail)?i|n.Visited|n.Invalid:0}function H(t,i,e,s,r){const o=m,l=O,u=o.length;let c=u,h=C;for(;;){const f=t.to,a=f.state;let d=0;if(d=0===(a&x)?a|h:N(t,a,h),0!==d)if(f.state=d,0!==(d&n.Watcher))s=S(f,s,r);else{const n=f.firstOut;if(null!==n){null!==i&&(o[c]=i,l[c++]=e),t=n,i=n.nextOut,h=e=C;continue}}if(null!==i)t=i,h=e;else{if(u>=c)return o.length=l.length=u,s;t=o[--c],h=e=l[c]}i=t.nextOut}}function L(t,i,s){return 0!==(i&(e|n.Disposed))?0:0===(i&n.Tracking)?i&~n.Visited|s:((t,n)=>{if(null===n)return!1;if(t===n)return!0;for(let i=t.prevIn;null!==i;i=i.prevIn)if(i===n)return!1;return!0})(t,t.to.depsTail)?i|n.Visited|n.Invalid:0}function P(t,n,i){const e=I(n,i);return!e||null===t.prevOut&&null===t.nextOut||j(n,i),e}function W(t,i,s,r,o,l){let u=!1;t:for(;;){const c=t.from,h=c.state;if(0!==(i.state&n.Changed))u=!0;else if(0!==(h&n.Changed))u=P(t,c,s);else if(0!==(h&e)){const n=c.firstIn;if(null!==n){r[o++]=t,t=n,i=c;continue}u=P(t,c,s)}if(!u){const e=t.nextIn;if(null!==e){t=e;continue}i.state&=~n.Invalid}for(;o>l;){const e=r[--o];if(u?u=P(e,i,s):i.state&=~n.Invalid,i=e.to,!u){const n=e.nextIn;if(null!==n){t=n;continue t}}}return u}}const q=[],A=n.Producer|n.Disposed,D=n.Invalid|n.Visited;var T;function z(t,n=g()){return u(t)||((t,n=g())=>{const i=n.activeComputed;if(!i)return;const e=u(t),s=u(i);if(e||s)return;const r=i.depsTail;if(null===r){const n=i.firstIn;return null===n?void(i.depsTail=a(t,i,null)):n.from===t?void(i.depsTail=n):void(i.depsTail=d(t,i,null,n))}if(r.from===t)return;const o=r.nextIn;i.depsTail=null===o||o.from!==t?d(t,i,r,o):o})(t,n),t.payload}function M(t,i,e=b,s=g()){if(u(t))return;if(e(t.payload,i))return;t.payload=i;const r=t.firstOut;if(null!==r){s.enterPropagation();try{((t,i=C,e=g())=>{if(0!==(t.from.state&n.Disposed))return;const s=((t,i,e,s)=>{for(;;){const r=t.to,o=r.state;let l=0;l=0===(o&x)?o|i:L(t,o,i);const u=t.nextOut;if(l)if(r.state=l,0!==(l&n.Watcher))e=S(r,e,s);else{const n=r.firstOut;if(null!==n){if(null!==u)return H(n,u,i,e,s);t=n,i=C;continue}}if(null===u)return e;t=u}})(t,i,null,e);if(null!==s)throw s})(r,E,s)}finally{s.leavePropagation()}}}function U(){return new ReactiveNode(0,null,s)}function V(t){return new ReactiveNode(null,t,r)}(t=>{t[t.lazy=1]="lazy",t[t.eager=2]="eager"})(T||(T={}));class ResourceRequest{constructor(t,n){this.owner=t,this.token=n}alive(){return this.owner.isAlive(this.token)}resolve(t){return this.owner.resolve(this.token,t)}reject(t){return this.owner.reject(this.token,t)}}class ResourceCore{track(){z(this.stateNode,this.context)}bump(){M(this.stateNode,this.stateNode.payload+1)}isAlive(t){return!this.disposed&&this.token===t}start(){const t=this.disposed?this.token:this.token+1;return this.disposed||(this.token=t,this.status="pending",this.error=void 0,this.bump()),new ResourceRequest(this,t)}clear(){this.disposed||(this.token+=1,this.status="idle",this.value=void 0,this.error=void 0,this.bump())}dispose(){this.disposed||(this.disposed=!0,this.token+=1,this.status="idle",this.value=void 0,this.error=void 0,this.bump(),null!==this.watcher&&((t=>{v(t);const n="function"==typeof t.payload?t.payload:null;n?.(),t.payload=p})(this.watcher),this.watcher=null),null!==this.refetchNode&&(v(this.refetchNode),this.refetchNode=null))}resolve(t,n){return!!this.isAlive(t)&&(this.status="resolved",this.value=n,this.error=void 0,this.bump(),!0)}reject(t,n){return!!this.isAlive(t)&&(this.status="rejected",this.error=n,this.bump(),!0)}settle(t,n){var i;"object"==typeof(i=t)&&null!==i&&"then"in i&&"function"==typeof i.then?t.then(t=>{n.resolve(t)},t=>{n.reject(t)}):n.resolve(t)}runLoad(t){const n=this.start();let i;try{i=t(n)}catch(t){return void n.reject(t)}this.settle(i,n)}runSourceLoad(t,n){const i=this.start();let e;try{e=n(t,i)}catch(t){return void i.reject(t)}this.settle(e,i)}refetch(){this.disposed||null===this.refetchNode||M(this.refetchNode,this.refetchNode.payload+1)}constructor(){this.context=g(),this.stateNode=U(),this.status="idle",this.value=void 0,this.error=void 0,this.token=0,this.disposed=!1,this.watcher=null,this.refetchNode=null}}exports.isPending=t=>"pending"===t.status(),exports.resource=(t,i)=>{const s=new ResourceCore,r={status:()=>(s.track(),s.status),value:()=>(s.track(),s.value),error:()=>(s.track(),s.error),token:()=>(s.track(),s.token),clear(){s.clear()},dispose(){s.dispose()}};if("function"==typeof t){if(s.refetchNode=U(),"function"==typeof i){const n=t,e=i;s.watcher=V(()=>{let t;z(s.refetchNode,s.context);try{t=n()}catch(t){return void s.start().reject(t)}s.runSourceLoad(t,e)})}else{const n=t;s.watcher=V(()=>{z(s.refetchNode,s.context),s.runLoad(n)})}return((t,i=g())=>{const s=t.state;if(0!==(s&n.Disposed))return;if(0===(s&e)||0===(s&n.Changed)&&!(t=>{const i=t.state;if(0!==(i&A))return!1;if(0!==(i&n.Changed)||(i&D)===D)return!0;const s=t.firstIn;return null===s?(t.state=i&~n.Invalid,!1):((t,i,s)=>{const r=q,o=r.length;let l=o,u=i,c=t,h=!1;for(;;){if(null!==u.nextIn)return W(u,c,s,r,l,o);if(0!==(c.state&n.Changed)){h=!0;break}const t=u.from,i=t.state;if(0!==(i&n.Changed)&&(h=P(u,t,s),h||null===u.nextIn))break;if(0!==(i&e)){const n=t.firstIn;if(null!==n){if(null!==n.nextIn){r[l++]=u;const i=W(n,t,s,r,l,o);return r.length=o,i}r[l++]=u,u=n,c=t;continue}h=P(u,t,s);break}if(c.state&=~n.Invalid,l===o)return!1;u=r[--l],c=u.to}for(;l>o;){const t=r[--l];h?h=P(t,c,s):c.state&=~n.Invalid,c=t.to}return h||(c.state&=~n.Invalid),r.length=o,h})(t,s,g())})(t))return void l(t);const r="function"==typeof t.payload?t.payload:null;if(t.payload=p,(t=>{t.state&=~n.Visited})(t),l(t),r?.(),u(t))return;let c=!1;((t,i,e=g())=>{const s=t.compute,r=w(t,e);let l;try{return l=s(),r(),k(t,e),i(l)}catch(t){throw r(),t}finally{t.state&=~n.Tracking,o(t),e.maybeNotifySettled()}})(t,n=>{u(t)||(c="function"==typeof n,c&&(t.payload=n))},i)})(s.watcher,s.context),s.context.registerWatcherCleanup(()=>{s.dispose()}),{...r,refetch(){s.refetch()}}}return s.context.registerWatcherCleanup(()=>{s.dispose()}),{...r,start(){return s.start()}}};
1
+ class ReactiveEdge{constructor(t,n,i,s,e,r,o){this.version=t,this.prevOut=n,this.nextOut=i,this.from=s,this.to=e,this.prevIn=r,this.nextIn=o}}function t(t){t.prevOut=t.nextOut=t.prevIn=t.nextIn=null}const n=24;function i(t){t.state&=-25}function s(t){return!!(64&t.state)}const e=Symbol.for("UNINITIALIZED");class ReactiveNode{constructor(t,n,i){this.state=0|i,this.firstOut=null,this.firstIn=null,this.lastOut=null,this.lastIn=null,this.depsTail=null,this.compute=n,this.payload=t}}let r;function o(t,n,i){const s=i?i.nextIn:t.firstIn;n.prevIn=i,n.nextIn=s,s?s.prevIn=n:t.lastIn=n,i?i.nextIn=n:t.firstIn=n}function u(t,n){const{prevIn:i,nextIn:s}=n;i?i.nextIn=s:t.firstIn=s,s?s.prevIn=i:t.lastIn=i}function l(t,n){const{prevOut:i,nextOut:s}=n;i?i.nextOut=s:t.firstOut=s,s?s.prevOut=i:t.lastOut=i}function c(t,n,i=n.lastIn,s=0){const e=t.lastOut,r=i?i.nextIn:n.firstIn,o=new ReactiveEdge(s,e,null,t,n,i,r);return e?e.nextOut=o:t.firstOut=o,t.lastOut=o,r?r.prevIn=o:n.lastIn=o,i?i.nextIn=o:n.firstIn=o,o}function h(t,n,i,s,e=0){const r=t.lastOut;if(null!=r&&r.version===e&&r.to===n)return r;for(let r=s?s.nextIn:n.firstIn;null!==r;r=r.nextIn)if(r.from===t)return r.prevIn!==i&&(u(n,r),o(n,r,i)),r.version=e,r;return c(t,n,i,e)}function f(n){s(n)||((t=>{t.state=7&t.state|64})(n),n.depsTail=null,(n=>{let i=n.firstIn;for(n.firstIn=n.lastIn=n.depsTail=null;i;){const n=i.nextIn;l(i.from,i),t(i),i=n}})(n),(n=>{let i=n.firstOut;for(n.firstOut=n.lastOut=null;i;){const n=i.nextOut;i.to.depsTail===i&&(i.to.depsTail=i.prevIn),u(i.to,i),t(i),i=n}})(n),n.compute=null,n.payload=e)}let d=h,a=new class{constructor(t={},n={}){this.activeComputed=null,this.trackingVersion=0,this.propagationDepth=0,this.cleanupRegistrar=null,this.trackReadFallback=h,this.onEffectInvalidated=void 0,this.onReactiveSettled=void 0,this.runtimeOnEffectInvalidated=void 0,this.runtimeOnReactiveSettled=void 0,this.effectInvalidatedDispatch=void 0,this.settledDispatch=void 0,this.setHooks(t),this.setOptions(n)}dispatchWatcherEvent(t){this.effectInvalidatedDispatch?.(t)}maybeNotifySettled(){0===this.propagationDepth&&null===this.activeComputed&&this.settledDispatch?.()}enterPropagation(){++this.propagationDepth}leavePropagation(){this.propagationDepth>0&&--this.propagationDepth,this.maybeNotifySettled()}resetState(){this.activeComputed=null,this.trackingVersion=0,this.propagationDepth=0,this.cleanupRegistrar=null}setOptions(t={}){this.trackReadFallback=d="function"==typeof t.trackReadFallback?t.trackReadFallback:h}setHooks(t={}){this.onEffectInvalidated="function"==typeof t.onEffectInvalidated?t.onEffectInvalidated:void 0,this.onReactiveSettled="function"==typeof t.onReactiveSettled?t.onReactiveSettled:void 0,this.refreshDispatchers()}setRuntimeHooks(t,n){this.runtimeOnEffectInvalidated="function"==typeof t?t:void 0,this.runtimeOnReactiveSettled="function"==typeof n?n:void 0,this.refreshDispatchers()}registerWatcherCleanup(t){this.cleanupRegistrar?.(t)}withCleanupRegistrar(t,n){const i=this.cleanupRegistrar;this.cleanupRegistrar=t;try{return n()}finally{this.cleanupRegistrar=i}}refreshDispatchers(){const t=this.runtimeOnEffectInvalidated,n=this.onEffectInvalidated,i=this.runtimeOnReactiveSettled,s=this.onReactiveSettled;this.effectInvalidatedDispatch=r=t&&n?i=>{t(i),n(i)}:t??n,this.settledDispatch=i&&s?()=>{i(),s()}:i??s}};const v=Object.is;function p(t,n){a.activeComputed=n,t.state&=-513,(t=>{t.state&=-129})(t)}function y(n){const i=n.compute,s=(t=>{const n=a,i=n.trackingVersion+1>>>0;t.depsTail=null,t.state=-33&t.state|512,(t=>{t.state|=128})(t),n.trackingVersion=0===i?1:i;const s=n.activeComputed;return n.activeComputed=t,s})(n);let e;try{return e=i(),p(n,s),n.depsTail!==n.lastIn&&(n=>{const i=n.depsTail,s=null===i?n.firstIn:i.nextIn;if(null===s)return;const e=s;null===i?(n.firstIn=null,n.lastIn=null):(i.nextIn=null,n.lastIn=i),(n=>{for(;n;){const i=n.nextIn;l(n.from,n),t(n),n=i}})(e)})(n),e}catch(t){throw p(n,s),t}}function R(t){if(64&t.state)return;let i=null;const s=r;for(let e=t.firstOut;null!==e;e=e.nextOut){const r=e.to,o=r.state;if(8!==(o&n))continue;const u=o^n;if(r.state=u,4&u&&void 0!==s)try{s(r)}catch(t){null===i&&(i=t)}}if(null!==i)throw i}const w=[];function b(t){return(t=>{if(s(t))return!1;const n=t.payload;let e=n,r=!1;return e=y(t),s(t)||(r=!v(n,e),t.payload=e),i(t),r})(t)}function g(t){return null!==t.prevOut||null!==t.nextOut}function k(t,n){const i=b(t);return i&&n&&R(t),i}function I(t,n){const i=b(t);return i&&n&&R(t),i}function N(t,i,s,e,r){let o=!1;t:for(;;){if(16&i.state)o=!0;else{const r=t.from,u=r.state;if(16&u)o=I(r,g(t));else if(0!==(u&n)){const n=r.firstIn;if(null!==n){s[e++]=t,t=n,i=r;continue}o=I(r,g(t))}}if(!o){const n=t.nextIn;if(null!==n){t=n;continue}i.state&=-9}for(;e>r;){const n=s[--e],r=g(n);if(o?o=I(i,r):i.state&=-9,i=n.to,!o){const i=n.nextIn;if(null!==i){t=i;continue t}}}return o}}function j(t,i){const s=w,e=s.length;let r=e,o=i,u=t,l=!1;for(;;){if(null!==o.nextIn)return N(o,u,s,r,e);if(16&u.state){l=!0;break}const t=o.from,i=t.state;if(16&i){l=k(t,g(o));break}if(0!==(i&n)){const n=t.firstIn;if(null!==n){if(null!==n.nextIn){s[r++]=o;const i=N(n,t,s,r,e);return s.length=e,i}s[r++]=o,o=n,u=t;continue}l=k(t,g(o));break}if(u.state&=-9,r===e)return s.length=e,!1;o=s[--r],u=o.to}for(;r>e;){const t=s[--r],n=g(t);l?l=I(u,n):u.state&=-9,u=t.to}return l||(u.state&=-9),s.length=e,l}function m(t){return"function"==typeof t?t:null}const x=[],C=[];function E(t,n,i){if(void 0!==n)try{n(t)}catch(t){if(null===i)return t}return i}function O(t,i,s,e){const r=-33&s|e,o=40|s;if(!(600&s))return r;if(64&s)return 0;if(512&s){const n=i.depsTail;if(null===n)return 0;if(t===n)return o;const s=t.prevIn;if(null===s)return o;if(s===n)return 0;let e=s.prevIn;for(;null!==e&&e!==n;)e=e.prevIn;return e===n?0:o}return 0!==(s&n)?0:r}function S(t,n,i,s,e){const o=x,u=C,l=o.length;let c=l,h=t.nextOut,f=n;const d=r;for(null!==s&&(o[c]=s,u[c++]=e);;){const s=t.to,e=s.state,r=600&e?O(t,s,e,n):-33&e|n;if(0!==r)if(s.state=r,4&r)i=E(s,d,i);else{const i=s.firstOut;if(null!==i){null!==h&&(o[c]=h,u[c++]=f),h=(t=i).nextOut,n=f=8;continue}}if(null===h){if(c===l)return o.length=l,u.length=l,i;t=o[--c],n=f=u[c],h=t.nextOut}else n=f,h=(t=h).nextOut}}function L(t){if(s(t))return t.payload;const n=a.activeComputed;return null!==n&&(((t,n)=>{const i=n.depsTail,s=a.trackingVersion,e=t.lastOut;if(null!=e&&e.version===s&&e.to===n)return!0;if(null!=i){if(i.from===t)return i.version=s,!0;const e=i.nextIn;return null!=e&&e.from===t&&(e.version=s,n.depsTail=e,!0)}const r=n.firstIn;return null!=r&&r.from===t&&(r.version=s,n.depsTail=r,!0)})(t,n)||((t,n)=>{const i=a.trackingVersion,e=s(t),r=s(n);if(e||r)return;const o=n.depsTail;if(null===o){const s=n.firstIn;return null===s?void(n.depsTail=c(t,n,null,i)):s.from===t?(s.version=i,void(n.depsTail=s)):null===s.nextIn?void(n.depsTail=c(t,n,null,i)):void(n.depsTail=d(t,n,null,s,i))}if(o.from===t)return void(o.version=i);const u=o.nextIn;null===u?n.depsTail=c(t,n,o,i):u.from===t?(u.version=i,n.depsTail=u):n.depsTail=null===u.nextIn?c(t,n,o,i):d(t,n,o,u,i)})(t,n)),t.payload}function q(t,n,i=v){if(s(t))return;if(i(t.payload,n))return;t.payload=n;const e=t.firstOut;if(null===e)return;const o=a;o.enterPropagation();try{((t,n=8)=>{if(64&t.from.state)return;const i=((t,n)=>{let i=null;const s=r;for(;;){const e=t.to,r=t.nextOut,o=e.state,u=600&o?O(t,e,o,n):-33&o|n;if(0!==u)if(e.state=u,4&u)i=E(e,s,i);else{const s=e.firstOut;if(null!==s){if(t=s,null!==r)return S(t,8,i,r,n);n=8;continue}}if(null===r)return i;t=r}})(t,n);if(null!==i)throw i})(e,16)}finally{o.leavePropagation()}}const A=()=>new ReactiveNode(0,null,1),D=t=>new ReactiveNode(void 0,t,20);class ResourceRequest{constructor(t,n){this.owner=t,this.token=n}alive(){return this.owner.isAlive(this.token)}resolve(t){return this.owner.resolve(this.token,t)}reject(t){return this.owner.reject(this.token,t)}}class ResourceCore{track(){L(this.stateNode)}bump(){q(this.stateNode,this.stateNode.payload+1)}isAlive(t){return!this.disposed&&this.token===t}start(){const t=this.disposed?this.token:this.token+1;return this.disposed||(this.token=t,this.status="pending",this.error=void 0,this.bump()),new ResourceRequest(this,t)}clear(){this.disposed||(this.token+=1,this.status="idle",this.value=void 0,this.error=void 0,this.bump())}dispose(){this.disposed||(this.disposed=!0,this.token+=1,this.status="idle",this.value=void 0,this.error=void 0,this.bump(),null!==this.watcher&&((t=>{const n=m(t.payload);f(t),null!==n&&n(),t.payload=e})(this.watcher),this.watcher=null),null!==this.refetchNode&&(f(this.refetchNode),this.refetchNode=null))}resolve(t,n){return!!this.isAlive(t)&&(this.status="resolved",this.value=n,this.error=void 0,this.bump(),!0)}reject(t,n){return!!this.isAlive(t)&&(this.status="rejected",this.error=n,this.bump(),!0)}settle(t,n){var i;"object"==typeof(i=t)&&null!==i&&"then"in i&&"function"==typeof i.then?t.then(t=>{n.resolve(t)},t=>{n.reject(t)}):n.resolve(t)}runLoad(t){const n=this.start();let i;try{i=t(n)}catch(t){return void n.reject(t)}this.settle(i,n)}runSourceLoad(t,n){const i=this.start();let s;try{s=n(t,i)}catch(t){return void i.reject(t)}this.settle(s,i)}refetch(){this.disposed||null===this.refetchNode||q(this.refetchNode,this.refetchNode.payload+1)}constructor(){this.context=a,this.stateNode=A(),this.status="idle",this.value=void 0,this.error=void 0,this.token=0,this.disposed=!1,this.watcher=null,this.refetchNode=null}}exports.isPending=t=>"pending"===t.status(),exports.resource=(t,s)=>{const r=new ResourceCore,o={status:()=>(r.track(),r.status),value:()=>(r.track(),r.value),error:()=>(r.track(),r.error),token:()=>(r.track(),r.token),clear(){r.clear()},dispose(){r.dispose()}};if("function"==typeof t){if(r.refetchNode=A(),"function"==typeof s){const n=t,i=s;r.watcher=D(()=>{let t;L(r.refetchNode);try{t=n()}catch(t){return void r.start().reject(t)}r.runSourceLoad(t,i)})}else{const n=t;r.watcher=D(()=>{L(r.refetchNode),r.runLoad(n)})}return(t=>{const s=t.state;if(64&s)return;if(0===(s&n))return;if(!((t,n)=>{if(16&n)return!0;if(!(40&~n))return!0;const i=t.firstIn;return null===i?(t.state=-9&n,!1):j(t,i)})(t,s))return void i(t);const r=m(t.payload);if(t.payload=e,(t=>{t.state&=-33})(t),null!==r&&r(),64&t.state)return;const o=y(t);"function"==typeof o&&(t.payload=o),32&t.state?t.state=-17&t.state|8:i(t)})(r.watcher),r.context.registerWatcherCleanup(()=>{r.dispose()}),{...o,refetch(){r.refetch()}}}return r.context.registerWatcherCleanup(()=>{r.dispose()}),{...o,start(){return r.start()}}};
package/dist/esm/index.js CHANGED
@@ -1 +1 @@
1
- class ReactiveEdge{constructor(t,n,i,e,u,s){this.from=t,this.to=n,this.prevOut=i,this.nextOut=e,this.prevIn=u,this.nextIn=s}}function t(t){t.prevOut=null,t.nextOut=null,t.prevIn=null,t.nextIn=null}var n;(t=>{t[t.Producer=1]="Producer",t[t.Consumer=2]="Consumer",t[t.Watcher=4]="Watcher",t[t.Invalid=8]="Invalid",t[t.Changed=16]="Changed",t[t.Visited=32]="Visited",t[t.Disposed=64]="Disposed",t[t.Computing=128]="Computing",t[t.Scheduled=256]="Scheduled",t[t.Tracking=512]="Tracking"})(n||(n={}));const i=n.Producer|n.Consumer|n.Watcher,e=n.Invalid|n.Changed,u=n.Producer,s=n.Changed|n.Consumer,r=n.Changed|n.Watcher;function o(t){t.state&=~n.Computing}function l(t){t.state&=~e}function c(t){return 0!==(t.state&n.Disposed)}function f(t,n,i){const e=i?i.nextIn:t.firstIn;n.prevIn=i,n.nextIn=e,e?e.prevIn=n:t.lastIn=n,i?i.nextIn=n:t.firstIn=n}function h(t,n){const{prevIn:i,nextIn:e}=n;i?i.nextIn=e:t.firstIn=e,e?e.prevIn=i:t.lastIn=i}function a(t,n){const{prevOut:i,nextOut:e}=n;i?i.nextOut=e:t.firstOut=e,e?e.prevOut=i:t.lastOut=i}function d(t,n,i=n.lastIn){const e=t.lastOut,u=i?i.nextIn:n.firstIn,s=new ReactiveEdge(t,n,e,null,i,u);return e?e.nextOut=s:t.firstOut=s,t.lastOut=s,u?u.prevIn=s:n.lastIn=s,i?i.nextIn=s:n.firstIn=s,s}function v(t,n,i,e){for(let u=e?e.nextIn:n.firstIn;null!==u;u=u.nextIn)if(u.from===t)return u.prevIn!==i&&(h(n,u),f(n,u,i)),u;return d(t,n,i)}function y(e){c(e)||((t=>{t.state=t.state&i|n.Disposed})(e),e.depsTail=null,(n=>{let i=n.firstIn;for(n.firstIn=n.lastIn=n.depsTail=null;i;){const n=i.nextIn;a(i.from,i),t(i),i=n}})(e),(n=>{let i=n.firstOut;for(n.firstOut=n.lastOut=null;i;){const n=i.nextOut;i.to.depsTail===i&&(i.to.depsTail=i.prevIn),h(i.to,i),t(i),i=n}})(e),e.compute=null)}const p=Symbol.for("UNINITIALIZED");class ReactiveNode{constructor(t,n,i){this.state=i,this.compute=n,this.firstOut=null,this.firstIn=null,this.lastOut=null,this.lastIn=null,this.depsTail=null,this.payload=t}}function b(t,n){if(!Object.hasOwn(t,n))return;const i=t[n];return"function"==typeof i?i:void 0}class ExecutionContext{constructor(t={}){this.activeComputed=null,this.propagationDepth=0,this.cleanupRegistrar=null,this.onEffectInvalidatedHook=void 0,this.onReactiveSettledHook=void 0,this.hookMask=0,this.hooks={},Object.defineProperties(this.hooks,{onEffectInvalidated:{enumerable:!0,get:()=>this.onEffectInvalidatedHook,set:t=>{this.setOnEffectInvalidatedHook(t)}},onReactiveSettled:{enumerable:!0,get:()=>this.onReactiveSettledHook,set:t=>{this.setOnReactiveSettledHook(t)}}}),this.setHooks(t)}dispatchWatcherEvent(t){const n=this.onEffectInvalidatedHook;void 0!==n&&n?.(t)}maybeNotifySettled(){if(!(2&this.hookMask))return;if(0!==this.propagationDepth||null!==this.activeComputed)return;const t=this.onReactiveSettledHook;t?.()}enterPropagation(){++this.propagationDepth}leavePropagation(){this.propagationDepth>0&&--this.propagationDepth,this.maybeNotifySettled()}resetState(){this.activeComputed=null,this.propagationDepth=0,this.cleanupRegistrar=null}setHooks(t={}){const n=b(t,"onEffectInvalidated"),i=b(t,"onReactiveSettled");this.hooks.onEffectInvalidated=n,this.hooks.onReactiveSettled=i}registerWatcherCleanup(t){this.cleanupRegistrar?.(t)}withCleanupRegistrar(t,n){const i=this.cleanupRegistrar;this.cleanupRegistrar=t;try{return n()}finally{this.cleanupRegistrar=i}}setOnEffectInvalidatedHook(t){this.onEffectInvalidatedHook="function"==typeof t?t:void 0,this.updateHookMask(1,void 0!==this.onEffectInvalidatedHook)}setOnReactiveSettledHook(t){this.onReactiveSettledHook="function"==typeof t?t:void 0,this.updateHookMask(2,void 0!==this.onReactiveSettledHook)}updateHookMask(t,n){this.hookMask=n?this.hookMask|t:this.hookMask&~t}}let E=g(void 0);function g(t={}){return new ExecutionContext(t)}function S(){return E}const I=Object.is;function w(t,n=S()){const i=n.activeComputed;if(!i)return;const e=c(t),u=c(i);if(e||u)return;const s=i.depsTail;if(null===s){const n=i.firstIn;return null===n?void(i.depsTail=d(t,i,null)):n.from===t?void(i.depsTail=n):void(i.depsTail=v(t,i,null,n))}if(s.from===t)return;const r=s.nextIn;i.depsTail=null===r||r.from!==t?v(t,i,s,r):r}function x(n,i=S()){const e=n.depsTail,u=null===e?n.firstIn:e.nextIn;null!==u&&(null===e?(n.firstIn=null,n.lastIn=null):(e.nextIn=null,n.lastIn=e),(n=>{for(;n;){const i=n.nextIn;a(n.from,n),t(n),n=i}})(u))}function N(t,i){t.depsTail=null,t.state=t.state&~n.Visited|n.Tracking,(t=>{t.state|=n.Computing})(t);const e=i.activeComputed;i.activeComputed=t;let u=!1;return()=>{u||(u=!0,i.activeComputed=e)}}function R(t,i=S()){if(c(t))return!1;const e=t.payload;let u=e,s=!1;return u=((t,i=S())=>{const e=t.compute,u=N(t,i);let s;try{return s=e(),u(),x(t,i),s}catch(t){throw u(),t}finally{t.state&=~n.Tracking,o(t),i.maybeNotifySettled()}})(t,i),c(t)||(s=!I(e,u),t.payload=u),l(t),s}const k=n.Invalid,m=n.Changed,C=n.Invalid|n.Changed|n.Disposed|n.Visited|n.Tracking;function O(t,n,i){const e=i.onEffectInvalidatedHook;if(void 0===e)return n;try{e(t)}catch(t){return n??t}return n}function D(t,i=S()){if(0!==(t.state&n.Disposed))return;let u=null;for(let s=t.firstOut;null!==s;s=s.nextOut){const t=s.to,r=t.state;if((r&e)!==n.Invalid)continue;const o=r&~n.Invalid|n.Changed;t.state=o,0!==(o&n.Watcher)&&(u=O(t,u,i))}if(null!==u)throw u}const H=[],P=[];function j(t,i,u){return 0!==(i&(e|n.Disposed))?0:0===(i&n.Tracking)?i&~n.Visited|u:((t,n)=>{if(null===n)return!1;for(let i=t.prevIn;null!==i;i=i.prevIn)if(i===n)return!1;return!0})(t,t.to.depsTail)?i|n.Visited|n.Invalid:0}function A(t,i,e,u,s){const r=H,o=P,l=r.length;let c=l,f=k;for(;;){const h=t.to,a=h.state;let d=0;if(d=0===(a&C)?a|f:j(t,a,f),0!==d)if(h.state=d,0!==(d&n.Watcher))u=O(h,u,s);else{const n=h.firstOut;if(null!==n){null!==i&&(r[c]=i,o[c++]=e),t=n,i=n.nextOut,f=e=k;continue}}if(null!==i)t=i,f=e;else{if(l>=c)return r.length=o.length=l,u;t=r[--c],f=e=o[c]}i=t.nextOut}}function T(t,i,u){return 0!==(i&(e|n.Disposed))?0:0===(i&n.Tracking)?i&~n.Visited|u:((t,n)=>{if(null===n)return!1;if(t===n)return!0;for(let i=t.prevIn;null!==i;i=i.prevIn)if(i===n)return!1;return!0})(t,t.to.depsTail)?i|n.Visited|n.Invalid:0}function W(t,n,i){const e=R(n,i);return!e||null===t.prevOut&&null===t.nextOut||D(n,i),e}function B(t,i,u,s,r,o){let l=!1;t:for(;;){const c=t.from,f=c.state;if(0!==(i.state&n.Changed))l=!0;else if(0!==(f&n.Changed))l=W(t,c,u);else if(0!==(f&e)){const n=c.firstIn;if(null!==n){s[r++]=t,t=n,i=c;continue}l=W(t,c,u)}if(!l){const e=t.nextIn;if(null!==e){t=e;continue}i.state&=~n.Invalid}for(;r>o;){const e=s[--r];if(l?l=W(e,i,u):i.state&=~n.Invalid,i=e.to,!l){const n=e.nextIn;if(null!==n){t=n;continue t}}}return l}}const L=[],U=n.Producer|n.Disposed,Z=n.Invalid|n.Visited;function q(t){const i=t.state;if(0!==(i&U))return!1;if(0!==(i&n.Changed)||(i&Z)===Z)return!0;const u=t.firstIn;return null===u?(t.state=i&~n.Invalid,!1):((t,i,u)=>{const s=L,r=s.length;let o=r,l=i,c=t,f=!1;for(;;){if(null!==l.nextIn)return B(l,c,u,s,o,r);if(0!==(c.state&n.Changed)){f=!0;break}const t=l.from,i=t.state;if(0!==(i&n.Changed)&&(f=W(l,t,u),f||null===l.nextIn))break;if(0!==(i&e)){const n=t.firstIn;if(null!==n){if(null!==n.nextIn){s[o++]=l;const i=B(n,t,u,s,o,r);return s.length=r,i}s[o++]=l,l=n,c=t;continue}f=W(l,t,u);break}if(c.state&=~n.Invalid,o===r)return!1;l=s[--o],c=l.to}for(;o>r;){const t=s[--o];f?f=W(t,c,u):c.state&=~n.Invalid,c=t.to}return f||(c.state&=~n.Invalid),s.length=r,f})(t,u,S())}var z;function F(t,n=S()){return c(t)||w(t,n),t.payload}function M(t,i){const u=t.state;return 0!==(u&n.Disposed)||0!==(u&e)&&(0!==(u&n.Changed)||q(t)?R(t,i)&&D(t,i):l(t)),t.payload}function V(t,n=z.lazy,i=S()){if(n===z.eager){const n=i.activeComputed;let e;i.activeComputed=null;try{e=M(t,i)}finally{i.activeComputed=n}return e}const e=M(t,i);return c(t)||w(t,i),e}function G(t,i,e=I,u=S()){if(c(t))return;if(e(t.payload,i))return;t.payload=i;const s=t.firstOut;if(null!==s){u.enterPropagation();try{((t,i=k,e=S())=>{if(0!==(t.from.state&n.Disposed))return;const u=((t,i,e,u)=>{for(;;){const s=t.to,r=s.state;let o=0;o=0===(r&C)?r|i:T(t,r,i);const l=t.nextOut;if(o)if(s.state=o,0!==(o&n.Watcher))e=O(s,e,u);else{const n=s.firstOut;if(null!==n){if(null!==l)return A(n,l,i,e,u);t=n,i=k;continue}}if(null===l)return e;t=l}})(t,i,null,e);if(null!==u)throw u})(s,m,u)}finally{u.leavePropagation()}}}function J(t,i=S()){const u=t.state;if(0!==(u&n.Disposed))return;if(0===(u&e)||0===(u&n.Changed)&&!q(t))return void l(t);const s="function"==typeof t.payload?t.payload:null;if(t.payload=p,(t=>{t.state&=~n.Visited})(t),l(t),s?.(),c(t))return;let r=!1;((t,i,e=S())=>{const u=t.compute,s=N(t,e);let r;try{return r=u(),s(),x(t,e),i(r)}catch(t){throw s(),t}finally{t.state&=~n.Tracking,o(t),e.maybeNotifySettled()}})(t,n=>{c(t)||(r="function"==typeof n,r&&(t.payload=n))},i)}(t=>{t[t.lazy=1]="lazy",t[t.eager=2]="eager"})(z||(z={}));class EventSource{constructor(){this.dispatchDepth=0,this.head=null,this.tail=null,this.pendingHead=null}}const K=Symbol("EventSubscriber.owner");function Q(t){return t[K]}function X(t,n){t[K]=n}function Y(t){return t()}function $(t,n){const i=n.prev,e=n.next;null===i?t.head=e:i.next=e,null===e?t.tail=i:e.prev=i,n.prev=null,n.next=null,n.unlinkNext=null,X(n,null)}function _(t,n,i=Y){i(()=>{const i=t.tail;if(null!==i){++t.dispatchDepth;try{let e=t.head;for(;null!==e;){const t=e===i?null:e.next;1&e.state&&e.fn(n),e=t}}finally{--t.dispatchDepth,0===t.dispatchDepth&&null!==t.pendingHead&&(t=>{let n=t.pendingHead;for(t.pendingHead=null;null!==n;){const i=n.unlinkNext;n.unlinkNext=null,$(t,n),n=i}})(t)}}})}const tt=Symbol("UNINITIALIZED");function nt(t){return new ReactiveNode(tt,t,s)}function it(t){t.state&=~n.Scheduled}function et(t){const n=new ReactiveNode(null,t,r),i=S();J(n,i);const e=()=>(t=>{y(t);const n="function"==typeof t.payload?t.payload:null;n?.(),t.payload=p})(n);return i.registerWatcherCleanup(e),e}class EffectScheduler{constructor(t,n){this.queue=[],this.head=0,this.batchDepth=0,this.phase=0,this.mode=t,this.context=n}getContext(){return this.context??S()}enqueue(t){this.isNodeIgnored(t)||((t=>{t.state|=n.Scheduled})(t),this.queue.push(t),this.shouldAutoFlush()&&this.flush())}batch(t){this.enterBatch();try{return t()}finally{this.leaveBatch()}}flush(){if(2&this.phase)return;if(!this.hasPending())return;this.phase=2;const t=this.getContext();try{for(;this.queue.length>this.head;){const n=this.queue[this.head++];it(n),this.shouldSkipNode(n)||J(n,t)}}finally{this.queue.length=0,this.head=0,this.phase=this.batchDepth>0?1:0,0===this.phase&&this.shouldAutoFlush()&&this.flush()}}reset(){this.queue.length=0,this.head=0,this.batchDepth=0,this.phase=0}notifySettled(){this.shouldAutoFlush()&&this.flush()}hasPending(){return this.queue.length>this.head}isNodeIgnored(t){return 0!==(t.state&n.Disposed)||0!==(t.state&n.Scheduled)}shouldSkipNode(t){return 0!==(t.state&n.Disposed)||0===(t.state&e)}shouldAutoFlush(){const t=this.getContext();return 1===this.mode&&0===this.phase&&0===t.propagationDepth&&null===t.activeComputed&&this.hasPending()}enterBatch(){++this.batchDepth,2!==this.phase&&(this.phase=1)}leaveBatch(){--this.batchDepth,0===this.batchDepth&&2!==this.phase&&(this.phase=0,this.shouldAutoFlush()&&this.flush())}}class EventDispatcher{constructor(t=Y){this.queue=[],this.head=0,this.flushing=!1,this.flush=()=>{if(!this.flushing){this.flushing=!0;try{const t=this.queue;for(;t.length>this.head;)_(t[this.head++],t[this.head++])}finally{this.queue.length=0,this.head=0,this.flushing=!1}}},this.runBoundary=t}emit(t,n){this.queue.push(t,n),this.flushing||this.runBoundary(this.flush)}}function ut(t){const{scheduler:n,dispatcher:i,executionContext:e}=(t=>{const n=t?.hooks,i=g(),e=new EffectScheduler((u=t?.effectStrategy,"eager"===u?1:0),i);var u;const s=new EventDispatcher(t=>e.batch(t));return i.setHooks({...n,onEffectInvalidated(t){e.enqueue(t),n?.onEffectInvalidated?.(t)},onReactiveSettled(){e.notifySettled(),n?.onReactiveSettled?.()}}),{scheduler:e,dispatcher:s,executionContext:i}})(t);return e.resetState(),(t=>{E=t})(e),{get ctx(){return e},event(){const t=new EventSource;return{subscribe(n){return((t,n)=>{const i={fn:n,next:null,prev:null,state:1,unlinkNext:null};return((t,n)=>{if(!(1&n.state))return;if(null!=Q(n))return;const i=t.tail;n.prev=i,n.next=null,n.unlinkNext=null,X(n,t),null!==i?(i.next=n,t.tail=n):t.head=t.tail=n})(t,i),()=>{((t,n)=>{Q(n)===t&&1&n.state&&(n.state&=-2,0===t.dispatchDepth?(n.state|=2,$(t,n)):((t,n)=>{2&n.state||(n.state|=2,n.unlinkNext=t.pendingHead,t.pendingHead=n)})(t,n))})(t,i)}})(t,n)},emit(n){i.emit(t,n)}}},flush(){n.flush()}}}function st(t){const n=nt(t);return()=>V(n)}function rt(t){const n=nt(t);return V(n,z.eager),()=>V(n)}function ot(t){return{subscribe:t}}function lt(t,n){let i,e=!0,u=!1;const s=()=>{if(!e)return;e=!1;const t=i;void 0!==t?(i=void 0,t()):u=!0};if(i=t.subscribe(t=>{e&&(s(),n(t))}),u){const t=i;i=void 0,t?.()}return s}function ct(t,n){return ot(i=>t.subscribe(t=>{i(n(t))}))}function ft(t,n){return ot(i=>t.subscribe(t=>{n(t)&&i(t)}))}function ht(...t){return ot(n=>{const i=t.map(t=>t.subscribe(t=>{n(t)}));return()=>{for(const t of i)t()}})}function at(t,n,i){return vt(t,n,i)}function dt(t,n){return vt(t,n,(t,n)=>n)}function vt(t,n,i){const e=new ReactiveNode(n,null,u);let s=t.subscribe(t=>{c(e)||G(e,i(e.payload,t))});return[()=>c(e)?e.payload:F(e),()=>{(t=>{y(t)})(e);const t=s;s=void 0,t?.()}]}function yt(t,n){const i=new ReactiveNode(t,null,u);return[()=>F(i),t=>{const n="function"!=typeof t?t:t(i.payload);return G(i,n),n}]}export{st as computed,ut as createRuntime,et as effect,ft as filter,dt as hold,ct as map,rt as memo,ht as merge,at as scan,yt as signal,lt as subscribeOnce};
1
+ class ReactiveEdge{constructor(t,n,u,i,r,e,o){this.version=t,this.prevOut=n,this.nextOut=u,this.from=i,this.to=r,this.prevIn=e,this.nextIn=o}}function t(t){t.prevOut=t.nextOut=t.prevIn=t.nextIn=null}const n=24;function u(t){t.state&=-25}function i(t){return!!(64&t.state)}const r=Symbol.for("UNINITIALIZED");class ReactiveNode{constructor(t,n,u){this.state=0|u,this.firstOut=null,this.firstIn=null,this.lastOut=null,this.lastIn=null,this.depsTail=null,this.compute=n,this.payload=t}}let e;function o(t,n,u){const i=u?u.nextIn:t.firstIn;n.prevIn=u,n.nextIn=i,i?i.prevIn=n:t.lastIn=n,u?u.nextIn=n:t.firstIn=n}function l(t,n){const{prevIn:u,nextIn:i}=n;u?u.nextIn=i:t.firstIn=i,i?i.prevIn=u:t.lastIn=u}function s(t,n){const{prevOut:u,nextOut:i}=n;u?u.nextOut=i:t.firstOut=i,i?i.prevOut=u:t.lastOut=u}function c(t,n,u=n.lastIn,i=0){const r=t.lastOut,e=u?u.nextIn:n.firstIn,o=new ReactiveEdge(i,r,null,t,n,u,e);return r?r.nextOut=o:t.firstOut=o,t.lastOut=o,e?e.prevIn=o:n.lastIn=o,u?u.nextIn=o:n.firstIn=o,o}function f(t,n,u,i,r=0){const e=t.lastOut;if(null!=e&&e.version===r&&e.to===n)return e;for(let e=i?i.nextIn:n.firstIn;null!==e;e=e.nextIn)if(e.from===t)return e.prevIn!==u&&(l(n,e),o(n,e,u)),e.version=r,e;return c(t,n,u,r)}function h(n){i(n)||((t=>{t.state=7&t.state|64})(n),n.depsTail=null,(n=>{let u=n.firstIn;for(n.firstIn=n.lastIn=n.depsTail=null;u;){const n=u.nextIn;s(u.from,u),t(u),u=n}})(n),(n=>{let u=n.firstOut;for(n.firstOut=n.lastOut=null;u;){const n=u.nextOut;u.to.depsTail===u&&(u.to.depsTail=u.prevIn),l(u.to,u),t(u),u=n}})(n),n.compute=null,n.payload=r)}let a=f;class ExecutionContext{constructor(t={},n={}){this.activeComputed=null,this.trackingVersion=0,this.propagationDepth=0,this.cleanupRegistrar=null,this.trackReadFallback=f,this.onEffectInvalidated=void 0,this.onReactiveSettled=void 0,this.runtimeOnEffectInvalidated=void 0,this.runtimeOnReactiveSettled=void 0,this.effectInvalidatedDispatch=void 0,this.settledDispatch=void 0,this.setHooks(t),this.setOptions(n)}dispatchWatcherEvent(t){this.effectInvalidatedDispatch?.(t)}maybeNotifySettled(){0===this.propagationDepth&&null===this.activeComputed&&this.settledDispatch?.()}enterPropagation(){++this.propagationDepth}leavePropagation(){this.propagationDepth>0&&--this.propagationDepth,this.maybeNotifySettled()}resetState(){this.activeComputed=null,this.trackingVersion=0,this.propagationDepth=0,this.cleanupRegistrar=null}setOptions(t={}){this.trackReadFallback=a="function"==typeof t.trackReadFallback?t.trackReadFallback:f}setHooks(t={}){this.onEffectInvalidated="function"==typeof t.onEffectInvalidated?t.onEffectInvalidated:void 0,this.onReactiveSettled="function"==typeof t.onReactiveSettled?t.onReactiveSettled:void 0,this.refreshDispatchers()}setRuntimeHooks(t,n){this.runtimeOnEffectInvalidated="function"==typeof t?t:void 0,this.runtimeOnReactiveSettled="function"==typeof n?n:void 0,this.refreshDispatchers()}registerWatcherCleanup(t){this.cleanupRegistrar?.(t)}withCleanupRegistrar(t,n){const u=this.cleanupRegistrar;this.cleanupRegistrar=t;try{return n()}finally{this.cleanupRegistrar=u}}refreshDispatchers(){const t=this.runtimeOnEffectInvalidated,n=this.onEffectInvalidated,u=this.runtimeOnReactiveSettled,i=this.onReactiveSettled;this.effectInvalidatedDispatch=e=t&&n?u=>{t(u),n(u)}:t??n,this.settledDispatch=u&&i?()=>{u(),i()}:u??i}}let v=new ExecutionContext;function d(){return v}const y=Object.is;function p(t,n){const u=n.depsTail,i=v.trackingVersion,r=t.lastOut;if(null!=r&&r.version===i&&r.to===n)return!0;if(null!=u){if(u.from===t)return u.version=i,!0;const r=u.nextIn;return null!=r&&r.from===t&&(r.version=i,n.depsTail=r,!0)}const e=n.firstIn;return null!=e&&e.from===t&&(e.version=i,n.depsTail=e,!0)}function b(t,n){const u=v.trackingVersion,r=i(t),e=i(n);if(r||e)return;const o=n.depsTail;if(null===o){const i=n.firstIn;return null===i?void(n.depsTail=c(t,n,null,u)):i.from===t?(i.version=u,void(n.depsTail=i)):null===i.nextIn?void(n.depsTail=c(t,n,null,u)):void(n.depsTail=a(t,n,null,i,u))}if(o.from===t)return void(o.version=u);const l=o.nextIn;return null===l?void(n.depsTail=c(t,n,o,u)):l.from===t?(l.version=u,void(n.depsTail=l)):null===l.nextIn?void(n.depsTail=c(t,n,o,u)):void(n.depsTail=a(t,n,o,l,u))}function x(t,n){v.activeComputed=n,t.state&=-513,(t=>{t.state&=-129})(t)}function w(n){const u=n.compute,i=(t=>{const n=v,u=n.trackingVersion+1>>>0;t.depsTail=null,t.state=-33&t.state|512,(t=>{t.state|=128})(t),n.trackingVersion=0===u?1:u;const i=n.activeComputed;return n.activeComputed=t,i})(n);let r;try{return r=u(),x(n,i),n.depsTail!==n.lastIn&&(n=>{const u=n.depsTail,i=null===u?n.firstIn:u.nextIn;if(null===i)return;const r=i;null===u?(n.firstIn=null,n.lastIn=null):(u.nextIn=null,n.lastIn=u),(n=>{for(;n;){const u=n.nextIn;s(n.from,n),t(n),n=u}})(r)})(n),r}catch(t){throw x(n,i),t}}function g(t){if(i(t))return!1;const n=t.payload;let r=n,e=!1;return r=w(t),i(t)||(e=!y(n,r),t.payload=r),u(t),e}function E(t){if(64&t.state)return;let u=null;const i=e;for(let r=t.firstOut;null!==r;r=r.nextOut){const e=r.to,o=e.state;if(8!==(o&n))continue;const l=o^n;if(e.state=l,4&l&&void 0!==i)try{i(e)}catch(t){null===u&&(u=t)}}if(null!==u)throw u}const N=[];function R(t){return g(t)}function S(t){return null!==t.prevOut||null!==t.nextOut}function m(t,n){const u=R(t);return u&&n&&E(t),u}function C(t,n){const u=R(t);return u&&n&&E(t),u}function k(t,u,i,r,e){let o=!1;t:for(;;){if(16&u.state)o=!0;else{const e=t.from,l=e.state;if(16&l)o=C(e,S(t));else if(0!==(l&n)){const n=e.firstIn;if(null!==n){i[r++]=t,t=n,u=e;continue}o=C(e,S(t))}}if(!o){const n=t.nextIn;if(null!==n){t=n;continue}u.state&=-9}for(;r>e;){const n=i[--r],e=S(n);if(o?o=C(u,e):u.state&=-9,u=n.to,!o){const u=n.nextIn;if(null!==u){t=u;continue t}}}return o}}function D(t,u){const i=N,r=i.length;let e=r,o=u,l=t,s=!1;for(;;){if(null!==o.nextIn)return k(o,l,i,e,r);if(16&l.state){s=!0;break}const t=o.from,u=t.state;if(16&u){s=m(t,S(o));break}if(0!==(u&n)){const n=t.firstIn;if(null!==n){if(null!==n.nextIn){i[e++]=o;const u=k(n,t,i,e,r);return i.length=r,u}i[e++]=o,o=n,l=t;continue}s=m(t,S(o));break}if(l.state&=-9,e===r)return i.length=r,!1;o=i[--e],l=o.to}for(;e>r;){const t=i[--e],n=S(t);s?s=C(l,n):l.state&=-9,l=t.to}return s||(l.state&=-9),i.length=r,s}function I(t){return"function"==typeof t?t:null}function O(t){const i=t.state;if(64&i)return;if(0===(i&n))return;if(!((t,n)=>{if(16&n)return!0;if(!(40&~n))return!0;const u=t.firstIn;return null===u?(t.state=-9&n,!1):D(t,u)})(t,i))return void u(t);const e=I(t.payload);if(t.payload=r,(t=>{t.state&=-33})(t),null!==e&&e(),64&t.state)return;const o=w(t);"function"==typeof o&&(t.payload=o),32&t.state?t.state=-17&t.state|8:u(t)}function q(t){const n=I(t.payload);h(t),null!==n&&n(),t.payload=r}const A=[],B=[];function H(t,n,u){if(void 0!==n)try{n(t)}catch(t){if(null===u)return t}return u}function P(t,u,i,r){const e=-33&i|r,o=40|i;if(!(600&i))return e;if(64&i)return 0;if(512&i){const n=u.depsTail;if(null===n)return 0;if(t===n)return o;const i=t.prevIn;if(null===i)return o;if(i===n)return 0;let r=i.prevIn;for(;null!==r&&r!==n;)r=r.prevIn;return r===n?0:o}return 0!==(i&n)?0:e}function W(t,n,u,i,r){const o=A,l=B,s=o.length;let c=s,f=t.nextOut,h=n;const a=e;for(null!==i&&(o[c]=i,l[c++]=r);;){const i=t.to,r=i.state,e=600&r?P(t,i,r,n):-33&r|n;if(0!==e)if(i.state=e,4&e)u=H(i,a,u);else{const u=i.firstOut;if(null!==u){null!==f&&(o[c]=f,l[c++]=h),f=(t=u).nextOut,n=h=8;continue}}if(null===f){if(c===s)return o.length=s,l.length=s,u;t=o[--c],n=h=l[c],f=t.nextOut}else n=h,f=(t=f).nextOut}}function j(t){if(i(t))return t.payload;const n=v.activeComputed;return null!==n&&(p(t,n)||b(t,n)),t.payload}function z(t){const i=t.state;return 64&i||0===(i&n)||(((t,n)=>{if(16&n)return!0;if(!(40&~n))return!0;const u=t.firstIn;return null===u?(t.state=-9&n,!1):D(t,u)})(t,i)?g(t)&&null!==t.firstOut&&E(t):u(t)),t.payload}function L(t){const u=t.state;if(64&u)return t.payload;const r=0!==(u&n)?z(t):t.payload;if(0!==(u&n)&&i(t))return r;const e=v.activeComputed;return null!==e&&(p(t,e)||b(t,e)),r}function T(t,n,u=y){if(i(t))return;if(u(t.payload,n))return;t.payload=n;const r=t.firstOut;if(null===r)return;const o=v;o.enterPropagation();try{((t,n=8)=>{if(64&t.from.state)return;const u=((t,n)=>{let u=null;const i=e;for(;;){const r=t.to,e=t.nextOut,o=r.state,l=600&o?P(t,r,o,n):-33&o|n;if(0!==l)if(r.state=l,4&l)u=H(r,i,u);else{const i=r.firstOut;if(null!==i){if(t=i,null!==e)return W(t,8,u,e,n);n=8;continue}}if(null===e)return u;t=e}})(t,n);if(null!==u)throw u})(r,16)}finally{o.leavePropagation()}}class EventSource{constructor(){this.dispatchDepth=0,this.head=null,this.tail=null,this.pendingHead=null}}const U=Symbol("EventSubscriber.owner");function Z(t){return t[U]}function _(t,n){t[U]=n}function F(t){return t()}function G(t,n){const u=n.prev,i=n.next;null===u?t.head=i:u.next=i,null===i?t.tail=u:i.prev=u,n.prev=null,n.next=null,n.unlinkNext=null,_(n,null)}function J(t,n,u=F){u(()=>{const u=t.tail;if(null!==u){++t.dispatchDepth;try{let i=t.head;for(;null!==i;){const t=i===u?null:i.next;1&i.state&&i.fn(n),i=t}}finally{--t.dispatchDepth,0===t.dispatchDepth&&null!==t.pendingHead&&(t=>{let n=t.pendingHead;for(t.pendingHead=null;null!==n;){const u=n.unlinkNext;n.unlinkNext=null,G(t,n),n=u}})(t)}}})}const K=t=>new ReactiveNode(void 0,t,18);class EventDispatcher{constructor(t=F){this.queue=[],this.head=0,this.flushing=!1,this.runBoundary=t,this.flush=()=>this._flush(),this.flush=this._flush.bind(this)}emit(t,n){this.queue.push(t,n),this.flushing||this.runBoundary(this.flush)}_flush(){if(!this.flushing){this.flushing=!0;try{const t=this.queue;for(;t.length>this.head;)J(t[this.head++],t[this.head++])}finally{this.queue.length=0,this.head=0,this.flushing=!1}}}}function M(t){const n=this.ring;this.size===n.length&&(t=>{const n=t.ring,u=n.length;if(0===u)return void(n.length=16);const i=t.size,r=t.head,e=u-1,o=u<<1,l=Array(o);for(let t=0;i>t;++t)l[t]=n[r+t&e];n.length=o;for(let t=0;i>t;++t)n[t]=l[t];t.head=0,t.tail=i})(this);const u=this.tail;n[u]=t,this.tail=u+1&n.length-1,++this.size}function Q(){if(0===this.size)return null;const t=this.ring,n=this.head,u=t[n];return t[n]=void 0,this.head=n+1&t.length-1,--this.size,u}function V(){this.head=0,this.tail=0,this.size=0}const X=O.bind(null);function Y(t){return 0===t.propagationDepth&&null===t.activeComputed}function $(t,n){return 0===n.phase&&0===n.batchDepth&&Y(t)}function tt(){const t={ring:[],head:0,tail:0,size:0,push:M,shift:Q,clear:V};let n=0,u=0;return{queue:t,flush(){if(2!==u&&0!==t.size){u=2;try{for(;0!==t.size;){const n=t.shift();n.state=-257&n.state,X(n)}}finally{t.clear(),u=n>0?1:0}}},enterBatch(){1===++n&&2!==u&&(u=1)},leaveBatch(){return 0===--n&&2!==u&&(u=0,!0)},reset(){for(;0!==t.size;)t.shift().state&=-257;t.clear(),n=0,u=0},get batchDepth(){return n},get phase(){return u}}}function nt(t,n){const u=n,i=u.state;return!(320&i||(u.state=256|i,t.push(u),0))}function ut(t,n,u,i,r,e,o){return{ring:u.queue.ring,mode:t,context:n,runtimeNotifySettled:o,enqueue:i,batch:r,flush:u.flush,notifySettled:e,reset:u.reset,get head(){return u.queue.head},get batchDepth(){return u.batchDepth},get phase(){return u.phase}}}function it(){}const rt={eager:1,sab:2,flush:0};function et(t){const{scheduler:n,dispatcher:u,executionContext:i}=(t=>{const n=((t={},n={})=>new ExecutionContext(t,n))(t?.hooks),u=((t=0,n=d())=>{switch(t){case 1:return(t=>{const n=tt(),u=n.queue,i=()=>{$(t,n)&&0!==u.size&&n.flush()},r=nt.bind(null,u);return ut(1,t,n,u=>{r(u)&&$(t,n)&&n.flush()},t=>{n.enterBatch();try{return t()}finally{n.leaveBatch()&&0!==u.size&&n.flush()}},i,i)})(n);case 2:return(t=>{const n=tt(),u=n.queue,i=nt.bind(null,u);return ut(2,t,n,i,i=>{n.enterBatch();try{return i()}finally{n.leaveBatch()&&0!==u.size&&Y(t)&&n.flush()}},it,void 0)})(n);default:return(t=>{const n=tt(),u=nt.bind(null,n.queue);return ut(0,t,n,u,t=>{n.enterBatch();try{return t()}finally{n.leaveBatch()}},it,void 0)})(n)}})((i=t?.effectStrategy,i?rt[i]:0),n);var i;const r=new EventDispatcher(u.batch);return n.setRuntimeHooks(u.enqueue,u.runtimeNotifySettled),n.resetState(),(t=>{v=t})(n),{scheduler:u,dispatcher:r,executionContext:n}})(t);return{ctx:i,batch:n.batch,event(){const t=new EventSource;return{subscribe(n){return((t,n)=>{const u={fn:n,next:null,prev:null,state:1,unlinkNext:null};return((t,n)=>{if(!(1&n.state))return;if(null!=Z(n))return;const u=t.tail;n.prev=u,n.next=null,n.unlinkNext=null,_(n,t),null!==u?(u.next=n,t.tail=n):t.head=t.tail=n})(t,u),()=>{((t,n)=>{Z(n)===t&&1&n.state&&(n.state&=-2,0===t.dispatchDepth?(n.state|=2,G(t,n)):((t,n)=>{2&n.state||(n.state|=2,n.unlinkNext=t.pendingHead,t.pendingHead=n)})(t,n))})(t,u)}})(t,n)},emit(n){u.emit(t,n)}}},flush:n.flush}}function ot(t){const n=K(t);return L.bind(null,n)}function lt(t){const u=K(t);return(t=>{const u=t.state;64&u||0!==(u&n)&&z(t)})(u),L.bind(null,u)}function st(t,n){return d().withCleanupRegistrar(t,n)}function ct(t){const n=d(),u=new ReactiveNode(void 0,t,20);O(u);const i=q.bind(null,u);return n.registerWatcherCleanup(i),i}function ft(t){return{subscribe:t}}function ht(t,n){let u,i=!0,r=!1;const e=()=>{if(!i)return;i=!1;const t=u;void 0!==t?(u=void 0,t()):r=!0};if(u=t.subscribe(t=>{i&&(e(),n(t))}),r){const t=u;u=void 0,t?.()}return e}function at(t,n){return ft(u=>t.subscribe(t=>{u(n(t))}))}function vt(t,n){return ft(u=>t.subscribe(t=>{n(t)&&u(t)}))}function dt(...t){return ft(n=>{const u=t.map(t=>t.subscribe(t=>{n(t)}));return()=>{for(const t of u)t()}})}function yt(t,n,u){return bt(t,n,u)}function pt(t,n){return bt(t,n,(t,n)=>n)}function bt(t,n,u){const r=new ReactiveNode(n,null,1);let e=n,o=t.subscribe(t=>{i(r)||(e=u(e,t),T(r,e))});return[()=>i(r)?e:j(r),()=>{(t=>{h(t)})(r);const t=o;o=void 0,t?.()}]}function xt(t){const n=new ReactiveNode(t,null,1);return[j.bind(null,n),t=>{const u="function"==typeof t?t(n.payload):t;T(n,u)}]}export{ot as computed,et as createRuntime,ct as effect,vt as filter,pt as hold,at as map,lt as memo,dt as merge,yt as scan,xt as signal,ht as subscribeOnce,st as withEffectCleanupRegistrar};
@@ -1 +1 @@
1
- class ReactiveEdge{constructor(t,n,i,e,s,r){this.from=t,this.to=n,this.prevOut=i,this.nextOut=e,this.prevIn=s,this.nextIn=r}}function t(t){t.prevOut=null,t.nextOut=null,t.prevIn=null,t.nextIn=null}var n;(t=>{t[t.Producer=1]="Producer",t[t.Consumer=2]="Consumer",t[t.Watcher=4]="Watcher",t[t.Invalid=8]="Invalid",t[t.Changed=16]="Changed",t[t.Visited=32]="Visited",t[t.Disposed=64]="Disposed",t[t.Computing=128]="Computing",t[t.Scheduled=256]="Scheduled",t[t.Tracking=512]="Tracking"})(n||(n={}));const i=n.Producer|n.Consumer|n.Watcher,e=n.Invalid|n.Changed,s=n.Producer,r=n.Changed|n.Watcher;function o(t){t.state&=~n.Computing}function u(t){t.state&=~e}function l(t){return 0!==(t.state&n.Disposed)}function c(t,n,i){const e=i?i.nextIn:t.firstIn;n.prevIn=i,n.nextIn=e,e?e.prevIn=n:t.lastIn=n,i?i.nextIn=n:t.firstIn=n}function h(t,n){const{prevIn:i,nextIn:e}=n;i?i.nextIn=e:t.firstIn=e,e?e.prevIn=i:t.lastIn=i}function f(t,n){const{prevOut:i,nextOut:e}=n;i?i.nextOut=e:t.firstOut=e,e?e.prevOut=i:t.lastOut=i}function a(t,n,i=n.lastIn){const e=t.lastOut,s=i?i.nextIn:n.firstIn,r=new ReactiveEdge(t,n,e,null,i,s);return e?e.nextOut=r:t.firstOut=r,t.lastOut=r,s?s.prevIn=r:n.lastIn=r,i?i.nextIn=r:n.firstIn=r,r}function d(t,n,i,e){for(let s=e?e.nextIn:n.firstIn;null!==s;s=s.nextIn)if(s.from===t)return s.prevIn!==i&&(h(n,s),c(n,s,i)),s;return a(t,n,i)}function v(e){l(e)||((t=>{t.state=t.state&i|n.Disposed})(e),e.depsTail=null,(n=>{let i=n.firstIn;for(n.firstIn=n.lastIn=n.depsTail=null;i;){const n=i.nextIn;f(i.from,i),t(i),i=n}})(e),(n=>{let i=n.firstOut;for(n.firstOut=n.lastOut=null;i;){const n=i.nextOut;i.to.depsTail===i&&(i.to.depsTail=i.prevIn),h(i.to,i),t(i),i=n}})(e),e.compute=null)}const p=Symbol.for("UNINITIALIZED");class ReactiveNode{constructor(t,n,i){this.state=i,this.compute=n,this.firstOut=null,this.firstIn=null,this.lastOut=null,this.lastIn=null,this.depsTail=null,this.payload=t}}function y(t,n){if(!Object.hasOwn(t,n))return;const i=t[n];return"function"==typeof i?i:void 0}class ExecutionContext{constructor(t={}){this.activeComputed=null,this.propagationDepth=0,this.cleanupRegistrar=null,this.onEffectInvalidatedHook=void 0,this.onReactiveSettledHook=void 0,this.hookMask=0,this.hooks={},Object.defineProperties(this.hooks,{onEffectInvalidated:{enumerable:!0,get:()=>this.onEffectInvalidatedHook,set:t=>{this.setOnEffectInvalidatedHook(t)}},onReactiveSettled:{enumerable:!0,get:()=>this.onReactiveSettledHook,set:t=>{this.setOnReactiveSettledHook(t)}}}),this.setHooks(t)}dispatchWatcherEvent(t){const n=this.onEffectInvalidatedHook;void 0!==n&&n?.(t)}maybeNotifySettled(){if(!(2&this.hookMask))return;if(0!==this.propagationDepth||null!==this.activeComputed)return;const t=this.onReactiveSettledHook;t?.()}enterPropagation(){++this.propagationDepth}leavePropagation(){this.propagationDepth>0&&--this.propagationDepth,this.maybeNotifySettled()}resetState(){this.activeComputed=null,this.propagationDepth=0,this.cleanupRegistrar=null}setHooks(t={}){const n=y(t,"onEffectInvalidated"),i=y(t,"onReactiveSettled");this.hooks.onEffectInvalidated=n,this.hooks.onReactiveSettled=i}registerWatcherCleanup(t){this.cleanupRegistrar?.(t)}withCleanupRegistrar(t,n){const i=this.cleanupRegistrar;this.cleanupRegistrar=t;try{return n()}finally{this.cleanupRegistrar=i}}setOnEffectInvalidatedHook(t){this.onEffectInvalidatedHook="function"==typeof t?t:void 0,this.updateHookMask(1,void 0!==this.onEffectInvalidatedHook)}setOnReactiveSettledHook(t){this.onReactiveSettledHook="function"==typeof t?t:void 0,this.updateHookMask(2,void 0!==this.onReactiveSettledHook)}updateHookMask(t,n){this.hookMask=n?this.hookMask|t:this.hookMask&~t}}let R=((t={})=>new ExecutionContext(t))(void 0);function g(){return R}const b=Object.is;function k(n,i=g()){const e=n.depsTail,s=null===e?n.firstIn:e.nextIn;null!==s&&(null===e?(n.firstIn=null,n.lastIn=null):(e.nextIn=null,n.lastIn=e),(n=>{for(;n;){const i=n.nextIn;f(n.from,n),t(n),n=i}})(s))}function w(t,i){t.depsTail=null,t.state=t.state&~n.Visited|n.Tracking,(t=>{t.state|=n.Computing})(t);const e=i.activeComputed;i.activeComputed=t;let s=!1;return()=>{s||(s=!0,i.activeComputed=e)}}function I(t,i=g()){if(l(t))return!1;const e=t.payload;let s=e,r=!1;return s=((t,i=g())=>{const e=t.compute,s=w(t,i);let r;try{return r=e(),s(),k(t,i),r}catch(t){throw s(),t}finally{t.state&=~n.Tracking,o(t),i.maybeNotifySettled()}})(t,i),l(t)||(r=!b(e,s),t.payload=s),u(t),r}const C=n.Invalid,E=n.Changed,S=n.Invalid|n.Changed|n.Disposed|n.Visited|n.Tracking;function j(t,n,i){const e=i.onEffectInvalidatedHook;if(void 0===e)return n;try{e(t)}catch(t){return n??t}return n}function m(t,i=g()){if(0!==(t.state&n.Disposed))return;let s=null;for(let r=t.firstOut;null!==r;r=r.nextOut){const t=r.to,o=t.state;if((o&e)!==n.Invalid)continue;const u=o&~n.Invalid|n.Changed;t.state=u,0!==(u&n.Watcher)&&(s=j(t,s,i))}if(null!==s)throw s}const x=[],O=[];function N(t,i,s){return 0!==(i&(e|n.Disposed))?0:0===(i&n.Tracking)?i&~n.Visited|s:((t,n)=>{if(null===n)return!1;for(let i=t.prevIn;null!==i;i=i.prevIn)if(i===n)return!1;return!0})(t,t.to.depsTail)?i|n.Visited|n.Invalid:0}function H(t,i,e,s,r){const o=x,u=O,l=o.length;let c=l,h=C;for(;;){const f=t.to,a=f.state;let d=0;if(d=0===(a&S)?a|h:N(t,a,h),0!==d)if(f.state=d,0!==(d&n.Watcher))s=j(f,s,r);else{const n=f.firstOut;if(null!==n){null!==i&&(o[c]=i,u[c++]=e),t=n,i=n.nextOut,h=e=C;continue}}if(null!==i)t=i,h=e;else{if(l>=c)return o.length=u.length=l,s;t=o[--c],h=e=u[c]}i=t.nextOut}}function L(t,i,s){return 0!==(i&(e|n.Disposed))?0:0===(i&n.Tracking)?i&~n.Visited|s:((t,n)=>{if(null===n)return!1;if(t===n)return!0;for(let i=t.prevIn;null!==i;i=i.prevIn)if(i===n)return!1;return!0})(t,t.to.depsTail)?i|n.Visited|n.Invalid:0}function P(t,n,i){const e=I(n,i);return!e||null===t.prevOut&&null===t.nextOut||m(n,i),e}function W(t,i,s,r,o,u){let l=!1;t:for(;;){const c=t.from,h=c.state;if(0!==(i.state&n.Changed))l=!0;else if(0!==(h&n.Changed))l=P(t,c,s);else if(0!==(h&e)){const n=c.firstIn;if(null!==n){r[o++]=t,t=n,i=c;continue}l=P(t,c,s)}if(!l){const e=t.nextIn;if(null!==e){t=e;continue}i.state&=~n.Invalid}for(;o>u;){const e=r[--o];if(l?l=P(e,i,s):i.state&=~n.Invalid,i=e.to,!l){const n=e.nextIn;if(null!==n){t=n;continue t}}}return l}}const q=[],A=n.Producer|n.Disposed,D=n.Invalid|n.Visited;var T;function z(t,n=g()){return l(t)||((t,n=g())=>{const i=n.activeComputed;if(!i)return;const e=l(t),s=l(i);if(e||s)return;const r=i.depsTail;if(null===r){const n=i.firstIn;return null===n?void(i.depsTail=a(t,i,null)):n.from===t?void(i.depsTail=n):void(i.depsTail=d(t,i,null,n))}if(r.from===t)return;const o=r.nextIn;i.depsTail=null===o||o.from!==t?d(t,i,r,o):o})(t,n),t.payload}function M(t,i,e=b,s=g()){if(l(t))return;if(e(t.payload,i))return;t.payload=i;const r=t.firstOut;if(null!==r){s.enterPropagation();try{((t,i=C,e=g())=>{if(0!==(t.from.state&n.Disposed))return;const s=((t,i,e,s)=>{for(;;){const r=t.to,o=r.state;let u=0;u=0===(o&S)?o|i:L(t,o,i);const l=t.nextOut;if(u)if(r.state=u,0!==(u&n.Watcher))e=j(r,e,s);else{const n=r.firstOut;if(null!==n){if(null!==l)return H(n,l,i,e,s);t=n,i=C;continue}}if(null===l)return e;t=l}})(t,i,null,e);if(null!==s)throw s})(r,E,s)}finally{s.leavePropagation()}}}function U(){return new ReactiveNode(0,null,s)}function V(t){return new ReactiveNode(null,t,r)}function Z(t){return"pending"===t.status()}(t=>{t[t.lazy=1]="lazy",t[t.eager=2]="eager"})(T||(T={}));class ResourceRequest{constructor(t,n){this.owner=t,this.token=n}alive(){return this.owner.isAlive(this.token)}resolve(t){return this.owner.resolve(this.token,t)}reject(t){return this.owner.reject(this.token,t)}}class ResourceCore{track(){z(this.stateNode,this.context)}bump(){M(this.stateNode,this.stateNode.payload+1)}isAlive(t){return!this.disposed&&this.token===t}start(){const t=this.disposed?this.token:this.token+1;return this.disposed||(this.token=t,this.status="pending",this.error=void 0,this.bump()),new ResourceRequest(this,t)}clear(){this.disposed||(this.token+=1,this.status="idle",this.value=void 0,this.error=void 0,this.bump())}dispose(){this.disposed||(this.disposed=!0,this.token+=1,this.status="idle",this.value=void 0,this.error=void 0,this.bump(),null!==this.watcher&&((t=>{v(t);const n="function"==typeof t.payload?t.payload:null;n?.(),t.payload=p})(this.watcher),this.watcher=null),null!==this.refetchNode&&(v(this.refetchNode),this.refetchNode=null))}resolve(t,n){return!!this.isAlive(t)&&(this.status="resolved",this.value=n,this.error=void 0,this.bump(),!0)}reject(t,n){return!!this.isAlive(t)&&(this.status="rejected",this.error=n,this.bump(),!0)}settle(t,n){var i;"object"==typeof(i=t)&&null!==i&&"then"in i&&"function"==typeof i.then?t.then(t=>{n.resolve(t)},t=>{n.reject(t)}):n.resolve(t)}runLoad(t){const n=this.start();let i;try{i=t(n)}catch(t){return void n.reject(t)}this.settle(i,n)}runSourceLoad(t,n){const i=this.start();let e;try{e=n(t,i)}catch(t){return void i.reject(t)}this.settle(e,i)}refetch(){this.disposed||null===this.refetchNode||M(this.refetchNode,this.refetchNode.payload+1)}constructor(){this.context=g(),this.stateNode=U(),this.status="idle",this.value=void 0,this.error=void 0,this.token=0,this.disposed=!1,this.watcher=null,this.refetchNode=null}}function B(t,i){const s=new ResourceCore,r={status:()=>(s.track(),s.status),value:()=>(s.track(),s.value),error:()=>(s.track(),s.error),token:()=>(s.track(),s.token),clear(){s.clear()},dispose(){s.dispose()}};if("function"==typeof t){if(s.refetchNode=U(),"function"==typeof i){const n=t,e=i;s.watcher=V(()=>{let t;z(s.refetchNode,s.context);try{t=n()}catch(t){return void s.start().reject(t)}s.runSourceLoad(t,e)})}else{const n=t;s.watcher=V(()=>{z(s.refetchNode,s.context),s.runLoad(n)})}return((t,i=g())=>{const s=t.state;if(0!==(s&n.Disposed))return;if(0===(s&e)||0===(s&n.Changed)&&!(t=>{const i=t.state;if(0!==(i&A))return!1;if(0!==(i&n.Changed)||(i&D)===D)return!0;const s=t.firstIn;return null===s?(t.state=i&~n.Invalid,!1):((t,i,s)=>{const r=q,o=r.length;let u=o,l=i,c=t,h=!1;for(;;){if(null!==l.nextIn)return W(l,c,s,r,u,o);if(0!==(c.state&n.Changed)){h=!0;break}const t=l.from,i=t.state;if(0!==(i&n.Changed)&&(h=P(l,t,s),h||null===l.nextIn))break;if(0!==(i&e)){const n=t.firstIn;if(null!==n){if(null!==n.nextIn){r[u++]=l;const i=W(n,t,s,r,u,o);return r.length=o,i}r[u++]=l,l=n,c=t;continue}h=P(l,t,s);break}if(c.state&=~n.Invalid,u===o)return!1;l=r[--u],c=l.to}for(;u>o;){const t=r[--u];h?h=P(t,c,s):c.state&=~n.Invalid,c=t.to}return h||(c.state&=~n.Invalid),r.length=o,h})(t,s,g())})(t))return void u(t);const r="function"==typeof t.payload?t.payload:null;if(t.payload=p,(t=>{t.state&=~n.Visited})(t),u(t),r?.(),l(t))return;let c=!1;((t,i,e=g())=>{const s=t.compute,r=w(t,e);let u;try{return u=s(),r(),k(t,e),i(u)}catch(t){throw r(),t}finally{t.state&=~n.Tracking,o(t),e.maybeNotifySettled()}})(t,n=>{l(t)||(c="function"==typeof n,c&&(t.payload=n))},i)})(s.watcher,s.context),s.context.registerWatcherCleanup(()=>{s.dispose()}),{...r,refetch(){s.refetch()}}}return s.context.registerWatcherCleanup(()=>{s.dispose()}),{...r,start(){return s.start()}}}export{Z as isPending,B as resource};
1
+ class ReactiveEdge{constructor(t,n,i,s,e,r,u){this.version=t,this.prevOut=n,this.nextOut=i,this.from=s,this.to=e,this.prevIn=r,this.nextIn=u}}function t(t){t.prevOut=t.nextOut=t.prevIn=t.nextIn=null}const n=24;function i(t){t.state&=-25}function s(t){return!!(64&t.state)}const e=Symbol.for("UNINITIALIZED");class ReactiveNode{constructor(t,n,i){this.state=0|i,this.firstOut=null,this.firstIn=null,this.lastOut=null,this.lastIn=null,this.depsTail=null,this.compute=n,this.payload=t}}let r;function u(t,n,i){const s=i?i.nextIn:t.firstIn;n.prevIn=i,n.nextIn=s,s?s.prevIn=n:t.lastIn=n,i?i.nextIn=n:t.firstIn=n}function o(t,n){const{prevIn:i,nextIn:s}=n;i?i.nextIn=s:t.firstIn=s,s?s.prevIn=i:t.lastIn=i}function l(t,n){const{prevOut:i,nextOut:s}=n;i?i.nextOut=s:t.firstOut=s,s?s.prevOut=i:t.lastOut=i}function c(t,n,i=n.lastIn,s=0){const e=t.lastOut,r=i?i.nextIn:n.firstIn,u=new ReactiveEdge(s,e,null,t,n,i,r);return e?e.nextOut=u:t.firstOut=u,t.lastOut=u,r?r.prevIn=u:n.lastIn=u,i?i.nextIn=u:n.firstIn=u,u}function h(t,n,i,s,e=0){const r=t.lastOut;if(null!=r&&r.version===e&&r.to===n)return r;for(let r=s?s.nextIn:n.firstIn;null!==r;r=r.nextIn)if(r.from===t)return r.prevIn!==i&&(o(n,r),u(n,r,i)),r.version=e,r;return c(t,n,i,e)}function f(n){s(n)||((t=>{t.state=7&t.state|64})(n),n.depsTail=null,(n=>{let i=n.firstIn;for(n.firstIn=n.lastIn=n.depsTail=null;i;){const n=i.nextIn;l(i.from,i),t(i),i=n}})(n),(n=>{let i=n.firstOut;for(n.firstOut=n.lastOut=null;i;){const n=i.nextOut;i.to.depsTail===i&&(i.to.depsTail=i.prevIn),o(i.to,i),t(i),i=n}})(n),n.compute=null,n.payload=e)}let d=h,a=new class{constructor(t={},n={}){this.activeComputed=null,this.trackingVersion=0,this.propagationDepth=0,this.cleanupRegistrar=null,this.trackReadFallback=h,this.onEffectInvalidated=void 0,this.onReactiveSettled=void 0,this.runtimeOnEffectInvalidated=void 0,this.runtimeOnReactiveSettled=void 0,this.effectInvalidatedDispatch=void 0,this.settledDispatch=void 0,this.setHooks(t),this.setOptions(n)}dispatchWatcherEvent(t){this.effectInvalidatedDispatch?.(t)}maybeNotifySettled(){0===this.propagationDepth&&null===this.activeComputed&&this.settledDispatch?.()}enterPropagation(){++this.propagationDepth}leavePropagation(){this.propagationDepth>0&&--this.propagationDepth,this.maybeNotifySettled()}resetState(){this.activeComputed=null,this.trackingVersion=0,this.propagationDepth=0,this.cleanupRegistrar=null}setOptions(t={}){this.trackReadFallback=d="function"==typeof t.trackReadFallback?t.trackReadFallback:h}setHooks(t={}){this.onEffectInvalidated="function"==typeof t.onEffectInvalidated?t.onEffectInvalidated:void 0,this.onReactiveSettled="function"==typeof t.onReactiveSettled?t.onReactiveSettled:void 0,this.refreshDispatchers()}setRuntimeHooks(t,n){this.runtimeOnEffectInvalidated="function"==typeof t?t:void 0,this.runtimeOnReactiveSettled="function"==typeof n?n:void 0,this.refreshDispatchers()}registerWatcherCleanup(t){this.cleanupRegistrar?.(t)}withCleanupRegistrar(t,n){const i=this.cleanupRegistrar;this.cleanupRegistrar=t;try{return n()}finally{this.cleanupRegistrar=i}}refreshDispatchers(){const t=this.runtimeOnEffectInvalidated,n=this.onEffectInvalidated,i=this.runtimeOnReactiveSettled,s=this.onReactiveSettled;this.effectInvalidatedDispatch=r=t&&n?i=>{t(i),n(i)}:t??n,this.settledDispatch=i&&s?()=>{i(),s()}:i??s}};const v=Object.is;function p(t,n){a.activeComputed=n,t.state&=-513,(t=>{t.state&=-129})(t)}function y(n){const i=n.compute,s=(t=>{const n=a,i=n.trackingVersion+1>>>0;t.depsTail=null,t.state=-33&t.state|512,(t=>{t.state|=128})(t),n.trackingVersion=0===i?1:i;const s=n.activeComputed;return n.activeComputed=t,s})(n);let e;try{return e=i(),p(n,s),n.depsTail!==n.lastIn&&(n=>{const i=n.depsTail,s=null===i?n.firstIn:i.nextIn;if(null===s)return;const e=s;null===i?(n.firstIn=null,n.lastIn=null):(i.nextIn=null,n.lastIn=i),(n=>{for(;n;){const i=n.nextIn;l(n.from,n),t(n),n=i}})(e)})(n),e}catch(t){throw p(n,s),t}}function R(t){if(64&t.state)return;let i=null;const s=r;for(let e=t.firstOut;null!==e;e=e.nextOut){const r=e.to,u=r.state;if(8!==(u&n))continue;const o=u^n;if(r.state=o,4&o&&void 0!==s)try{s(r)}catch(t){null===i&&(i=t)}}if(null!==i)throw i}const w=[];function b(t){return(t=>{if(s(t))return!1;const n=t.payload;let e=n,r=!1;return e=y(t),s(t)||(r=!v(n,e),t.payload=e),i(t),r})(t)}function g(t){return null!==t.prevOut||null!==t.nextOut}function k(t,n){const i=b(t);return i&&n&&R(t),i}function I(t,n){const i=b(t);return i&&n&&R(t),i}function N(t,i,s,e,r){let u=!1;t:for(;;){if(16&i.state)u=!0;else{const r=t.from,o=r.state;if(16&o)u=I(r,g(t));else if(0!==(o&n)){const n=r.firstIn;if(null!==n){s[e++]=t,t=n,i=r;continue}u=I(r,g(t))}}if(!u){const n=t.nextIn;if(null!==n){t=n;continue}i.state&=-9}for(;e>r;){const n=s[--e],r=g(n);if(u?u=I(i,r):i.state&=-9,i=n.to,!u){const i=n.nextIn;if(null!==i){t=i;continue t}}}return u}}function j(t,i){const s=w,e=s.length;let r=e,u=i,o=t,l=!1;for(;;){if(null!==u.nextIn)return N(u,o,s,r,e);if(16&o.state){l=!0;break}const t=u.from,i=t.state;if(16&i){l=k(t,g(u));break}if(0!==(i&n)){const n=t.firstIn;if(null!==n){if(null!==n.nextIn){s[r++]=u;const i=N(n,t,s,r,e);return s.length=e,i}s[r++]=u,u=n,o=t;continue}l=k(t,g(u));break}if(o.state&=-9,r===e)return s.length=e,!1;u=s[--r],o=u.to}for(;r>e;){const t=s[--r],n=g(t);l?l=I(o,n):o.state&=-9,o=t.to}return l||(o.state&=-9),s.length=e,l}function m(t){return"function"==typeof t?t:null}const C=[],E=[];function O(t,n,i){if(void 0!==n)try{n(t)}catch(t){if(null===i)return t}return i}function S(t,i,s,e){const r=-33&s|e,u=40|s;if(!(600&s))return r;if(64&s)return 0;if(512&s){const n=i.depsTail;if(null===n)return 0;if(t===n)return u;const s=t.prevIn;if(null===s)return u;if(s===n)return 0;let e=s.prevIn;for(;null!==e&&e!==n;)e=e.prevIn;return e===n?0:u}return 0!==(s&n)?0:r}function x(t,n,i,s,e){const u=C,o=E,l=u.length;let c=l,h=t.nextOut,f=n;const d=r;for(null!==s&&(u[c]=s,o[c++]=e);;){const s=t.to,e=s.state,r=600&e?S(t,s,e,n):-33&e|n;if(0!==r)if(s.state=r,4&r)i=O(s,d,i);else{const i=s.firstOut;if(null!==i){null!==h&&(u[c]=h,o[c++]=f),h=(t=i).nextOut,n=f=8;continue}}if(null===h){if(c===l)return u.length=l,o.length=l,i;t=u[--c],n=f=o[c],h=t.nextOut}else n=f,h=(t=h).nextOut}}function L(t){if(s(t))return t.payload;const n=a.activeComputed;return null!==n&&(((t,n)=>{const i=n.depsTail,s=a.trackingVersion,e=t.lastOut;if(null!=e&&e.version===s&&e.to===n)return!0;if(null!=i){if(i.from===t)return i.version=s,!0;const e=i.nextIn;return null!=e&&e.from===t&&(e.version=s,n.depsTail=e,!0)}const r=n.firstIn;return null!=r&&r.from===t&&(r.version=s,n.depsTail=r,!0)})(t,n)||((t,n)=>{const i=a.trackingVersion,e=s(t),r=s(n);if(e||r)return;const u=n.depsTail;if(null===u){const s=n.firstIn;return null===s?void(n.depsTail=c(t,n,null,i)):s.from===t?(s.version=i,void(n.depsTail=s)):null===s.nextIn?void(n.depsTail=c(t,n,null,i)):void(n.depsTail=d(t,n,null,s,i))}if(u.from===t)return void(u.version=i);const o=u.nextIn;null===o?n.depsTail=c(t,n,u,i):o.from===t?(o.version=i,n.depsTail=o):n.depsTail=null===o.nextIn?c(t,n,u,i):d(t,n,u,o,i)})(t,n)),t.payload}function q(t,n,i=v){if(s(t))return;if(i(t.payload,n))return;t.payload=n;const e=t.firstOut;if(null===e)return;const u=a;u.enterPropagation();try{((t,n=8)=>{if(64&t.from.state)return;const i=((t,n)=>{let i=null;const s=r;for(;;){const e=t.to,r=t.nextOut,u=e.state,o=600&u?S(t,e,u,n):-33&u|n;if(0!==o)if(e.state=o,4&o)i=O(e,s,i);else{const s=e.firstOut;if(null!==s){if(t=s,null!==r)return x(t,8,i,r,n);n=8;continue}}if(null===r)return i;t=r}})(t,n);if(null!==i)throw i})(e,16)}finally{u.leavePropagation()}}const A=()=>new ReactiveNode(0,null,1),D=t=>new ReactiveNode(void 0,t,20);function H(t){return"pending"===t.status()}class ResourceRequest{constructor(t,n){this.owner=t,this.token=n}alive(){return this.owner.isAlive(this.token)}resolve(t){return this.owner.resolve(this.token,t)}reject(t){return this.owner.reject(this.token,t)}}class ResourceCore{track(){L(this.stateNode)}bump(){q(this.stateNode,this.stateNode.payload+1)}isAlive(t){return!this.disposed&&this.token===t}start(){const t=this.disposed?this.token:this.token+1;return this.disposed||(this.token=t,this.status="pending",this.error=void 0,this.bump()),new ResourceRequest(this,t)}clear(){this.disposed||(this.token+=1,this.status="idle",this.value=void 0,this.error=void 0,this.bump())}dispose(){this.disposed||(this.disposed=!0,this.token+=1,this.status="idle",this.value=void 0,this.error=void 0,this.bump(),null!==this.watcher&&((t=>{const n=m(t.payload);f(t),null!==n&&n(),t.payload=e})(this.watcher),this.watcher=null),null!==this.refetchNode&&(f(this.refetchNode),this.refetchNode=null))}resolve(t,n){return!!this.isAlive(t)&&(this.status="resolved",this.value=n,this.error=void 0,this.bump(),!0)}reject(t,n){return!!this.isAlive(t)&&(this.status="rejected",this.error=n,this.bump(),!0)}settle(t,n){var i;"object"==typeof(i=t)&&null!==i&&"then"in i&&"function"==typeof i.then?t.then(t=>{n.resolve(t)},t=>{n.reject(t)}):n.resolve(t)}runLoad(t){const n=this.start();let i;try{i=t(n)}catch(t){return void n.reject(t)}this.settle(i,n)}runSourceLoad(t,n){const i=this.start();let s;try{s=n(t,i)}catch(t){return void i.reject(t)}this.settle(s,i)}refetch(){this.disposed||null===this.refetchNode||q(this.refetchNode,this.refetchNode.payload+1)}constructor(){this.context=a,this.stateNode=A(),this.status="idle",this.value=void 0,this.error=void 0,this.token=0,this.disposed=!1,this.watcher=null,this.refetchNode=null}}function P(t,s){const r=new ResourceCore,u={status:()=>(r.track(),r.status),value:()=>(r.track(),r.value),error:()=>(r.track(),r.error),token:()=>(r.track(),r.token),clear(){r.clear()},dispose(){r.dispose()}};if("function"==typeof t){if(r.refetchNode=A(),"function"==typeof s){const n=t,i=s;r.watcher=D(()=>{let t;L(r.refetchNode);try{t=n()}catch(t){return void r.start().reject(t)}r.runSourceLoad(t,i)})}else{const n=t;r.watcher=D(()=>{L(r.refetchNode),r.runLoad(n)})}return(t=>{const s=t.state;if(64&s)return;if(0===(s&n))return;if(!((t,n)=>{if(16&n)return!0;if(!(40&~n))return!0;const i=t.firstIn;return null===i?(t.state=-9&n,!1):j(t,i)})(t,s))return void i(t);const r=m(t.payload);if(t.payload=e,(t=>{t.state&=-33})(t),null!==r&&r(),64&t.state)return;const u=y(t);"function"==typeof u&&(t.payload=u),32&t.state?t.state=-17&t.state|8:i(t)})(r.watcher),r.context.registerWatcherCleanup(()=>{r.dispose()}),{...u,refetch(){r.refetch()}}}return r.context.registerWatcherCleanup(()=>{r.dispose()}),{...u,start(){return r.start()}}}export{H as isPending,P as resource};