@volynets/reflex 0.1.2 → 0.1.4

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.
@@ -1 +1 @@
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
+ class ReactiveEdge{constructor(t,n,r,e,u,i,o){this.version=t,this.prevOut=n,this.nextOut=r,this.from=e,this.to=u,this.prevIn=i,this.nextIn=o}}function t(t){t.prevOut=t.nextOut=t.prevIn=t.nextIn=null}const n=24;function r(t){t.state&=-25}function e(t){return!!(64&t.state)}const u=Symbol.for("UNINITIALIZED");class ReactiveNode{constructor(t,n,r){this.state=0|r,this.firstOut=null,this.firstIn=null,this.lastOut=null,this.lastIn=null,this.depsTail=null,this.compute=n,this.payload=t}}let i;function o(t,n,r){const e=r?r.nextIn:t.firstIn;n.prevIn=r,n.nextIn=e,e?e.prevIn=n:t.lastIn=n,r?r.nextIn=n:t.firstIn=n}function l(t,n){const{prevIn:r,nextIn:e}=n;r?r.nextIn=e:t.firstIn=e,e?e.prevIn=r:t.lastIn=r}function s(t,n){const{prevOut:r,nextOut:e}=n;r?r.nextOut=e:t.firstOut=e,e?e.prevOut=r:t.lastOut=r}function c(t,n,r=n.lastIn,e=0){const u=t.lastOut,i=r?r.nextIn:n.firstIn,o=new ReactiveEdge(e,u,null,t,n,r,i);return u?u.nextOut=o:t.firstOut=o,t.lastOut=o,i?i.prevIn=o:n.lastIn=o,r?r.nextIn=o:n.firstIn=o,o}function f(t,n,r,e,u=0){for(let i=e??n.firstIn;null!==i;i=i.nextIn)if(i.from===t)return i.prevIn!==r&&(l(n,i),o(n,i,r)),i.version=u,i;return c(t,n,r,u)}function h(n){e(n)||((t=>{t.state=7&t.state|64})(n),n.depsTail=null,(n=>{let r=n.firstIn;for(n.firstIn=n.lastIn=n.depsTail=null;r;){const n=r.nextIn;s(r.from,r),t(r),r=n}})(n),(n=>{let r=n.firstOut;for(n.firstOut=n.lastOut=null;r;){const n=r.nextOut;r.to.depsTail===r&&(r.to.depsTail=r.prevIn),l(r.to,r),t(r),r=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 r=this.cleanupRegistrar;this.cleanupRegistrar=t;try{return n()}finally{this.cleanupRegistrar=r}}refreshDispatchers(){const t=this.runtimeOnEffectInvalidated,n=this.onEffectInvalidated,r=this.runtimeOnReactiveSettled,e=this.onReactiveSettled;this.effectInvalidatedDispatch=i=t&&n?r=>{t(r),n(r)}:t??n,this.settledDispatch=r&&e?()=>{r(),e()}:r??e}}let v=new ExecutionContext;function d(){return v}const p=Object.is;function y(t,n){const r=n.depsTail,e=v.trackingVersion,u=t.lastOut;if(null!=u&&u.version===e&&u.to===n)return!0;if(null!=r){if(r.from===t)return r.version=e,!0;const u=r.nextIn;return null!=u&&u.from===t&&(u.version=e,n.depsTail=u,!0)}const i=n.firstIn;return null!=i&&i.from===t&&(i.version=e,n.depsTail=i,!0)}function x(t,n){const r=v.trackingVersion,u=e(t),i=e(n);if(u||i)return;const o=n.depsTail;if(null===o){const e=n.firstIn;return null===e?void(n.depsTail=c(t,n,null,r)):e.from===t?(e.version=r,void(n.depsTail=e)):null===e.nextIn?void(n.depsTail=c(t,n,null,r)):void(n.depsTail=a(t,n,null,e,r))}if(o.from===t)return void(o.version=r);const l=o.nextIn;return null===l?void(n.depsTail=c(t,n,o,r)):l.from===t?(l.version=r,void(n.depsTail=l)):null===l.nextIn?void(n.depsTail=c(t,n,o,r)):void(n.depsTail=a(t,n,o,l,r))}function b(t,n){v.activeComputed=n,t.state&=-513,(t=>{t.state&=-129})(t)}function g(n){const r=n.compute,e=(t=>{const n=v,r=n.trackingVersion+1>>>0;t.depsTail=null,t.state=-33&t.state|512,(t=>{t.state|=128})(t),n.trackingVersion=0===r?1:r;const e=n.activeComputed;return n.activeComputed=t,e})(n);let u;try{return u=r(),b(n,e),n.depsTail!==n.lastIn&&(n=>{const r=n.depsTail,e=null===r?n.firstIn:r.nextIn;if(null===e)return;const u=e;null===r?(n.firstIn=null,n.lastIn=null):(r.nextIn=null,n.lastIn=r),(n=>{for(;n;){const r=n.nextIn;s(n.from,n),t(n),n=r}})(u)})(n),u}catch(t){throw b(n,e),t}}function w(t){if(e(t))return!1;const n=t.payload;let u=n,i=!1;return u=g(t),e(t)||(i=!p(n,u),t.payload=u),r(t),i}function E(t){if(64&t.state)return;let r=null;const e=i;for(let u=t.firstOut;null!==u;u=u.nextOut){const i=u.to,o=i.state;if(8!==(o&n))continue;const l=o^n;if(i.state=l,4&l&&void 0!==e)try{e(i)}catch(t){null===r&&(r=t)}}if(null!==r)throw r}const N=[];function R(t){return w(t)}function S(t){return null!==t.prevOut||null!==t.nextOut}function k(t,n){const r=R(t);return r&&n&&E(t),r}function m(t,n){const r=R(t);return r&&n&&E(t),r}function C(t,r,e,u,i){let o=!1;t:for(;;){if(16&r.state)o=!0;else{const i=t.from,l=i.state;if(16&l)o=m(i,S(t));else if(0!==(l&n)){const n=i.firstIn;if(null!==n){e[u++]=t,t=n,r=i;continue}o=m(i,S(t))}}if(!o){const n=t.nextIn;if(null!==n){t=n;continue}r.state&=-9}for(;u>i;){const n=e[--u],i=S(n);if(o?o=m(r,i):r.state&=-9,r=n.to,!o){const r=n.nextIn;if(null!==r){t=r;continue t}}}return o}}function D(t,r){const e=N,u=e.length;let i=u,o=r,l=t,s=!1;for(;;){if(null!==o.nextIn)return C(o,l,e,i,u);if(16&l.state){s=!0;break}const t=o.from,r=t.state;if(16&r){s=k(t,S(o));break}if(0!==(r&n)){const n=t.firstIn;if(null!==n){if(null!==n.nextIn){e[i++]=o;const r=C(n,t,e,i,u);return e.length=u,r}e[i++]=o,o=n,l=t;continue}s=k(t,S(o));break}if(l.state&=-9,i===u)return e.length=u,!1;o=e[--i],l=o.to}for(;i>u;){const t=e[--i],n=S(t);s?s=m(l,n):l.state&=-9,l=t.to}return s||(l.state&=-9),e.length=u,s}function I(t){return"function"==typeof t?t:null}function B(t){const e=t.state;if(64&e)return;if(0===(e&n))return;if(!((t,n)=>{if(16&n)return!0;if(!(40&~n))return!0;const r=t.firstIn;return null===r?(t.state=-9&n,!1):D(t,r)})(t,e))return void r(t);const i=I(t.payload);if(t.payload=u,(t=>{t.state&=-33})(t),null!==i&&i(),64&t.state)return;const o=g(t);"function"==typeof o&&(t.payload=o),32&t.state?t.state=-17&t.state|8:r(t)}function O(t){const n=I(t.payload);h(t),null!==n&&n(),t.payload=u}const q=[],A=[];function H(t,n,r){if(void 0!==n)try{n(t)}catch(t){if(null===r)return t}return r}function P(t,n,r){const e=n.depsTail;if(null===e)return 0;const u=40|r;if(t===e)return u;const i=t.prevIn;if(null===i)return u;if(i===e)return 0;let o=i.prevIn;for(;null!==o&&o!==e;)o=o.prevIn;return o===e?0:u}function W(t,r,e,u){const i=-33&e|u,o=40|e;if(!(600&e))return i;if(64&e)return 0;if(512&e){const n=r.depsTail;if(null===n)return 0;if(t===n)return o;const e=t.prevIn;if(null===e)return o;if(e===n)return 0;let u=e.prevIn;for(;null!==u&&u!==n;)u=u.prevIn;return u===n?0:o}return 0!==(e&n)?0:i}function j(t,n,r,e,u){const o=q,l=A,s=o.length;let c=s,f=t.nextOut,h=n;const a=i;for(null!==e&&(o[c]=e,l[c++]=u);;){const e=t.to,u=e.state;let i;if(i=600&u?512&u?P(t,e,u):88&u?0:-33&u|n:-33&u|n,0!==i)if(e.state=i,4&i)r=H(e,a,r);else{const r=e.firstOut;if(null!==r){null!==f&&(o[c]=f,l[c++]=h),f=(t=r).nextOut,n=h=8;continue}}if(null===f){if(c===s)return o.length=s,l.length=s,r;t=o[--c],n=h=l[c],f=t.nextOut}else n=h,f=(t=f).nextOut}}function z(t){if(e(t))return t.payload;const n=v.activeComputed;return null!==n&&(y(t,n)||x(t,n)),t.payload}function L(t){const e=t.state;return 64&e||0===(e&n)||(((t,n)=>{if(16&n)return!0;if(!(40&~n))return!0;const r=t.firstIn;return null===r?(t.state=-9&n,!1):D(t,r)})(t,e)?w(t)&&null!==t.firstOut&&E(t):r(t)),t.payload}function T(t){const r=t.state;if(64&r)return t.payload;const u=0!==(r&n)?L(t):t.payload;if(0!==(r&n)&&e(t))return u;const i=v.activeComputed;return null!==i&&(y(t,i)||x(t,i)),u}function U(t,n,r=p){if(e(t))return;if(r(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;let r=null;const e=i;for(;;){const u=t.to,i=t.nextOut,o=u.state,l=600&o?W(t,u,o,n):-33&o|n;if(0!==l)if(u.state=l,4&l)r=H(u,e,r);else{const e=u.firstOut;if(null!==e){t=e,null!==i&&(r=j(t,8,r,i,n)),n=8;continue}}if(null===i)break;t=i}if(null!==r)throw r})(u,16)}finally{o.leavePropagation()}}class EventSource{constructor(){this.dispatchDepth=0,this.head=null,this.tail=null,this.pendingHead=null}}const Z=Symbol("EventSubscriber.owner");function _(t){return t[Z]}function F(t,n){t[Z]=n}function G(t){return t()}function J(t,n){const r=n.prev,e=n.next;null===r?t.head=e:r.next=e,null===e?t.tail=r:e.prev=r,n.prev=null,n.next=null,n.unlinkNext=null,F(n,null)}function K(t,n,r=G){r(()=>{const r=t.tail;if(null!==r){++t.dispatchDepth;try{let e=t.head;for(;null!==e;){const t=e===r?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 r=n.unlinkNext;n.unlinkNext=null,J(t,n),n=r}})(t)}}})}const M=t=>new ReactiveNode(void 0,t,18);class EventDispatcher{constructor(t=G){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;)K(t[this.head++],t[this.head++])}finally{this.queue.length=0,this.head=0,this.flushing=!1}}}}function Q(t){const n=this.ring;this.size===n.length&&(t=>{const n=t.ring,r=n.length;if(0===r)return void(n.length=16);const e=t.size,u=t.head,i=r-1,o=r<<1,l=Array(o);for(let t=0;e>t;++t)l[t]=n[u+t&i];n.length=o;for(let t=0;e>t;++t)n[t]=l[t];t.head=0,t.tail=e})(this);const r=this.tail;n[r]=t,this.tail=r+1&n.length-1,++this.size}function V(){if(0===this.size)return null;const t=this.ring,n=this.head,r=t[n];return t[n]=void 0,this.head=n+1&t.length-1,--this.size,r}function X(){this.head=0,this.tail=0,this.size=0}function Y(){return{ring:[],head:0,tail:0,size:0,push:Q,shift:V,clear:X}}const $=-257,tt=B.bind(null);function nt(t){return 0===t.propagationDepth&&null===t.activeComputed}function rt(t,n){return 0===n.phase&&0===n.batchDepth&&nt(t)}function et(){const t=Y();let n=0,r=0;return{queue:t,flush(){if(2!==r&&0!==t.size){r=2;try{for(;0!==t.size;){const n=t.shift();n.state=n.state&$,tt(n)}}finally{t.clear(),r=n>0?1:0}}},enterBatch(){1===++n&&2!==r&&(r=1)},leaveBatch(){return 0===--n&&2!==r&&(r=0,!0)},reset(){for(;0!==t.size;)t.shift().state&=$;t.clear(),n=0,r=0},get batchDepth(){return n},get phase(){return r}}}function ut(t,n){const r=n,e=r.state;return!(320&e||(r.state=256|e,t.push(r),0))}function it(t,n,r,e,u,i,o){return{ring:r.queue.ring,mode:t,context:n,runtimeNotifySettled:o,enqueue:e,batch:u,flush:r.flush,notifySettled:i,reset:r.reset,get head(){return r.queue.head},get batchDepth(){return r.batchDepth},get phase(){return r.phase}}}function ot(){}const lt=B.bind(null);function st(t){return t.priority??t.rank??0}const ct={eager:1,sab:2,flush:0,ranked:3};function ft(t){return{subscribe:t}}function ht(t,n,r){const u=new ReactiveNode(n,null,1);let i=n,o=t.subscribe(t=>{e(u)||(i=r(i,t),U(u,i))});return[()=>e(u)?i:z(u),()=>{(t=>{h(t)})(u);const t=o;o=void 0,t?.()}]}exports.computed=t=>{const n=M(t);return T.bind(null,n)},exports.createRuntime=t=>{const{scheduler:n,dispatcher:r,executionContext:e}=(t=>{const n=((t={},n={})=>new ExecutionContext(t,n))(t?.hooks),r=((t=0,n=d())=>{switch(t){case 1:return(t=>{const n=et(),r=n.queue,e=()=>{rt(t,n)&&0!==r.size&&n.flush()},u=ut.bind(null,r);return it(1,t,n,r=>{u(r)&&rt(t,n)&&n.flush()},t=>{n.enterBatch();try{return t()}finally{n.leaveBatch()&&0!==r.size&&n.flush()}},e,e)})(n);case 3:return(t=>{const n=Y();let r=0,e=0;const u={queue:n,flush(){if(2===e)return;if(0===n.size)return;e=2;const t=[];try{for(;0!==n.size;)t.push(n.shift());t.sort((t,n)=>st(n)-st(t));for(let n=0;t.length>n;++n){const r=t[n];r.state=r.state&$,lt(r)}}finally{n.clear(),e=r>0?1:0}},enterBatch(){1===++r&&2!==e&&(e=1)},leaveBatch:()=>0===--r&&2!==e&&(e=0,!0),reset(){for(;0!==n.size;)n.shift().state&=$;n.clear(),r=0,e=0},get batchDepth(){return r},get phase(){return e}},i=ut.bind(null,n);return it(3,t,u,i,t=>{u.enterBatch();try{return t()}finally{u.leaveBatch()}},ot,void 0)})(n);case 2:return(t=>{const n=et(),r=n.queue,e=ut.bind(null,r);return it(2,t,n,e,e=>{n.enterBatch();try{return e()}finally{n.leaveBatch()&&0!==r.size&&nt(t)&&n.flush()}},ot,void 0)})(n);default:return(t=>{const n=et(),r=ut.bind(null,n.queue);return it(0,t,n,r,t=>{n.enterBatch();try{return t()}finally{n.leaveBatch()}},ot,void 0)})(n)}})((e=t?.effectStrategy,e?ct[e]:0),n);var e;const u=new EventDispatcher(r.batch);return n.setRuntimeHooks(r.enqueue,r.runtimeNotifySettled),n.resetState(),(t=>{v=t})(n),{scheduler:r,dispatcher:u,executionContext:n}})(t);return{ctx:e,batch:n.batch,event(){const t=new EventSource;return{subscribe(n){return((t,n)=>{const r={fn:n,next:null,prev:null,state:1,unlinkNext:null};return((t,n)=>{if(!(1&n.state))return;if(null!=_(n))return;const r=t.tail;n.prev=r,n.next=null,n.unlinkNext=null,F(n,t),null!==r?(r.next=n,t.tail=n):t.head=t.tail=n})(t,r),()=>{((t,n)=>{_(n)===t&&1&n.state&&(n.state&=-2,0===t.dispatchDepth?(n.state|=2,J(t,n)):((t,n)=>{2&n.state||(n.state|=2,n.unlinkNext=t.pendingHead,t.pendingHead=n)})(t,n))})(t,r)}})(t,n)},emit(n){r.emit(t,n)}}},flush:n.flush}},exports.effect=t=>{const n=d(),r=new ReactiveNode(void 0,t,20);B(r);const e=O.bind(null,r);return n.registerWatcherCleanup(e),e},exports.filter=(t,n)=>ft(r=>t.subscribe(t=>{n(t)&&r(t)})),exports.hold=(t,n)=>ht(t,n,(t,n)=>n),exports.map=(t,n)=>ft(r=>t.subscribe(t=>{r(n(t))})),exports.memo=t=>{const r=M(t);return(t=>{const r=t.state;64&r||0!==(r&n)&&L(t)})(r),T.bind(null,r)},exports.merge=(...t)=>ft(n=>{const r=t.map(t=>t.subscribe(t=>{n(t)}));return()=>{for(const t of r)t()}}),exports.scan=(t,n,r)=>ht(t,n,r),exports.signal=t=>{const n=new ReactiveNode(t,null,1);return[z.bind(null,n),t=>{const r="function"==typeof t?t(n.payload):t;U(n,r)}]},exports.subscribeOnce=(t,n)=>{let r,e=!0,u=!1;const i=()=>{if(!e)return;e=!1;const t=r;void 0!==t?(r=void 0,t()):u=!0};if(r=t.subscribe(t=>{e&&(i(),n(t))}),u){const t=r;r=void 0,t?.()}return i},exports.withEffectCleanupRegistrar=(t,n)=>d().withCleanupRegistrar(t,n);
@@ -1 +1 @@
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()}}};
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){for(let r=s??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 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,n,i){const s=n.depsTail;if(null===s)return 0;const e=40|i;if(t===s)return e;const r=t.prevIn;if(null===r)return e;if(r===s)return 0;let u=r.prevIn;for(;null!==u&&u!==s;)u=u.prevIn;return u===s?0:e}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 L(t,n,i,s,e){const u=x,o=C,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;let r;if(r=600&e?512&e?O(t,s,e):88&e?0:-33&e|n:-33&e|n,0!==r)if(s.state=r,4&r)i=E(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 q(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 A(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;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=E(e,s,i);else{const s=e.firstOut;if(null!==s){t=s,null!==r&&(i=L(t,8,i,r,n)),n=8;continue}}if(null===r)break;t=r}if(null!==i)throw i})(e,16)}finally{u.leavePropagation()}}const D=()=>new ReactiveNode(0,null,1),H=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(){q(this.stateNode)}bump(){A(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||A(this.refetchNode,this.refetchNode.payload+1)}constructor(){this.context=a,this.stateNode=D(),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,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=D(),"function"==typeof s){const n=t,i=s;r.watcher=H(()=>{let t;q(r.refetchNode);try{t=n()}catch(t){return void r.start().reject(t)}r.runSourceLoad(t,i)})}else{const n=t;r.watcher=H(()=>{q(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()}}};
package/dist/esm/index.js CHANGED
@@ -1 +1 @@
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
+ class ReactiveEdge{constructor(t,n,u,r,i,e,o){this.version=t,this.prevOut=n,this.nextOut=u,this.from=r,this.to=i,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 r(t){return!!(64&t.state)}const i=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 r=u?u.nextIn:t.firstIn;n.prevIn=u,n.nextIn=r,r?r.prevIn=n:t.lastIn=n,u?u.nextIn=n:t.firstIn=n}function l(t,n){const{prevIn:u,nextIn:r}=n;u?u.nextIn=r:t.firstIn=r,r?r.prevIn=u:t.lastIn=u}function s(t,n){const{prevOut:u,nextOut:r}=n;u?u.nextOut=r:t.firstOut=r,r?r.prevOut=u:t.lastOut=u}function c(t,n,u=n.lastIn,r=0){const i=t.lastOut,e=u?u.nextIn:n.firstIn,o=new ReactiveEdge(r,i,null,t,n,u,e);return i?i.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,r,i=0){for(let e=r??n.firstIn;null!==e;e=e.nextIn)if(e.from===t)return e.prevIn!==u&&(l(n,e),o(n,e,u)),e.version=i,e;return c(t,n,u,i)}function h(n){r(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=i)}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,r=this.onReactiveSettled;this.effectInvalidatedDispatch=e=t&&n?u=>{t(u),n(u)}:t??n,this.settledDispatch=u&&r?()=>{u(),r()}:u??r}}let v=new ExecutionContext;function d(){return v}const y=Object.is;function p(t,n){const u=n.depsTail,r=v.trackingVersion,i=t.lastOut;if(null!=i&&i.version===r&&i.to===n)return!0;if(null!=u){if(u.from===t)return u.version=r,!0;const i=u.nextIn;return null!=i&&i.from===t&&(i.version=r,n.depsTail=i,!0)}const e=n.firstIn;return null!=e&&e.from===t&&(e.version=r,n.depsTail=e,!0)}function b(t,n){const u=v.trackingVersion,i=r(t),e=r(n);if(i||e)return;const o=n.depsTail;if(null===o){const r=n.firstIn;return null===r?void(n.depsTail=c(t,n,null,u)):r.from===t?(r.version=u,void(n.depsTail=r)):null===r.nextIn?void(n.depsTail=c(t,n,null,u)):void(n.depsTail=a(t,n,null,r,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 g(n){const u=n.compute,r=(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 r=n.activeComputed;return n.activeComputed=t,r})(n);let i;try{return i=u(),x(n,r),n.depsTail!==n.lastIn&&(n=>{const u=n.depsTail,r=null===u?n.firstIn:u.nextIn;if(null===r)return;const i=r;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}})(i)})(n),i}catch(t){throw x(n,r),t}}function w(t){if(r(t))return!1;const n=t.payload;let i=n,e=!1;return i=g(t),r(t)||(e=!y(n,i),t.payload=i),u(t),e}function E(t){if(64&t.state)return;let u=null;const r=e;for(let i=t.firstOut;null!==i;i=i.nextOut){const e=i.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===u&&(u=t)}}if(null!==u)throw u}const N=[];function R(t){return w(t)}function S(t){return null!==t.prevOut||null!==t.nextOut}function k(t,n){const u=R(t);return u&&n&&E(t),u}function m(t,n){const u=R(t);return u&&n&&E(t),u}function C(t,u,r,i,e){let o=!1;t:for(;;){if(16&u.state)o=!0;else{const e=t.from,l=e.state;if(16&l)o=m(e,S(t));else if(0!==(l&n)){const n=e.firstIn;if(null!==n){r[i++]=t,t=n,u=e;continue}o=m(e,S(t))}}if(!o){const n=t.nextIn;if(null!==n){t=n;continue}u.state&=-9}for(;i>e;){const n=r[--i],e=S(n);if(o?o=m(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 r=N,i=r.length;let e=i,o=u,l=t,s=!1;for(;;){if(null!==o.nextIn)return C(o,l,r,e,i);if(16&l.state){s=!0;break}const t=o.from,u=t.state;if(16&u){s=k(t,S(o));break}if(0!==(u&n)){const n=t.firstIn;if(null!==n){if(null!==n.nextIn){r[e++]=o;const u=C(n,t,r,e,i);return r.length=i,u}r[e++]=o,o=n,l=t;continue}s=k(t,S(o));break}if(l.state&=-9,e===i)return r.length=i,!1;o=r[--e],l=o.to}for(;e>i;){const t=r[--e],n=S(t);s?s=m(l,n):l.state&=-9,l=t.to}return s||(l.state&=-9),r.length=i,s}function I(t){return"function"==typeof t?t:null}function B(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 u=t.firstIn;return null===u?(t.state=-9&n,!1):D(t,u)})(t,r))return void u(t);const e=I(t.payload);if(t.payload=i,(t=>{t.state&=-33})(t),null!==e&&e(),64&t.state)return;const o=g(t);"function"==typeof o&&(t.payload=o),32&t.state?t.state=-17&t.state|8:u(t)}function O(t){const n=I(t.payload);h(t),null!==n&&n(),t.payload=i}const q=[],A=[];function H(t,n,u){if(void 0!==n)try{n(t)}catch(t){if(null===u)return t}return u}function P(t,n,u){const r=n.depsTail;if(null===r)return 0;const i=40|u;if(t===r)return i;const e=t.prevIn;if(null===e)return i;if(e===r)return 0;let o=e.prevIn;for(;null!==o&&o!==r;)o=o.prevIn;return o===r?0:i}function W(t,u,r,i){const e=-33&r|i,o=40|r;if(!(600&r))return e;if(64&r)return 0;if(512&r){const n=u.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 i=r.prevIn;for(;null!==i&&i!==n;)i=i.prevIn;return i===n?0:o}return 0!==(r&n)?0:e}function j(t,n,u,r,i){const o=q,l=A,s=o.length;let c=s,f=t.nextOut,h=n;const a=e;for(null!==r&&(o[c]=r,l[c++]=i);;){const r=t.to,i=r.state;let e;if(e=600&i?512&i?P(t,r,i):88&i?0:-33&i|n:-33&i|n,0!==e)if(r.state=e,4&e)u=H(r,a,u);else{const u=r.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 z(t){if(r(t))return t.payload;const n=v.activeComputed;return null!==n&&(p(t,n)||b(t,n)),t.payload}function L(t){const r=t.state;return 64&r||0===(r&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,r)?w(t)&&null!==t.firstOut&&E(t):u(t)),t.payload}function T(t){const u=t.state;if(64&u)return t.payload;const i=0!==(u&n)?L(t):t.payload;if(0!==(u&n)&&r(t))return i;const e=v.activeComputed;return null!==e&&(p(t,e)||b(t,e)),i}function U(t,n,u=y){if(r(t))return;if(u(t.payload,n))return;t.payload=n;const i=t.firstOut;if(null===i)return;const o=v;o.enterPropagation();try{((t,n=8)=>{if(64&t.from.state)return;let u=null;const r=e;for(;;){const i=t.to,e=t.nextOut,o=i.state,l=600&o?W(t,i,o,n):-33&o|n;if(0!==l)if(i.state=l,4&l)u=H(i,r,u);else{const r=i.firstOut;if(null!==r){t=r,null!==e&&(u=j(t,8,u,e,n)),n=8;continue}}if(null===e)break;t=e}if(null!==u)throw u})(i,16)}finally{o.leavePropagation()}}class EventSource{constructor(){this.dispatchDepth=0,this.head=null,this.tail=null,this.pendingHead=null}}const Z=Symbol("EventSubscriber.owner");function _(t){return t[Z]}function F(t,n){t[Z]=n}function G(t){return t()}function J(t,n){const u=n.prev,r=n.next;null===u?t.head=r:u.next=r,null===r?t.tail=u:r.prev=u,n.prev=null,n.next=null,n.unlinkNext=null,F(n,null)}function K(t,n,u=G){u(()=>{const u=t.tail;if(null!==u){++t.dispatchDepth;try{let r=t.head;for(;null!==r;){const t=r===u?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 u=n.unlinkNext;n.unlinkNext=null,J(t,n),n=u}})(t)}}})}const M=t=>new ReactiveNode(void 0,t,18);class EventDispatcher{constructor(t=G){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;)K(t[this.head++],t[this.head++])}finally{this.queue.length=0,this.head=0,this.flushing=!1}}}}function Q(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 r=t.size,i=t.head,e=u-1,o=u<<1,l=Array(o);for(let t=0;r>t;++t)l[t]=n[i+t&e];n.length=o;for(let t=0;r>t;++t)n[t]=l[t];t.head=0,t.tail=r})(this);const u=this.tail;n[u]=t,this.tail=u+1&n.length-1,++this.size}function V(){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 X(){this.head=0,this.tail=0,this.size=0}function Y(){return{ring:[],head:0,tail:0,size:0,push:Q,shift:V,clear:X}}const $=-257,tt=B.bind(null);function nt(t){return 0===t.propagationDepth&&null===t.activeComputed}function ut(t,n){return 0===n.phase&&0===n.batchDepth&&nt(t)}function rt(){const t=Y();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=n.state&$,tt(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&=$;t.clear(),n=0,u=0},get batchDepth(){return n},get phase(){return u}}}function it(t,n){const u=n,r=u.state;return!(320&r||(u.state=256|r,t.push(u),0))}function et(t,n,u,r,i,e,o){return{ring:u.queue.ring,mode:t,context:n,runtimeNotifySettled:o,enqueue:r,batch:i,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 ot(){}const lt=B.bind(null);function st(t){return t.priority??t.rank??0}const ct={eager:1,sab:2,flush:0,ranked:3};function ft(t){const{scheduler:n,dispatcher:u,executionContext:r}=(t=>{const n=((t={},n={})=>new ExecutionContext(t,n))(t?.hooks),u=((t=0,n=d())=>{switch(t){case 1:return(t=>{const n=rt(),u=n.queue,r=()=>{ut(t,n)&&0!==u.size&&n.flush()},i=it.bind(null,u);return et(1,t,n,u=>{i(u)&&ut(t,n)&&n.flush()},t=>{n.enterBatch();try{return t()}finally{n.leaveBatch()&&0!==u.size&&n.flush()}},r,r)})(n);case 3:return(t=>{const n=Y();let u=0,r=0;const i={queue:n,flush(){if(2===r)return;if(0===n.size)return;r=2;const t=[];try{for(;0!==n.size;)t.push(n.shift());t.sort((t,n)=>st(n)-st(t));for(let n=0;t.length>n;++n){const u=t[n];u.state=u.state&$,lt(u)}}finally{n.clear(),r=u>0?1:0}},enterBatch(){1===++u&&2!==r&&(r=1)},leaveBatch:()=>0===--u&&2!==r&&(r=0,!0),reset(){for(;0!==n.size;)n.shift().state&=$;n.clear(),u=0,r=0},get batchDepth(){return u},get phase(){return r}},e=it.bind(null,n);return et(3,t,i,e,t=>{i.enterBatch();try{return t()}finally{i.leaveBatch()}},ot,void 0)})(n);case 2:return(t=>{const n=rt(),u=n.queue,r=it.bind(null,u);return et(2,t,n,r,r=>{n.enterBatch();try{return r()}finally{n.leaveBatch()&&0!==u.size&&nt(t)&&n.flush()}},ot,void 0)})(n);default:return(t=>{const n=rt(),u=it.bind(null,n.queue);return et(0,t,n,u,t=>{n.enterBatch();try{return t()}finally{n.leaveBatch()}},ot,void 0)})(n)}})((r=t?.effectStrategy,r?ct[r]:0),n);var r;const i=new EventDispatcher(u.batch);return n.setRuntimeHooks(u.enqueue,u.runtimeNotifySettled),n.resetState(),(t=>{v=t})(n),{scheduler:u,dispatcher:i,executionContext:n}})(t);return{ctx:r,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!=_(n))return;const u=t.tail;n.prev=u,n.next=null,n.unlinkNext=null,F(n,t),null!==u?(u.next=n,t.tail=n):t.head=t.tail=n})(t,u),()=>{((t,n)=>{_(n)===t&&1&n.state&&(n.state&=-2,0===t.dispatchDepth?(n.state|=2,J(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 ht(t){const n=M(t);return T.bind(null,n)}function at(t){const u=M(t);return(t=>{const u=t.state;64&u||0!==(u&n)&&L(t)})(u),T.bind(null,u)}function vt(t,n){return d().withCleanupRegistrar(t,n)}function dt(t){const n=d(),u=new ReactiveNode(void 0,t,20);B(u);const r=O.bind(null,u);return n.registerWatcherCleanup(r),r}function yt(t){return{subscribe:t}}function pt(t,n){let u,r=!0,i=!1;const e=()=>{if(!r)return;r=!1;const t=u;void 0!==t?(u=void 0,t()):i=!0};if(u=t.subscribe(t=>{r&&(e(),n(t))}),i){const t=u;u=void 0,t?.()}return e}function bt(t,n){return yt(u=>t.subscribe(t=>{u(n(t))}))}function xt(t,n){return yt(u=>t.subscribe(t=>{n(t)&&u(t)}))}function gt(...t){return yt(n=>{const u=t.map(t=>t.subscribe(t=>{n(t)}));return()=>{for(const t of u)t()}})}function wt(t,n,u){return Nt(t,n,u)}function Et(t,n){return Nt(t,n,(t,n)=>n)}function Nt(t,n,u){const i=new ReactiveNode(n,null,1);let e=n,o=t.subscribe(t=>{r(i)||(e=u(e,t),U(i,e))});return[()=>r(i)?e:z(i),()=>{(t=>{h(t)})(i);const t=o;o=void 0,t?.()}]}function Rt(t){const n=new ReactiveNode(t,null,1);return[z.bind(null,n),t=>{const u="function"==typeof t?t(n.payload):t;U(n,u)}]}export{ht as computed,ft as createRuntime,dt as effect,xt as filter,Et as hold,bt as map,at as memo,gt as merge,wt as scan,Rt as signal,pt as subscribeOnce,vt as withEffectCleanupRegistrar};
@@ -1 +1 @@
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};
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){for(let r=s??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,n,i){const s=n.depsTail;if(null===s)return 0;const e=40|i;if(t===s)return e;const r=t.prevIn;if(null===r)return e;if(r===s)return 0;let u=r.prevIn;for(;null!==u&&u!==s;)u=u.prevIn;return u===s?0:e}function x(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 L(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;let r;if(r=600&e?512&e?S(t,s,e):88&e?0:-33&e|n:-33&e|n,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 q(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 A(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;let i=null;const s=r;for(;;){const e=t.to,r=t.nextOut,u=e.state,o=600&u?x(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){t=s,null!==r&&(i=L(t,8,i,r,n)),n=8;continue}}if(null===r)break;t=r}if(null!==i)throw i})(e,16)}finally{u.leavePropagation()}}const D=()=>new ReactiveNode(0,null,1),H=t=>new ReactiveNode(void 0,t,20);function P(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(){q(this.stateNode)}bump(){A(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||A(this.refetchNode,this.refetchNode.payload+1)}constructor(){this.context=a,this.stateNode=D(),this.status="idle",this.value=void 0,this.error=void 0,this.token=0,this.disposed=!1,this.watcher=null,this.refetchNode=null}}function W(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=D(),"function"==typeof s){const n=t,i=s;r.watcher=H(()=>{let t;q(r.refetchNode);try{t=n()}catch(t){return void r.start().reject(t)}r.runSourceLoad(t,i)})}else{const n=t;r.watcher=H(()=>{q(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{P as isPending,W as resource};
package/dist/globals.d.ts CHANGED
@@ -406,6 +406,8 @@ declare function withEffectCleanupRegistrar<T>(registrar: EffectCleanupRegistrar
406
406
  * - The first run happens synchronously during `effect()` creation.
407
407
  * - With the default runtime strategy, later re-runs are queued until
408
408
  * `rt.flush()`.
409
+ * - With `createRuntime({ effectStrategy: "ranked" })`, later re-runs are
410
+ * queued until `rt.flush()` and then drained in descending watcher rank.
409
411
  * - With `createRuntime({ effectStrategy: "sab" })`, invalidations stay lazy
410
412
  * during propagation but auto-deliver after the outermost `rt.batch()`.
411
413
  * - With `createRuntime({ effectStrategy: "eager" })`, invalidations flush
@@ -419,7 +421,7 @@ declare function withEffectCleanupRegistrar<T>(registrar: EffectCleanupRegistrar
419
421
  */
420
422
  declare function effect(fn: EffectFn): Destructor;
421
423
 
422
- type EffectStrategy = "flush" | "eager" | "sab";
424
+ type EffectStrategy = "flush" | "eager" | "sab" | "ranked";
423
425
 
424
426
  interface RuntimeOptions {
425
427
  /**
@@ -433,6 +435,8 @@ interface RuntimeOptions {
433
435
  * Controls when invalidated effects are executed.
434
436
  *
435
437
  * - `"flush"` queues reruns until `rt.flush()` is called.
438
+ * - `"ranked"` queues reruns until `rt.flush()` and then drains higher-rank
439
+ * watchers before lower-rank ones.
436
440
  * - `"sab"` keeps lazy enqueue semantics but stabilizes effects after the
437
441
  * outermost `rt.batch()` exits.
438
442
  * - `"eager"` flushes reruns automatically.
@@ -516,7 +520,8 @@ interface Runtime {
516
520
  *
517
521
  * @param options - Optional runtime configuration:
518
522
  * - `effectStrategy` controls whether invalidated effects flush on
519
- * `rt.flush()`, stabilize after the outermost batch, or run automatically.
523
+ * `rt.flush()`, flush in rank order, stabilize after the outermost batch, or
524
+ * run automatically.
520
525
  * - `hooks` installs low-level runtime hooks that are composed with Reflex's
521
526
  * scheduler integration.
522
527
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@volynets/reflex",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "type": "module",
5
5
  "description": "Public Reflex facade with a connected runtime",
6
6
  "license": "MIT",
package/src/api/effect.ts CHANGED
@@ -98,6 +98,8 @@ export function withEffectCleanupRegistrar<T>(
98
98
  * - The first run happens synchronously during `effect()` creation.
99
99
  * - With the default runtime strategy, later re-runs are queued until
100
100
  * `rt.flush()`.
101
+ * - With `createRuntime({ effectStrategy: "ranked" })`, later re-runs are
102
+ * queued until `rt.flush()` and then drained in descending watcher rank.
101
103
  * - With `createRuntime({ effectStrategy: "sab" })`, invalidations stay lazy
102
104
  * during propagation but auto-deliver after the outermost `rt.batch()`.
103
105
  * - With `createRuntime({ effectStrategy: "eager" })`, invalidations flush
package/src/api/event.ts CHANGED
@@ -228,25 +228,25 @@ export function hold<T>(
228
228
  return createScan(source, initial, (_, value) => value);
229
229
  }
230
230
 
231
- function createScan<T, A>(
232
- source: Event<T>,
233
- seed: A,
234
- reducer: (acc: A, value: T) => A,
235
- ): [read: Accessor<A>, dispose: Destructor] {
236
- const node = createAccumulator(seed);
237
- let current = seed;
238
- const accessor = () => (isDisposedNode(node) ? current : readProducer(node));
239
-
240
- let unsubscribe: Destructor | undefined = source.subscribe((value: T) => {
241
- /* c8 ignore start -- disposal unsubscribes before a queued delivery can reach this callback */
242
- if (isDisposedNode(node)) return;
243
- /* c8 ignore stop */
244
- current = reducer(current, value);
245
- writeProducer(node, current);
246
- });
247
-
248
- function dispose(): void {
249
- disposeNodeEvent(node);
231
+ function createScan<T, A>(
232
+ source: Event<T>,
233
+ seed: A,
234
+ reducer: (acc: A, value: T) => A,
235
+ ): [read: Accessor<A>, dispose: Destructor] {
236
+ const node = createAccumulator(seed);
237
+ let current = seed;
238
+ const accessor = () => (isDisposedNode(node) ? current : readProducer(node));
239
+
240
+ let unsubscribe: Destructor | undefined = source.subscribe((value: T) => {
241
+ /* c8 ignore start -- disposal unsubscribes before a queued delivery can reach this callback */
242
+ if (isDisposedNode(node)) return;
243
+ /* c8 ignore stop */
244
+ current = reducer(current, value);
245
+ writeProducer(node, current);
246
+ });
247
+
248
+ function dispose(): void {
249
+ disposeNodeEvent(node);
250
250
 
251
251
  const stop = unsubscribe;
252
252
  unsubscribe = undefined;
@@ -21,6 +21,8 @@ export interface RuntimeOptions {
21
21
  * Controls when invalidated effects are executed.
22
22
  *
23
23
  * - `"flush"` queues reruns until `rt.flush()` is called.
24
+ * - `"ranked"` queues reruns until `rt.flush()` and then drains higher-rank
25
+ * watchers before lower-rank ones.
24
26
  * - `"sab"` keeps lazy enqueue semantics but stabilizes effects after the
25
27
  * outermost `rt.batch()` exits.
26
28
  * - `"eager"` flushes reruns automatically.
@@ -131,7 +133,8 @@ export interface Runtime {
131
133
  *
132
134
  * @param options - Optional runtime configuration:
133
135
  * - `effectStrategy` controls whether invalidated effects flush on
134
- * `rt.flush()`, stabilize after the outermost batch, or run automatically.
136
+ * `rt.flush()`, flush in rank order, stabilize after the outermost batch, or
137
+ * run automatically.
135
138
  * - `hooks` installs low-level runtime hooks that are composed with Reflex's
136
139
  * scheduler integration.
137
140
  *
@@ -4,6 +4,7 @@ export const enum EffectSchedulerMode {
4
4
  Flush = 0,
5
5
  Eager = 1,
6
6
  SAB = 2,
7
+ Ranked = 3,
7
8
  }
8
9
 
9
10
  export const enum SchedulerPhase {
@@ -4,16 +4,18 @@ import { EffectSchedulerMode } from "./scheduler.constants";
4
4
  import type { EffectScheduler } from "./scheduler.types";
5
5
  import {
6
6
  createEagerScheduler,
7
+ createRankedScheduler,
7
8
  createSabScheduler,
8
9
  createFlushScheduler,
9
10
  } from "./variants";
10
11
 
11
- export type EffectStrategy = "flush" | "eager" | "sab";
12
+ export type EffectStrategy = "flush" | "eager" | "sab" | "ranked";
12
13
 
13
14
  const strategyMap: Record<EffectStrategy, EffectSchedulerMode> = {
14
15
  eager: EffectSchedulerMode.Eager,
15
16
  sab: EffectSchedulerMode.SAB,
16
17
  flush: EffectSchedulerMode.Flush,
18
+ ranked: EffectSchedulerMode.Ranked,
17
19
  };
18
20
 
19
21
  export function resolveEffectSchedulerMode(
@@ -29,6 +31,8 @@ export function createEffectScheduler(
29
31
  switch (mode) {
30
32
  case EffectSchedulerMode.Eager:
31
33
  return createEagerScheduler(context);
34
+ case EffectSchedulerMode.Ranked:
35
+ return createRankedScheduler(context);
32
36
  case EffectSchedulerMode.SAB:
33
37
  return createSabScheduler(context);
34
38
  default:
@@ -1,3 +1,4 @@
1
- export * from "./scheduler.eager";
2
- export * from "./scheduler.flush";
3
- export * from "./scheduler.sab";
1
+ export * from "./scheduler.eager";
2
+ export * from "./scheduler.flush";
3
+ export * from "./scheduler.ranked";
4
+ export * from "./scheduler.sab";
@@ -0,0 +1,118 @@
1
+ import type { ExecutionContext } from "@reflex/runtime";
2
+ import { runWatcher } from "@reflex/runtime";
3
+ import {
4
+ EffectSchedulerMode,
5
+ SchedulerPhase,
6
+ UNSCHEDULE_MASK,
7
+ } from "../scheduler.constants";
8
+ import { createSchedulerInstance, tryEnqueue } from "../scheduler.core";
9
+ import { createWatcherQueue } from "../scheduler.queue";
10
+ import type {
11
+ EffectNode,
12
+ EffectScheduler,
13
+ SchedulerCore,
14
+ } from "../scheduler.types";
15
+ import { noopNotifySettled } from "../scheduler.types";
16
+
17
+ type RankedEffectNode = EffectNode & {
18
+ priority?: number;
19
+ rank?: number;
20
+ };
21
+
22
+ const runner = runWatcher.bind(null);
23
+
24
+ function getNodeRank(node: EffectNode): number {
25
+ const rankedNode = node as RankedEffectNode;
26
+ return rankedNode.priority ?? rankedNode.rank ?? 0;
27
+ }
28
+
29
+ export function createRankedScheduler(
30
+ context: ExecutionContext,
31
+ ): EffectScheduler {
32
+ const queue = createWatcherQueue();
33
+ let batchDepth = 0;
34
+ let phase = SchedulerPhase.Idle;
35
+
36
+ const flush = (): void => {
37
+ if (phase === SchedulerPhase.Flushing) return;
38
+ if (queue.size === 0) return;
39
+
40
+ phase = SchedulerPhase.Flushing;
41
+ const pending: EffectNode[] = [];
42
+
43
+ try {
44
+ while (queue.size !== 0) {
45
+ pending.push(queue.shift()!);
46
+ }
47
+
48
+ pending.sort((left, right) => getNodeRank(right) - getNodeRank(left));
49
+
50
+ for (let i = 0; i < pending.length; ++i) {
51
+ const node = pending[i]!,
52
+ s = node.state;
53
+ node.state = s & UNSCHEDULE_MASK;
54
+ runner(node);
55
+ }
56
+ } finally {
57
+ queue.clear();
58
+ phase = batchDepth > 0 ? SchedulerPhase.Batching : SchedulerPhase.Idle;
59
+ }
60
+ };
61
+
62
+ const core: SchedulerCore = {
63
+ queue,
64
+ flush,
65
+ enterBatch() {
66
+ if (++batchDepth === 1 && phase !== SchedulerPhase.Flushing) {
67
+ phase = SchedulerPhase.Batching;
68
+ }
69
+ },
70
+ leaveBatch() {
71
+ if (--batchDepth !== 0) {
72
+ return false;
73
+ }
74
+
75
+ if (phase === SchedulerPhase.Flushing) {
76
+ return false;
77
+ }
78
+
79
+ phase = SchedulerPhase.Idle;
80
+ return true;
81
+ },
82
+ reset() {
83
+ while (queue.size !== 0) {
84
+ queue.shift()!.state &= UNSCHEDULE_MASK;
85
+ }
86
+
87
+ queue.clear();
88
+ batchDepth = 0;
89
+ phase = SchedulerPhase.Idle;
90
+ },
91
+ get batchDepth() {
92
+ return batchDepth;
93
+ },
94
+ get phase() {
95
+ return phase;
96
+ },
97
+ };
98
+
99
+ const enqueue = tryEnqueue.bind(null, queue);
100
+ const batch = <T>(fn: () => T): T => {
101
+ core.enterBatch();
102
+ try {
103
+ return fn();
104
+ } finally {
105
+ core.leaveBatch();
106
+ }
107
+ };
108
+
109
+ return createSchedulerInstance(
110
+ EffectSchedulerMode.Ranked,
111
+ context,
112
+ core,
113
+ enqueue,
114
+ batch,
115
+ noopNotifySettled,
116
+ undefined,
117
+ );
118
+ }