@jucie.io/reactive 1.0.13 → 1.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/main.js +1 -1
- package/dist/main.js.map +3 -3
- package/package.json +1 -1
package/dist/main.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
function D(t){return typeof window<"u"&&window.requestIdleCallback?window.requestIdleCallback(t,{timeout:100}):typeof window<"u"?window.requestAnimationFrame?window.requestAnimationFrame(()=>{setTimeout(t,0)}):setTimeout(t,0):(typeof t=="function"&&t(),null)}var l=class{constructor(){this.roots=new Map,this.pending=new Set,this.onCompleteCallbacks=new Set,this.onNextIdle=new Set,this.idleScheduled=!1}markAsDirty(e){if(!e.isDirty&&(e.isDirty=!0,e.isAsync||e.immediate||e.effects&&e.effects.size>0?this.scheduleRecomputation(e):(this.onNextIdle.add(e),this.idleScheduled||(this.idleScheduled=!0,D(()=>{for(let s of this.onNextIdle)this.pending.add(s);this.flush(null),this.onNextIdle.clear(),this.idleScheduled=!1}))),e.dependants&&e.dependants.size>0)){let s=[],r=new Set;e.dependants.forEach(n=>{let c=n.deref();c?(this.markAsDirty(c),r.add(c._id)):s.push(n)}),s.forEach(n=>e.dependants.delete(n)),e.dependantIds=r}}scheduleRecomputation(e){if(!e.debounce)return this.recompute(e);let s=Date.now(),r=e._lastComputeTime?s-e._lastComputeTime:1/0;return!e._hasPendingDebounce||r>=e.debounce?(clearTimeout(e._debounceTimer),e._hasPendingDebounce=!0,e._lastComputeTime=s,e._debounceTimer=setTimeout(()=>{e._hasPendingDebounce=!1,e._debounceTimer=null},e.debounce),this.recompute(e)):e.cachedValue}removeReactive(e){this.pending.delete(e),this.onNextIdle.delete(e)}recompute(e){return this.pending.add(e),this.flush(e)}flush(e){let s=Array.from(this.pending);this.pending.clear();let r=this.sortByDependencies(s);for(let n of r)this.onNextIdle.delete(n),n.compute();for(let n of this.onCompleteCallbacks)try{n()}catch(c){console.error("Error in batch completion callback:",c)}if(e)return r.includes(e)||e.compute(),e.cachedValue}sortByDependencies(e){let s=[],r=new Set,n=new Set,c=o=>{if(n.has(o)||r.has(o))return;n.add(o);let a=o.dependants;a&&a.size>0&&a.forEach(u=>{let g=u.deref();g&&e.includes(g)&&c(g)}),n.delete(o),r.add(o),s.unshift(o)};for(let o of e)r.has(o)||c(o);return s}};var i=class t{static computationManager=new l;static awaitingRecomputation=new Set;static reactives=new WeakMap;static currentlyComputing=null;static computationStack=[];static currentDepth=0;static effectsCache=new Set;static processingEffects=!1;static _nextId=1;static config={maxDepth:2e3};static ctx={};static nextId(){return t._nextId++}static addContext(e,s){if(!e||typeof e!="string")throw new Error("Invalid context key");if(typeof s>"u")throw new Error("Invalid context value");if(e in t.ctx)throw new Error("Context key already exists");t.ctx[e]=s}static useContext(e){if(!e||e.length===0)return t.ctx;if(e.length===1)return t.ctx[e[0]];let s=new Array(e.length);for(let r=0;r<e.length;r++)s[r]=t.ctx[e[r]];return s}static hasContext(e){if(!e||e.length===0)return Object.keys(t.ctx).length>0;if(e.length===1)return e[0]in t.ctx;for(let s of e)if(!(s in t.ctx))return!1;return!0}static clearContext(){t.ctx={}}static begin(e){t.awaitingRecomputation.has(e)&&t.awaitingRecomputation.delete(e);let s=t.computationStack.indexOf(e);if(s!==-1){if(e.isAsync){t.computationStack.splice(s,1),t.computationStack.push(e),t.currentlyComputing=e;return}let r=t.computationStack.slice(s).concat(e),n=new Error(`Circular dependency detected: ${r.map(c=>c).join(" -> ")}`);throw n.name="CircularDependencyError",n.displayed=!1,n}if(t.currentDepth>=t.config.maxDepth)throw new Error(`Maximum reactive depth of ${t.config.maxDepth} exceeded`);t.computationStack.push(e),t.currentlyComputing=e,t.currentDepth++}static end(e){if(e.isAsync){t.computationStack.splice(t.computationStack.indexOf(e),1),t.currentlyComputing=t.computationStack[t.computationStack.length-1]||null,t.currentDepth--;return}t.computationStack.pop(),t.currentlyComputing=t.computationStack[t.computationStack.length-1]||null,t.currentDepth--}static addEffect(e,s){let r=t.reactives.get(e);return r.isDirty&&t.computationManager.scheduleRecomputation(r),r.effects||(r.effects=new Set),r.effects.add(s),()=>t.removeEffect(e,s)}static removeEffect(e,s){let r=t.reactives.get(e);r.effects&&r.effects.delete(s)}static recompute(e){return t.awaitingRecomputation.has(e)||t.awaitingRecomputation.add(e),t.computationManager.scheduleRecomputation(e)}static callEffects(e){t.effectsCache.add(e),t.processingEffects||(t.processingEffects=!0,setTimeout(()=>{t.processEffectsCache(),t.processingEffects=!1},0))}static processEffectsCache(){let e=new Set(t.effectsCache);t.effectsCache.clear();for(let s of e)try{(s.effects||new Set).forEach(n=>{n&&n(s.cachedValue)})}catch(r){console.error(`Error in reactive ${s._id} effect:`,r)}t.effectsCache.size>0&&setTimeout(()=>{t.processEffectsCache()},0)}static markAsDirty(e){if(!e.isDirty){e.isDirty=!0,(e.immediate||e.effects&&e.effects.size>0)&&t.computationManager.scheduleRecomputation(e);let s=[],r=new Set;e.dependants.forEach(n=>{let c=n.deref();c?(t.markAsDirty(c),r.add(c._id)):s.push(n)}),s.forEach(n=>e.dependants.delete(n)),e.dependantIds=r}}static destroy(e){let s=t.reactives.get(e);t.computationManager.removeReactive(s),t.reactives.delete(e)}};var h=t=>i.reactives.has(t),p=(t,e)=>{if(!h(t))throw new Error("Invalid effect getter");if(!e||typeof e!="function")throw new Error("Invalid effect function");return i.addEffect(t,e)},v=(t,e)=>{if(h(t))return i.removeEffect(t,e)};var V=(t,e)=>i.addContext(t,e),k=(...t)=>t.length===0?i.ctx:t.length===1?i.ctx[t[0]]:t.map(e=>i.ctx[e]),R=(...t)=>i.hasContext(t),T=(t,e=[])=>{if(!h(t))throw new Error("Invalid adapter getter");let s,r=null,n=new Set,c=()=>{if(s!==void 0)return s;let a=e&&e.length>0?traverse(t(),e):t();if(Array.isArray(a))s=a.slice();else if(typeof a=="object"&&a!==null){let u=Object.create(Object.getPrototypeOf(a));Object.defineProperties(u,Object.getOwnPropertyDescriptors(a)),s=Object.freeze(u)}else s=a;return s};return[c,a=>(r||(r=p(t,()=>{s=void 0;for(let u of n)u(c)})),n.add(a),()=>{n.delete(a),n.size===0&&(r(),r=null)})]};var E=t=>typeof t=="function"&&(t.constructor.name==="AsyncFunction"||t.constructor.name==="AsyncGeneratorFunction");var m=class t{static create(e,s={}){let r=new t(e,s);return i.reactives.set(r.getter,r),r.getter}constructor(e,s={}){this.fn=e,this.isAsync=E(e),this.pendingResolve=void 0,this.roots=new Set,this.dependants=new Set,this.dependantIds=new Set,this.effects=new Set(Array.isArray(s.effects)?s.effects:[]),this.cachedValue=s.initialValue||void 0,this.isDirty=!0,this.debounce=s.debounce||0,this.onAccess=s.onAccess||void 0,this.detatched=s.detatched||!1,this.immediate=s.immediate||!1,this.context=s.context||void 0,this.useContext=()=>this.context?this.context:i.hasContext()?i.useContext():void 0,this.resolvers=[],this.rejectors=[],this._id=i.nextId(),this._lastComputeTime=void 0,this._hasPendingDebounce=!1,this._debounceTimer=void 0,this._computationId=0,this.getter=this.#e.bind(this),this.immediate&&this.compute()}compute(){i.begin(this);try{if(!this.isAsync)return this.cachedValue=this.fn(this.useContext(),this.cachedValue),this.isDirty=!1,this.cachedValue;this._computationId=(this._computationId||0)+1;let e=this._computationId;return this.pendingResolve=this.fn(this.useContext(),this.cachedValue),this.pendingResolve.then(s=>(this._computationId===e&&(this.resolvers.forEach(r=>r(s)),this.resolvers=[],this.cachedValue=s,this.isDirty=!1),s)).catch(s=>{this._computationId===e&&(this.rejectors.forEach(r=>r(s)),this.rejectors=[])}).finally(()=>{this.pendingResolve=null,this._computationId===e&&(i.end(this),i.callEffects(this))}),this.cachedValue=new Promise((s,r)=>{this.resolvers.push(s),this.rejectors.push(r)}),this.cachedValue}finally{this.isAsync||(i.end(this),i.callEffects(this))}}#e(){try{return!this.detatched&&i.currentlyComputing&&i.currentlyComputing!==this&&!this.dependantIds.has(i.currentlyComputing._id)&&(this.dependantIds.add(i.currentlyComputing._id),this.dependants.add(new WeakRef(i.currentlyComputing))),this.isDirty?i.recompute(this):this.isAsync?Promise.resolve(this.cachedValue):this.cachedValue}catch(e){throw e}finally{this.onAccess&&this.onAccess(this.cachedValue)}}},w=(t,e={})=>m.create(t,e),C=t=>{A(t)&&i.destroy(t)},A=t=>{let e=i.reactives.get(t);return e?e instanceof m:!1},$=t=>{let e=i.reactives.get(t);return e?e.isDirty:!1};var b=class t{static create(e,s={}){let r=new t(e,s);return i.reactives.set(r.getter,r),r.getter}constructor(e,s={}){this._id=i.nextId(),this.isAsync=!1,this.cachedValue=void 0,this.dependants=new Set,this.dependantIds=new Set,this.roots=new Set,this.effects=new Set(Array.isArray(s.effects)?s.effects:[]),this.isDirty=!0,this.debounce=s.debounce||0,this.onAccess=s.onAccess||null,this.detatched=s.detatched||!1,this.immediate=s.immediate||!1,this._pendingChange=e,this._lastComputeTime=null,this._hasPendingDebounce=!1,this._debounceTimer=null,this.getter=(...r)=>this.#e(...r)}compute(){i.begin(this);try{return this.cachedValue=this._pendingChange,this._pendingChange=void 0,this.isDirty=!1,this.cachedValue}finally{i.end(this),i.callEffects(this)}}#e(...e){try{if(!this.detatched&&i.currentlyComputing&&i.currentlyComputing!==this&&!this.dependantIds.has(i.currentlyComputing._id)&&(this.dependantIds.add(i.currentlyComputing._id),this.dependants.add(new WeakRef(i.currentlyComputing))),e.length>0){let s=e[0];this._pendingChange=typeof s=="function"?s(this.cachedValue):s,i.markAsDirty(this);return}return this.isDirty?i.recompute(this):this.cachedValue}catch(s){throw s}finally{this.onAccess&&this.onAccess(this.cachedValue)}}},S=(t,e={})=>b.create(t,e),M=t=>{O(t)&&i.destroy(t)},O=t=>{let e=i.reactives.get(t);return e?e instanceof b:!1},z=t=>{let e=i.reactives.get(t);return e?e.isDirty:!1};var y=class t{static create(e,s,r={}){let n=new t(e,s,r);return i.reactives.set(n.getter,n),()=>i.destroy(n.getter)}constructor(e,s,r={}){this._id=i.nextId(),this.getter=e,this.isDirty=!1,this.subscriber=s,this.debounce=r.debounce||0,this.onAccess=r.onAccess||null,this.immediate=!0,this._hasPendingDebounce=!1,this._lastComputeTime=null,this._debounceTimer=null,this.dependants=new Set,this.dependantIds=new Set,this.unsubscribe=()=>i.computationManager.removeReactive(this),i.begin(this),this.cachedValue=this.getter(),this.subscriber(this.cachedValue),i.end(this)}compute(){try{this.cachedValue=this.getter(),this.subscriber(this.cachedValue),this.isDirty=!1}catch(e){throw e}}},F=(t,e,s={})=>y.create(t,e,s),N=t=>{I(t)&&i.destroy(t)},I=t=>{let e=i.reactives.get(t);return e?e instanceof y:!1};var d=[null,null,(t,e)=>t?.[e[0]]?.[e[1]],(t,e)=>t?.[e[0]]?.[e[1]]?.[e[2]],(t,e)=>t?.[e[0]]?.[e[1]]?.[e[2]]?.[e[3]],(t,e)=>t?.[e[0]]?.[e[1]]?.[e[2]]?.[e[3]]?.[e[4]],(t,e)=>t?.[e[0]]?.[e[1]]?.[e[2]]?.[e[3]]?.[e[4]]?.[e[5]],(t,e)=>t?.[e[0]]?.[e[1]]?.[e[2]]?.[e[3]]?.[e[4]]?.[e[5]]?.[e[6]],(t,e)=>t?.[e[0]]?.[e[1]]?.[e[2]]?.[e[3]]?.[e[4]]?.[e[5]]?.[e[6]]?.[e[7]]];function q(t){let s="obj"+Array.from({length:t},(n,c)=>`?.[path[${c}]]`).join(""),r=new Function("obj","path",`return ${s}`);return d[t]=r,r}function P(t,e){let s=e.length;return s===0?t:s===1?t[e[0]]:s<d.length&&d[s]||d[s]?d[s](t,e):q(s)(t,e)}var x=Symbol(),f=class t{static surfaces=new WeakMap;static plugins=new Map;static registerPlugin(e,s){if(t.plugins.has(e))throw new Error(`Plugin "${e}" already registered`);t.plugins.set(e,s())}static resetPlugins(){t.plugins.clear()}static create(e,s={}){let r=new t(s),n=r.setup(e);return t.surfaces.set(n,r),n}static createPlugin(e,s,r={}){let n=t.create(s,r);return t.registerPlugin(e,n),n}constructor(e={}){this.options=e,this.setupFn=null,this.subscribers=new Set,this.subscribersQueued=!1,this.destroyCallback=null,this.values=new Set,this.computeds=new Set,this.actions=new Set,this.extensions=new Set,this.snapshotCache=x,this.surface=this.#n(),this.useSurface=()=>this.surface}setup(e){if(!e)return null;this.setupFn=e,this.reset();let s=new Set;try{let r;if(typeof e=="function")r=this.#e(e,s);else if(typeof e=="object"&&e!==null)r=this.#o(e,s);else throw new Error("setupFn must be a function or object configuration");return this.#h(r),s.forEach(n=>p(n,()=>this.#r())),this.#r(),this.useSurface}catch(r){throw console.error("Error in setup function",r),r}}reset(){this.subscribers.clear(),this.subscribersQueued=!1,this.values.clear(),this.computeds.clear(),this.actions.clear(),this.extensions.clear(),this.snapshotCache=x,this.surface=this.#n()}createValue(e=void 0,s){let r=S(e),n=Object.create(null);return Object.defineProperty(n,"value",{get:()=>r(),set:c=>r(c),enumerable:!0}),this.values.add(n),s?.(r),n}createComputed(e,s){let r=w(e,{context:this.surface}),n=Object.create(null);return Object.defineProperty(n,"value",{get:()=>r(),enumerable:!0}),this.computeds.add(n),s?.(r),n}createAction(e){let s=e.bind(this.surface,this.surface);return this.actions.add(s),s}extend(e){if(!e)throw new Error("No source surface provided");if(!j(e))throw new Error("Cannot extend non-surface");let s=e();return this.extensions.add(s),s}#e(e,s){return e({value:(r=void 0)=>this.createValue(r,n=>s.add(n)),computed:(r=()=>{})=>this.createComputed(r,n=>s.add(n)),action:(r=()=>{})=>this.createAction(r),extend:r=>this.extend(r),destroy:()=>this.#i(),...Object.fromEntries(t.plugins.entries())})||{}}#c(e,s,r){if(typeof e!="object"||e===null)return typeof e=="function"?e():e;if(!("default"in e))return s&&"dummy"in e&&console.warn(`State "${r}" has dummy value but no default value`),typeof e=="function"?e():e;let n=s&&"dummy"in e?e.dummy:e.default;return typeof n=="function"?n():n}#o(e,s){let r={},n=this.options.mode==="development"||this.options.mode==="dev";if(e.extend&&Array.isArray(e.extend))for(let c of e.extend)this.extend(c);if(e.state&&typeof e.state=="object")for(let[c,o]of Object.entries(e.state)){let a=this.#c(o,n,c);r[c]=this.createValue(a,u=>s.add(u))}if(e.computed&&typeof e.computed=="object")for(let[c,o]of Object.entries(e.computed))typeof o=="function"&&(r[c]=this.createComputed(o,a=>s.add(a)));if(e.actions&&typeof e.actions=="object")for(let[c,o]of Object.entries(e.actions))typeof o=="function"&&(r[c]=this.createAction(o));return e.onInit&&typeof e.onInit=="function"&&Promise.resolve().then(()=>{try{e.onInit(this.surface)}catch(c){console.error("Error in onInit callback",c)}}),e.onDestroy&&typeof e.onDestroy=="function"&&(this.destroyCallback=e.onDestroy),r}#a(){return[()=>this.#t(),e=>this.#s(e)]}#t(){if(this.snapshotCache!==x)return this.snapshotCache;let e=Object.create(Object.getPrototypeOf(this.surface));return Object.defineProperties(e,Object.getOwnPropertyDescriptors(this.surface)),this.snapshotCache=Object.freeze(e),this.snapshotCache}#s(e){return this.subscribers.add(e),()=>this.subscribers.delete(e)}#u(e){for(let s of this.subscribers)s(e)}#r(){this.subscribers.size===0||this.subscribersQueued||(this.subscribersQueued=!0,Promise.resolve().then(()=>{this.subscribersQueued=!1,this.snapshotCache=x,this.#u(this.#t())}))}#n(e=Object.create(null)){return Object.defineProperty(e,"$get",{value:s=>this.#d(s),writable:!1,enumerable:!1,configurable:!1}),Object.defineProperty(e,"$set",{value:(s,r)=>this.#f(s,r),writable:!1,enumerable:!1,configurable:!1}),Object.defineProperty(e,"$dispatch",{value:s=>this.#l(s),writable:!1,enumerable:!1,configurable:!1}),Object.defineProperty(e,"$inject",{value:s=>Object.assign({},this.surface,s),writable:!1,enumerable:!1,configurable:!1}),Object.defineProperty(e,"$snapshot",{value:()=>this.#t(),writable:!1,enumerable:!1,configurable:!1}),Object.defineProperty(e,"$subscribe",{value:s=>this.#s(s),writable:!1,enumerable:!1,configurable:!1}),Object.defineProperty(e,"$adapter",{value:()=>this.#a(),writable:!1,enumerable:!1,configurable:!1}),Object.defineProperty(e,"$destroy",{value:()=>this.#i(),writable:!1,enumerable:!1,configurable:!1}),e}#i(){if(this.destroyCallback&&typeof this.destroyCallback=="function")try{this.destroyCallback(this.surface)}catch(s){console.error("Error in onDestroy callback",s)}let e=this.surfaceComputed;this.surfaceComputed=null,t.surfaces.delete(e),C(e)}#d(e=[]){return P(this.surface,e)}#f(e,s){let r=this.values?.get?.(e);return r.value=s,this.surface}#l(e,...s){let r=this.actions.has(e)?this.actions.get(e):this.surface[e];return typeof r=="function"?r(...s):this.surfaceComputed()}#h(e={}){let s=Object.keys(this.surface);for(;s.length>0;){let n=s.shift();n in this.surface&&delete this.surface[n]}for(let[n,c]of t.plugins)Object.defineProperty(this.surface,n,{value:c});for(let n of this.extensions){let c=Object.getOwnPropertyDescriptors(n),o=Object.fromEntries(Object.entries(c).filter(([a])=>!a.startsWith("$")));Object.defineProperties(this.surface,o)}let r=Object.entries(e);for(let[n,c]of r){if(this.values.has(c)){Object.defineProperty(this.surface,n,{get:()=>c.value,set:o=>c.value=o});continue}if(this.computeds.has(c)){Object.defineProperty(this.surface,n,{get:()=>c.value});continue}if(this.actions.has(c)){Object.defineProperty(this.surface,n,{value:c});continue}this.surface[n]=c}return this.surface}},Q=(...t)=>f.create(...t),W=t=>{if(j(t)){let e=f.surfaces.get(t);e&&e.setup()}},B=(...t)=>f.createPlugin(...t),j=t=>f.surfaces.has(t);export{i as Reactive,V as addContext,p as addEffect,T as createAdapter,w as createComputed,S as createSignal,F as createSubscriber,B as definePlugin,Q as defineSurface,C as destroyComputed,M as destroySignal,N as destroySubscriber,R as hasContext,A as isComputed,$ as isDirtyComputed,z as isDirtySignal,h as isReactive,O as isSignal,I as isSubscriber,j as isSurface,W as refreshSurface,v as removeEffect,k as useContext};
|
|
1
|
+
function E(t){return typeof window<"u"&&window.requestIdleCallback?window.requestIdleCallback(t,{timeout:100}):typeof window<"u"?window.requestAnimationFrame?window.requestAnimationFrame(()=>{setTimeout(t,0)}):setTimeout(t,0):(typeof t=="function"&&t(),null)}var l=class{constructor(){this.roots=new Map,this.pending=new Set,this.onCompleteCallbacks=new Set,this.onNextIdle=new Set,this.idleScheduled=!1}markAsDirty(e){if(!e.isDirty&&(e.isDirty=!0,e.isAsync||e.immediate||e.effects&&e.effects.size>0?this.scheduleRecomputation(e):(this.onNextIdle.add(e),this.idleScheduled||(this.idleScheduled=!0,E(()=>{for(let s of this.onNextIdle)this.pending.add(s);this.flush(null),this.onNextIdle.clear(),this.idleScheduled=!1}))),e.dependants&&e.dependants.size>0)){let s=[],n=new Set;e.dependants.forEach(r=>{let c=r.deref();c?(this.markAsDirty(c),n.add(c._id)):s.push(r)}),s.forEach(r=>e.dependants.delete(r)),e.dependantIds=n}}scheduleRecomputation(e){if(!e.debounce)return this.recompute(e);let s=Date.now(),n=e._lastComputeTime?s-e._lastComputeTime:1/0;return!e._hasPendingDebounce||n>=e.debounce?(clearTimeout(e._debounceTimer),e._hasPendingDebounce=!0,e._lastComputeTime=s,e._debounceTimer=setTimeout(()=>{e._hasPendingDebounce=!1,e._debounceTimer=null},e.debounce),this.recompute(e)):e.cachedValue}removeReactive(e){this.pending.delete(e),this.onNextIdle.delete(e)}recompute(e){return this.pending.add(e),this.flush(e)}flush(e){let s=Array.from(this.pending);this.pending.clear();let n=this.sortByDependencies(s);for(let r of n)this.onNextIdle.delete(r),r.compute();for(let r of this.onCompleteCallbacks)try{r()}catch(c){console.error("Error in batch completion callback:",c)}if(e)return n.includes(e)||e.compute(),e.cachedValue}sortByDependencies(e){let s=[],n=new Set,r=new Set,c=o=>{if(r.has(o)||n.has(o))return;r.add(o);let a=o.dependants;a&&a.size>0&&a.forEach(u=>{let g=u.deref();g&&e.includes(g)&&c(g)}),r.delete(o),n.add(o),s.unshift(o)};for(let o of e)n.has(o)||c(o);return s}};var i=class t{static computationManager=new l;static awaitingRecomputation=new Set;static reactives=new WeakMap;static currentlyComputing=null;static computationStack=[];static currentDepth=0;static effectsCache=new Set;static processingEffects=!1;static _nextId=1;static config={maxDepth:2e3};static ctx={};static nextId(){return t._nextId++}static addContext(e,s){if(!e||typeof e!="string")throw new Error("Invalid context key");if(typeof s>"u")throw new Error("Invalid context value");if(e in t.ctx)throw new Error("Context key already exists");t.ctx[e]=s}static useContext(e){if(!e||e.length===0)return t.ctx;if(e.length===1)return t.ctx[e[0]];let s=new Array(e.length);for(let n=0;n<e.length;n++)s[n]=t.ctx[e[n]];return s}static hasContext(e){if(!e||e.length===0)return Object.keys(t.ctx).length>0;if(e.length===1)return e[0]in t.ctx;for(let s of e)if(!(s in t.ctx))return!1;return!0}static clearContext(){t.ctx={}}static begin(e){t.awaitingRecomputation.has(e)&&t.awaitingRecomputation.delete(e);let s=t.computationStack.indexOf(e);if(s!==-1){if(e.isAsync){t.computationStack.splice(s,1),t.computationStack.push(e),t.currentlyComputing=e;return}let n=t.computationStack.slice(s).concat(e),r=new Error(`Circular dependency detected: ${n.map(c=>c).join(" -> ")}`);throw r.name="CircularDependencyError",r.displayed=!1,r}if(t.currentDepth>=t.config.maxDepth)throw new Error(`Maximum reactive depth of ${t.config.maxDepth} exceeded`);t.computationStack.push(e),t.currentlyComputing=e,t.currentDepth++}static end(e){if(e.isAsync){t.computationStack.splice(t.computationStack.indexOf(e),1),t.currentlyComputing=t.computationStack[t.computationStack.length-1]||null,t.currentDepth--;return}t.computationStack.pop(),t.currentlyComputing=t.computationStack[t.computationStack.length-1]||null,t.currentDepth--}static addEffect(e,s){let n=t.reactives.get(e);return n.isDirty&&t.computationManager.scheduleRecomputation(n),n.effects||(n.effects=new Set),n.effects.add(s),()=>t.removeEffect(e,s)}static removeEffect(e,s){let n=t.reactives.get(e);n.effects&&n.effects.delete(s)}static recompute(e){return t.awaitingRecomputation.has(e)||t.awaitingRecomputation.add(e),t.computationManager.scheduleRecomputation(e)}static callEffects(e){t.effectsCache.add(e),t.processingEffects||(t.processingEffects=!0,setTimeout(()=>{t.processEffectsCache(),t.processingEffects=!1},0))}static processEffectsCache(){let e=new Set(t.effectsCache);t.effectsCache.clear();for(let s of e)try{(s.effects||new Set).forEach(r=>{r&&r(s.cachedValue)})}catch(n){console.error(`Error in reactive ${s._id} effect:`,n)}t.effectsCache.size>0&&setTimeout(()=>{t.processEffectsCache()},0)}static markAsDirty(e){if(!e.isDirty){e.isDirty=!0,(e.immediate||e.effects&&e.effects.size>0)&&t.computationManager.scheduleRecomputation(e);let s=[],n=new Set;e.dependants.forEach(r=>{let c=r.deref();c?(t.markAsDirty(c),n.add(c._id)):s.push(r)}),s.forEach(r=>e.dependants.delete(r)),e.dependantIds=n}}static destroy(e){let s=t.reactives.get(e);t.computationManager.removeReactive(s),t.reactives.delete(e)}};var h=t=>i.reactives.has(t),p=(t,e)=>{if(!h(t))throw new Error("Invalid effect getter");if(!e||typeof e!="function")throw new Error("Invalid effect function");return i.addEffect(t,e)},v=(t,e)=>{if(h(t))return i.removeEffect(t,e)};var V=(t,e)=>i.addContext(t,e),k=(...t)=>t.length===0?i.ctx:t.length===1?i.ctx[t[0]]:t.map(e=>i.ctx[e]),R=(...t)=>i.hasContext(t),T=(t,e=[])=>{if(!h(t))throw new Error("Invalid adapter getter");let s,n=null,r=new Set,c=()=>{if(s!==void 0)return s;let a=e&&e.length>0?traverse(t(),e):t();if(Array.isArray(a))s=a.slice();else if(typeof a=="object"&&a!==null){let u=Object.create(Object.getPrototypeOf(a));Object.defineProperties(u,Object.getOwnPropertyDescriptors(a)),s=Object.freeze(u)}else s=a;return s};return[c,a=>(n||(n=p(t,()=>{s=void 0;for(let u of r)u(c)})),r.add(a),()=>{r.delete(a),r.size===0&&(n(),n=null)})]};var D=t=>typeof t=="function"&&(t.constructor.name==="AsyncFunction"||t.constructor.name==="AsyncGeneratorFunction");var m=class t{static create(e,s={}){let n=new t(e,s);return i.reactives.set(n.getter,n),n.getter}constructor(e,s={}){if(s.context&&typeof s.context!="function")throw new Error("Computed context must be a function");this.fn=e,this.isAsync=D(e),this.pendingResolve=void 0,this.roots=new Set,this.dependants=new Set,this.dependantIds=new Set,this.effects=new Set(Array.isArray(s.effects)?s.effects:[]),this.cachedValue=s.initialValue||void 0,this.isDirty=!0,this.debounce=s.debounce||0,this.onAccess=s.onAccess||void 0,this.detatched=s.detatched||!1,this.immediate=s.immediate||!1,this.useContext=s.context||(i.hasContext()?()=>i.useContext():()=>{}),this.resolvers=[],this.rejectors=[],this._id=i.nextId(),this._lastComputeTime=void 0,this._hasPendingDebounce=!1,this._debounceTimer=void 0,this._computationId=0,this.getter=this.#e.bind(this),this.immediate&&this.compute()}compute(){i.begin(this);try{if(!this.isAsync){let n=this.useContext?this.useContext():void 0;return this.cachedValue=this.fn(n,this.cachedValue),this.isDirty=!1,this.cachedValue}this._computationId=(this._computationId||0)+1;let e=this._computationId,s=this.useContext?this.useContext():void 0;return this.pendingResolve=this.fn(s,this.cachedValue),this.pendingResolve.then(n=>(this._computationId===e&&(this.resolvers.forEach(r=>r(n)),this.resolvers=[],this.cachedValue=n,this.isDirty=!1),n)).catch(n=>{this._computationId===e&&(this.rejectors.forEach(r=>r(n)),this.rejectors=[])}).finally(()=>{this.pendingResolve=null,this._computationId===e&&(i.end(this),i.callEffects(this))}),this.cachedValue=new Promise((n,r)=>{this.resolvers.push(n),this.rejectors.push(r)}),this.cachedValue}finally{this.isAsync||(i.end(this),i.callEffects(this))}}#e(){try{return!this.detatched&&i.currentlyComputing&&i.currentlyComputing!==this&&!this.dependantIds.has(i.currentlyComputing._id)&&(this.dependantIds.add(i.currentlyComputing._id),this.dependants.add(new WeakRef(i.currentlyComputing))),this.isDirty?i.recompute(this):this.isAsync?Promise.resolve(this.cachedValue):this.cachedValue}catch(e){throw e}finally{this.onAccess&&this.onAccess(this.cachedValue)}}},w=(t,e={})=>m.create(t,e),C=t=>{A(t)&&i.destroy(t)},A=t=>{let e=i.reactives.get(t);return e?e instanceof m:!1},$=t=>{let e=i.reactives.get(t);return e?e.isDirty:!1};var b=class t{static create(e,s={}){let n=new t(e,s);return i.reactives.set(n.getter,n),n.getter}constructor(e,s={}){this._id=i.nextId(),this.isAsync=!1,this.cachedValue=void 0,this.dependants=new Set,this.dependantIds=new Set,this.roots=new Set,this.effects=new Set(Array.isArray(s.effects)?s.effects:[]),this.isDirty=!0,this.debounce=s.debounce||0,this.onAccess=s.onAccess||null,this.detatched=s.detatched||!1,this.immediate=s.immediate||!1,this._pendingChange=e,this._lastComputeTime=null,this._hasPendingDebounce=!1,this._debounceTimer=null,this.getter=(...n)=>this.#e(...n)}compute(){i.begin(this);try{return this.cachedValue=this._pendingChange,this._pendingChange=void 0,this.isDirty=!1,this.cachedValue}finally{i.end(this),i.callEffects(this)}}#e(...e){try{if(!this.detatched&&i.currentlyComputing&&i.currentlyComputing!==this&&!this.dependantIds.has(i.currentlyComputing._id)&&(this.dependantIds.add(i.currentlyComputing._id),this.dependants.add(new WeakRef(i.currentlyComputing))),e.length>0){let s=e[0];this._pendingChange=typeof s=="function"?s(this.cachedValue):s,i.markAsDirty(this);return}return this.isDirty?i.recompute(this):this.cachedValue}catch(s){throw s}finally{this.onAccess&&this.onAccess(this.cachedValue)}}},S=(t,e={})=>b.create(t,e),M=t=>{O(t)&&i.destroy(t)},O=t=>{let e=i.reactives.get(t);return e?e instanceof b:!1},z=t=>{let e=i.reactives.get(t);return e?e.isDirty:!1};var y=class t{static create(e,s,n={}){let r=new t(e,s,n);return i.reactives.set(r.getter,r),()=>i.destroy(r.getter)}constructor(e,s,n={}){this._id=i.nextId(),this.getter=e,this.isDirty=!1,this.subscriber=s,this.debounce=n.debounce||0,this.onAccess=n.onAccess||null,this.immediate=!0,this._hasPendingDebounce=!1,this._lastComputeTime=null,this._debounceTimer=null,this.dependants=new Set,this.dependantIds=new Set,this.unsubscribe=()=>i.computationManager.removeReactive(this),i.begin(this),this.cachedValue=this.getter(),this.subscriber(this.cachedValue),i.end(this)}compute(){try{this.cachedValue=this.getter(),this.subscriber(this.cachedValue),this.isDirty=!1}catch(e){throw e}}},F=(t,e,s={})=>y.create(t,e,s),N=t=>{I(t)&&i.destroy(t)},I=t=>{let e=i.reactives.get(t);return e?e instanceof y:!1};var d=[null,null,(t,e)=>t?.[e[0]]?.[e[1]],(t,e)=>t?.[e[0]]?.[e[1]]?.[e[2]],(t,e)=>t?.[e[0]]?.[e[1]]?.[e[2]]?.[e[3]],(t,e)=>t?.[e[0]]?.[e[1]]?.[e[2]]?.[e[3]]?.[e[4]],(t,e)=>t?.[e[0]]?.[e[1]]?.[e[2]]?.[e[3]]?.[e[4]]?.[e[5]],(t,e)=>t?.[e[0]]?.[e[1]]?.[e[2]]?.[e[3]]?.[e[4]]?.[e[5]]?.[e[6]],(t,e)=>t?.[e[0]]?.[e[1]]?.[e[2]]?.[e[3]]?.[e[4]]?.[e[5]]?.[e[6]]?.[e[7]]];function q(t){let s="obj"+Array.from({length:t},(r,c)=>`?.[path[${c}]]`).join(""),n=new Function("obj","path",`return ${s}`);return d[t]=n,n}function P(t,e){let s=e.length;return s===0?t:s===1?t[e[0]]:s<d.length&&d[s]||d[s]?d[s](t,e):q(s)(t,e)}var x=Symbol(),f=class t{static surfaces=new WeakMap;static plugins=new Map;static registerPlugin(e,s){if(t.plugins.has(e))throw new Error(`Plugin "${e}" already registered`);t.plugins.set(e,s())}static resetPlugins(){t.plugins.clear()}static create(e,s={}){let n=new t(s),r=n.setup(e);return t.surfaces.set(r,n),r}static createPlugin(e,s,n={}){let r=t.create(s,n);return t.registerPlugin(e,r),r}constructor(e={}){this.options=e,this.setupFn=null,this.subscribers=new Set,this.subscribersQueued=!1,this.destroyCallback=null,this.values=new Set,this.computeds=new Set,this.actions=new Set,this.extensions=new Set,this.snapshotCache=x,this.surface=this.#r(),this.useSurface=()=>this.surface}setup(e){if(!e)return null;this.setupFn=e,this.reset();let s=new Set;try{let n;if(typeof e=="function")n=this.#e(e,s);else if(typeof e=="object"&&e!==null)n=this.#o(e,s);else throw new Error("setupFn must be a function or object configuration");return this.#h(n),s.forEach(r=>p(r,()=>this.#n())),this.#n(),this.useSurface}catch(n){throw console.error("Error in setup function",n),n}}reset(){this.subscribers.clear(),this.subscribersQueued=!1,this.values.clear(),this.computeds.clear(),this.actions.clear(),this.extensions.clear(),this.snapshotCache=x,this.surface=this.#r()}createValue(e=void 0,s){let n=S(e),r=Object.create(null);return Object.defineProperty(r,"value",{get:()=>n(),set:c=>n(c),enumerable:!0}),this.values.add(r),s?.(n),r}createComputed(e,s){let n=w(e,{context:()=>this.surface}),r=Object.create(null);return Object.defineProperty(r,"value",{get:()=>n(),enumerable:!0}),this.computeds.add(r),s?.(n),r}createAction(e){let s=e.bind(this.surface,this.surface);return this.actions.add(s),s}extend(e){if(!e)throw new Error("No source surface provided");if(!j(e))throw new Error("Cannot extend non-surface");let s=e();return this.extensions.add(s),s}#e(e,s){return e({value:(n=void 0)=>this.createValue(n,r=>s.add(r)),computed:(n=()=>{})=>this.createComputed(n,r=>s.add(r)),action:(n=()=>{})=>this.createAction(n),extend:n=>this.extend(n),destroy:()=>this.#i(),...Object.fromEntries(t.plugins.entries())})||{}}#c(e,s,n){if(typeof e!="object"||e===null)return typeof e=="function"?e():e;if(!("default"in e))return s&&"dummy"in e&&console.warn(`State "${n}" has dummy value but no default value`),typeof e=="function"?e():e;let r=s&&"dummy"in e?e.dummy:e.default;return typeof r=="function"?r():r}#o(e,s){let n={},r=this.options.mode==="development"||this.options.mode==="dev";if(e.extend&&Array.isArray(e.extend))for(let c of e.extend)this.extend(c);if(e.state&&typeof e.state=="object")for(let[c,o]of Object.entries(e.state)){let a=this.#c(o,r,c);n[c]=this.createValue(a,u=>s.add(u))}if(e.computed&&typeof e.computed=="object")for(let[c,o]of Object.entries(e.computed))typeof o=="function"&&(n[c]=this.createComputed(o,a=>s.add(a)));if(e.actions&&typeof e.actions=="object")for(let[c,o]of Object.entries(e.actions))typeof o=="function"&&(n[c]=this.createAction(o));return e.onInit&&typeof e.onInit=="function"&&Promise.resolve().then(()=>{try{e.onInit(this.surface)}catch(c){console.error("Error in onInit callback",c)}}),e.onDestroy&&typeof e.onDestroy=="function"&&(this.destroyCallback=e.onDestroy),n}#a(){return[()=>this.#t(),e=>this.#s(e)]}#t(){if(this.snapshotCache!==x)return this.snapshotCache;let e=Object.create(Object.getPrototypeOf(this.surface));return Object.defineProperties(e,Object.getOwnPropertyDescriptors(this.surface)),this.snapshotCache=Object.freeze(e),this.snapshotCache}#s(e){return this.subscribers.add(e),()=>this.subscribers.delete(e)}#u(e){for(let s of this.subscribers)s(e)}#n(){this.subscribers.size===0||this.subscribersQueued||(this.subscribersQueued=!0,Promise.resolve().then(()=>{this.subscribersQueued=!1,this.snapshotCache=x,this.#u(this.#t())}))}#r(e=Object.create(null)){return Object.defineProperty(e,"$get",{value:s=>this.#d(s),writable:!1,enumerable:!1,configurable:!1}),Object.defineProperty(e,"$set",{value:(s,n)=>this.#f(s,n),writable:!1,enumerable:!1,configurable:!1}),Object.defineProperty(e,"$dispatch",{value:s=>this.#l(s),writable:!1,enumerable:!1,configurable:!1}),Object.defineProperty(e,"$inject",{value:s=>Object.assign({},this.surface,s),writable:!1,enumerable:!1,configurable:!1}),Object.defineProperty(e,"$snapshot",{value:()=>this.#t(),writable:!1,enumerable:!1,configurable:!1}),Object.defineProperty(e,"$subscribe",{value:s=>this.#s(s),writable:!1,enumerable:!1,configurable:!1}),Object.defineProperty(e,"$adapter",{value:()=>this.#a(),writable:!1,enumerable:!1,configurable:!1}),Object.defineProperty(e,"$destroy",{value:()=>this.#i(),writable:!1,enumerable:!1,configurable:!1}),e}#i(){if(this.destroyCallback&&typeof this.destroyCallback=="function")try{this.destroyCallback(this.surface)}catch(s){console.error("Error in onDestroy callback",s)}let e=this.surfaceComputed;this.surfaceComputed=null,t.surfaces.delete(e),C(e)}#d(e=[]){return P(this.surface,e)}#f(e,s){let n=this.values?.get?.(e);return n.value=s,this.surface}#l(e,...s){let n=this.actions.has(e)?this.actions.get(e):this.surface[e];return typeof n=="function"?n(...s):this.surfaceComputed()}#h(e={}){let s=Object.keys(this.surface);for(;s.length>0;){let r=s.shift();r in this.surface&&delete this.surface[r]}for(let[r,c]of t.plugins)Object.defineProperty(this.surface,r,{value:c});for(let r of this.extensions){let c=Object.getOwnPropertyDescriptors(r),o=Object.fromEntries(Object.entries(c).filter(([a])=>!a.startsWith("$")));Object.defineProperties(this.surface,o)}let n=Object.entries(e);for(let[r,c]of n){if(this.values.has(c)){Object.defineProperty(this.surface,r,{get:()=>c.value,set:o=>c.value=o});continue}if(this.computeds.has(c)){Object.defineProperty(this.surface,r,{get:()=>c.value});continue}if(this.actions.has(c)){Object.defineProperty(this.surface,r,{value:c});continue}this.surface[r]=c}return this.surface}},Q=(...t)=>f.create(...t),W=t=>{if(j(t)){let e=f.surfaces.get(t);e&&e.setup()}},B=(...t)=>f.createPlugin(...t),j=t=>f.surfaces.has(t);export{i as Reactive,V as addContext,p as addEffect,T as createAdapter,w as createComputed,S as createSignal,F as createSubscriber,B as definePlugin,Q as defineSurface,C as destroyComputed,M as destroySignal,N as destroySubscriber,R as hasContext,A as isComputed,$ as isDirtyComputed,z as isDirtySignal,h as isReactive,O as isSignal,I as isSubscriber,j as isSurface,W as refreshSurface,v as removeEffect,k as useContext};
|
|
2
2
|
//# sourceMappingURL=main.js.map
|
package/dist/main.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/utils/nextIdleTick.js", "../src/ComputationManager.js", "../src/Reactive.js", "../src/utils/isAsync.js", "../src/Computed.js", "../src/Signal.js", "../src/Subscriber.js", "../src/lib/traverse.js", "../src/Surface.js"],
|
|
4
|
-
"sourcesContent": ["export function nextIdleTick(callback) {\n if (typeof window !== 'undefined' && window.requestIdleCallback) {\n return window.requestIdleCallback(callback, { timeout: 100 });\n }\n\n // Fallback for browsers without requestIdleCallback (Safari/WebKit)\n if (typeof window !== 'undefined') {\n // Use requestAnimationFrame + setTimeout for better idle approximation\n if (window.requestAnimationFrame) {\n return window.requestAnimationFrame(() => {\n setTimeout(callback, 0);\n });\n }\n // Final fallback to setTimeout\n return setTimeout(callback, 0);\n }\n\n // Server-side or no window object - execute immediately\n if (typeof callback === 'function') {\n callback();\n }\n return null;\n}\n", "import { nextIdleTick } from './utils/nextIdleTick.js';\n\nexport class ComputationManager {\n constructor() {\n this.roots = new Map();\n this.pending = new Set();\n this.onCompleteCallbacks = new Set();\n this.onNextIdle = new Set();\n this.idleScheduled = false;\n }\n\n markAsDirty(reactive) {\n if (!reactive.isDirty) {\n reactive.isDirty = true;\n \n if (reactive.isAsync || reactive.immediate || (reactive.effects && reactive.effects.size > 0)) {\n this.scheduleRecomputation(reactive);\n } else {\n this.onNextIdle.add(reactive);\n\n if (!this.idleScheduled) {\n this.idleScheduled = true;\n nextIdleTick(() => {\n for (const reactive of this.onNextIdle) {\n this.pending.add(reactive);\n }\n this.flush(null);\n this.onNextIdle.clear();\n this.idleScheduled = false; // \u2190 Reset flag\n });\n }\n }\n if (reactive.dependants && reactive.dependants.size > 0) {\n // Process WeakRefs and rebuild ID set with only alive IDs\n const deadRefs = [];\n const ids = new Set();\n reactive.dependants.forEach(weakRef => {\n const dependant = weakRef.deref();\n if (dependant) {\n this.markAsDirty(dependant);\n ids.add(dependant._id);\n } else {\n deadRefs.push(weakRef);\n }\n });\n // Clean up dead WeakRefs and sync IDs\n deadRefs.forEach(ref => reactive.dependants.delete(ref));\n reactive.dependantIds = ids;\n }\n }\n }\n\n scheduleRecomputation(reactive) {\n if (!reactive.debounce) {\n return this.recompute(reactive);\n }\n\n // Check if we can recompute (either first time or cooldown expired)\n const now = Date.now();\n const timeElapsed = reactive._lastComputeTime ? now - reactive._lastComputeTime : Infinity;\n const canRecompute = !reactive._hasPendingDebounce || timeElapsed >= reactive.debounce;\n\n if (canRecompute) {\n // Clear any existing timer and set up new cooldown period\n clearTimeout(reactive._debounceTimer);\n reactive._hasPendingDebounce = true;\n reactive._lastComputeTime = now;\n \n reactive._debounceTimer = setTimeout(() => {\n reactive._hasPendingDebounce = false;\n reactive._debounceTimer = null;\n }, reactive.debounce);\n \n return this.recompute(reactive);\n }\n\n // Still in cooldown period, return cached value\n return reactive.cachedValue;\n }\n\n removeReactive(reactive) {\n this.pending.delete(reactive);\n this.onNextIdle.delete(reactive);\n }\n\n recompute(reactive) {\n this.pending.add(reactive);\n return this.flush(reactive);\n }\n\n flush(reactive) {\n const reactives = Array.from(this.pending);\n this.pending.clear();\n\n // Sort by dependencies\n const sortedReactives = this.sortByDependencies(reactives);\n \n // Process in reverse order (dependencies first)\n for (const reactive of sortedReactives) {\n this.onNextIdle.delete(reactive);\n reactive.compute()\n }\n\n // Notify completion callbacks\n for (const callback of this.onCompleteCallbacks) {\n try {\n callback();\n } catch (error) {\n console.error('Error in batch completion callback:', error);\n }\n }\n\n // If we have a target ID, ensure it's computed and return its value\n if (reactive) {\n // Make sure the target computed is evaluated if it wasn't in the batch\n if (!sortedReactives.includes(reactive)) {\n reactive.compute();\n }\n return reactive.cachedValue;\n }\n \n return undefined;\n }\n\n sortByDependencies(reactives) {\n const sorted = [];\n const visited = new Set();\n const visiting = new Set();\n\n const visit = (reactive) => {\n if (visiting.has(reactive)) return;\n if (visited.has(reactive)) return;\n\n visiting.add(reactive);\n\n // Get dependant computed values (handle WeakRefs)\n const dependants = reactive.dependants;\n if (dependants && dependants.size > 0) {\n dependants.forEach(weakRef => {\n const dependant = weakRef.deref();\n if (dependant && reactives.includes(dependant)) {\n visit(dependant); // Visit dependants first\n }\n });\n }\n\n visiting.delete(reactive);\n visited.add(reactive);\n sorted.unshift(reactive); // Add to start of array instead of end\n };\n\n // Process all nodes\n for (const reactive of reactives) {\n if (!visited.has(reactive)) {\n visit(reactive);\n }\n }\n\n return sorted;\n }\n}", "import { ComputationManager } from './ComputationManager.js';\n\nexport class Reactive {\n static computationManager = new ComputationManager();\n static awaitingRecomputation = new Set();\n static reactives = new WeakMap();\n static currentlyComputing = null;\n static computationStack = [];\n static currentDepth = 0;\n static effectsCache = new Set();\n static processingEffects = false;\n static _nextId = 1; // Counter for unique reactive IDs\n static config = {\n maxDepth: 2000,\n }\n static ctx = {};\n \n static nextId() {\n return Reactive._nextId++;\n }\n\n static addContext(key, value) {\n if (!key || typeof key !== 'string') {\n throw new Error('Invalid context key');\n }\n \n if (typeof value === 'undefined') {\n throw new Error('Invalid context value');\n }\n \n if (key in Reactive.ctx) {\n throw new Error('Context key already exists');\n }\n \n Reactive.ctx[key] = value;\n }\n\n static useContext(keys) { \n if (!keys || keys.length === 0) return Reactive.ctx;\n if (keys.length === 1) return Reactive.ctx[keys[0]];\n\n const out = new Array(keys.length);\n for (let i = 0; i < keys.length; i++) {\n out[i] = Reactive.ctx[keys[i]];\n }\n return out;\n }\n\n static hasContext(keys) {\n if (!keys || keys.length === 0) return Object.keys(Reactive.ctx).length > 0;\n if (keys.length === 1) return keys[0] in Reactive.ctx;\n for (const key of keys) {\n if (!(key in Reactive.ctx)) return false;\n }\n return true;\n }\n\n static clearContext() {\n Reactive.ctx = {};\n }\n\n static begin(reactive) {\n if (Reactive.awaitingRecomputation.has(reactive)) {\n Reactive.awaitingRecomputation.delete(reactive);\n }\n\n const reactorIndex = Reactive.computationStack.indexOf(reactive);\n\n if (reactorIndex !== -1) {\n if (reactive.isAsync) {\n Reactive.computationStack.splice(reactorIndex, 1);\n Reactive.computationStack.push(reactive);\n Reactive.currentlyComputing = reactive;\n return;\n } \n const cycle = Reactive.computationStack.slice(reactorIndex).concat(reactive);\n const error = new Error(`Circular dependency detected: ${cycle.map(r => r).join(' -> ')}`);\n error.name = 'CircularDependencyError';\n error.displayed = false;\n throw error;\n }\n \n if (Reactive.currentDepth >= Reactive.config.maxDepth) {\n throw new Error(`Maximum reactive depth of ${Reactive.config.maxDepth} exceeded`);\n }\n \n Reactive.computationStack.push(reactive);\n Reactive.currentlyComputing = reactive;\n Reactive.currentDepth++;\n }\n \n static end(reactive) {\n if (reactive.isAsync) {\n Reactive.computationStack.splice(Reactive.computationStack.indexOf(reactive), 1);\n Reactive.currentlyComputing = Reactive.computationStack[Reactive.computationStack.length - 1] || null;\n Reactive.currentDepth--;\n return;\n }\n Reactive.computationStack.pop();\n Reactive.currentlyComputing = Reactive.computationStack[Reactive.computationStack.length - 1] || null;\n Reactive.currentDepth--;\n }\n\n static addEffect(getter, effect) {\n const reactive = Reactive.reactives.get(getter);\n \n // Compute if needed and notify with current value\n if (reactive.isDirty) {\n Reactive.computationManager.scheduleRecomputation(reactive);\n }\n \n if (!reactive.effects) {\n reactive.effects = new Set();\n }\n \n // Store the WeakRef instead of the raw effect\n reactive.effects.add(effect);\n \n // Return unsubscribe function\n return () => Reactive.removeEffect(getter, effect);\n }\n\n static removeEffect(getter, effect) {\n const reactive = Reactive.reactives.get(getter);\n if (reactive.effects) {\n reactive.effects.delete(effect);\n }\n }\n\n static recompute(reactive) {\n if (!Reactive.awaitingRecomputation.has(reactive)) {\n Reactive.awaitingRecomputation.add(reactive);\n }\n\n \n return Reactive.computationManager.scheduleRecomputation(reactive);\n }\n\n static callEffects(reactive) { \n Reactive.effectsCache.add(reactive);\n \n // Use a single setTimeout for batching\n if (!Reactive.processingEffects) {\n Reactive.processingEffects = true;\n setTimeout(() => {\n Reactive.processEffectsCache();\n Reactive.processingEffects = false;\n }, 0);\n }\n }\n\n static processEffectsCache() {\n const reactives = new Set(Reactive.effectsCache);\n Reactive.effectsCache.clear();\n \n for (const reactive of reactives) {\n try {\n // Process effects using WeakRefs\n const effects = reactive.effects || new Set();\n effects.forEach(effect => {\n if (effect) {\n effect(reactive.cachedValue);\n }\n });\n } catch (error) {\n console.error(`Error in reactive ${reactive._id} effect:`, error);\n }\n }\n \n // If new effects were added during processing, schedule another batch\n if (Reactive.effectsCache.size > 0) {\n setTimeout(() => {\n Reactive.processEffectsCache();\n }, 0);\n }\n }\n\n static markAsDirty(reactive) {\n if (!reactive.isDirty) {\n reactive.isDirty = true;\n \n if (reactive.immediate || (reactive.effects && reactive.effects.size > 0)) {\n Reactive.computationManager.scheduleRecomputation(reactive);\n }\n \n // Process WeakRefs and clean up dead ones\n const deadRefs = [];\n const ids = new Set();\n reactive.dependants.forEach(weakRef => {\n const dependant = weakRef.deref();\n if (dependant) {\n Reactive.markAsDirty(dependant);\n ids.add(dependant._id);\n } else {\n deadRefs.push(weakRef);\n }\n });\n // Clean up dead WeakRefs and sync IDs\n deadRefs.forEach(ref => reactive.dependants.delete(ref));\n reactive.dependantIds = ids;\n }\n }\n\n static destroy(getter) {\n const reactive = Reactive.reactives.get(getter);\n Reactive.computationManager.removeReactive(reactive);\n Reactive.reactives.delete(getter);\n }\n}\n\nexport const markAsDirty = (reactive) => {\n if (isReactive(reactive)) {\n const reactiveInstance = Reactive.reactives.get(reactive);\n if (reactiveInstance) {\n return Reactive.markAsDirty(reactiveInstance);\n }\n }\n}\n\nexport const isReactive = (getter) => {\n return Reactive.reactives.has(getter);\n}\n\nexport const addEffect = (getter, effect) => {\n if (!isReactive(getter)) {\n throw new Error('Invalid effect getter');\n \n }\n\n if (!effect || typeof effect !== 'function') {\n throw new Error('Invalid effect function');\n }\n\n return Reactive.addEffect(getter, effect);\n}\n\nexport const removeEffect = (getter, effect) => {\n if (isReactive(getter)) {\n return Reactive.removeEffect(getter, effect);\n }\n}\n\nexport const destroyReactive = (getter) => {\n if (isReactive(getter)) {\n return Reactive.destroy(getter);\n }\n}\n\nexport const addContext = (key, value) => Reactive.addContext(key, value)\n\nexport const useContext = (...keys) => {\n if (keys.length === 0) return Reactive.ctx;\n if (keys.length === 1) return Reactive.ctx[keys[0]];\n return keys.map(key => Reactive.ctx[key]);\n}\n\nexport const hasContext = (...keys) => Reactive.hasContext(keys)\n\nexport const createAdapter = (getter, path = []) => {\n if (!isReactive(getter)) {\n throw new Error('Invalid adapter getter');\n }\n\n let snapshotCache = undefined;\n let unsubscribeAll = null;\n const subscribers = new Set();\n\n const getSnapshot = () => {\n if (snapshotCache !== undefined) {\n return snapshotCache;\n }\n\n const value = path && path.length > 0 ? traverse(getter(), path) : getter();\n\n if (Array.isArray(value)) {\n snapshotCache = value.slice();\n } else if (typeof value === 'object' && value !== null) {\n const clone = Object.create(Object.getPrototypeOf(value));\n Object.defineProperties(clone, Object.getOwnPropertyDescriptors(value));\n snapshotCache = Object.freeze(clone);\n } else {\n snapshotCache = value;\n }\n \n return snapshotCache;\n };\n\n const subscribe = (listener) => {\n if (!unsubscribeAll) {\n unsubscribeAll = addEffect(getter, () => {\n snapshotCache = undefined;\n for (const subscriber of subscribers) {\n subscriber(getSnapshot);\n }\n });\n }\n \n subscribers.add(listener);\n return () => {\n subscribers.delete(listener);\n if (subscribers.size === 0) {\n unsubscribeAll();\n unsubscribeAll = null;\n }\n };\n };\n\n return [getSnapshot, subscribe];\n}", "export const isAsyncFunction = fn =>\n typeof fn === 'function' &&\n (fn.constructor.name === 'AsyncFunction' ||\n fn.constructor.name === 'AsyncGeneratorFunction');\n", "import { Reactive } from './Reactive.js';\nimport { isAsyncFunction } from './utils/isAsync.js';\n\nexport class Computed {\n static create(fn, config = {}) {\n const computed = new Computed(fn, config);\n Reactive.reactives.set(computed.getter, computed);\n return computed.getter;\n }\n\n constructor(fn, config = {}) {\n this.fn = fn;\n this.isAsync = isAsyncFunction(fn);\n this.pendingResolve = undefined;\n this.roots = new Set();\n this.dependants = new Set();\n this.dependantIds = new Set();\n this.effects = new Set(Array.isArray(config.effects) ? config.effects : []);\n this.cachedValue = config.initialValue || undefined;\n this.isDirty = true;\n this.debounce = config.debounce || 0;\n this.onAccess = config.onAccess || undefined;\n this.detatched = config.detatched || false;\n this.immediate = config.immediate || false;\n this.context = config.context || undefined;\n this.useContext = () => this.context ? this.context : Reactive.hasContext() ? Reactive.useContext() : undefined;\n this.resolvers = [];\n this.rejectors = [];\n this._id = Reactive.nextId();\n this._lastComputeTime = undefined;\n this._hasPendingDebounce = false;\n this._debounceTimer = undefined;\n this._computationId = 0; // Track computation version\n this.getter = this.#getter.bind(this);\n \n\n if (this.immediate) {\n this.compute();\n }\n }\n\n compute() {\n Reactive.begin(this);\n try { \n if (!this.isAsync) {\n this.cachedValue = this.fn(this.useContext(), this.cachedValue);\n this.isDirty = false;\n return this.cachedValue;\n }\n\n // Track this specific computation\n this._computationId = (this._computationId || 0) + 1;\n const computationId = this._computationId;\n\n this.pendingResolve = this.fn(this.useContext(), this.cachedValue);\n this.pendingResolve.then(value => {\n // Only update if this is still the latest computation\n if (this._computationId === computationId) {\n this.resolvers.forEach(resolve => resolve(value));\n this.resolvers = [];\n this.cachedValue = value;\n this.isDirty = false;\n }\n return value;\n }).catch(error => {\n if (this._computationId === computationId) {\n this.rejectors.forEach(reject => reject(error));\n this.rejectors = [];\n }\n }).finally(() => {\n this.pendingResolve = null; // Always clear pending promise\n // Only call end/effects if this is still the latest computation\n if (this._computationId === computationId) {\n Reactive.end(this);\n Reactive.callEffects(this);\n }\n });\n\n this.cachedValue = new Promise((resolve, reject) => {\n this.resolvers.push(resolve);\n this.rejectors.push(reject);\n });\n \n return this.cachedValue;\n } finally {\n if (!this.isAsync) {\n Reactive.end(this);\n Reactive.callEffects(this);\n }\n }\n }\n\n #getter() {\n try {\n if (!this.detatched && Reactive.currentlyComputing && Reactive.currentlyComputing !== this && !this.dependantIds.has(Reactive.currentlyComputing._id)) {\n this.dependantIds.add(Reactive.currentlyComputing._id);\n this.dependants.add(new WeakRef(Reactive.currentlyComputing));\n }\n \n if (!this.isDirty) {\n if (this.isAsync) {\n return Promise.resolve(this.cachedValue);\n }\n\n return this.cachedValue;\n }\n\n // If dirty, always start new computation (even if previous pending)\n return Reactive.recompute(this);\n } catch (error) {\n throw error;\n } finally {\n if (this.onAccess) {\n this.onAccess(this.cachedValue);\n }\n }\n }\n}\n\nexport const createComputed = (fn, config = {}) => Computed.create(fn, config);\n\nexport const destroyComputed = (target) => {\n if (isComputed(target)) {\n Reactive.destroy(target);\n }\n}\n\nexport const isComputed = (getter) => {\n const computed = Reactive.reactives.get(getter);\n if (!computed) {\n return false;\n }\n\n return computed instanceof Computed;\n}\n\nexport const isDirtyComputed = (getter) => {\n const computed = Reactive.reactives.get(getter);\n if (!computed) {\n return false;\n }\n\n return computed.isDirty;\n}\n", "import { Reactive } from './Reactive.js';\n\nexport class Signal {\n static create(initialValue, config = {}) {\n const signal = new Signal(initialValue, config);\n Reactive.reactives.set(signal.getter, signal);\n return signal.getter;\n }\n\n constructor(initialValue, config = {}) {\n this._id = Reactive.nextId();\n this.isAsync = false;\n this.cachedValue = undefined;\n this.dependants = new Set();\n this.dependantIds = new Set();\n this.roots = new Set();\n this.effects = new Set(Array.isArray(config.effects) ? config.effects : []);\n this.isDirty = true;\n this.debounce = config.debounce || 0;\n this.onAccess = config.onAccess || null;\n this.detatched = config.detatched || false;\n this.immediate = config.immediate || false;\n this._pendingChange = initialValue;\n this._lastComputeTime = null;\n this._hasPendingDebounce = false;\n this._debounceTimer = null;\n this.getter = (...args) => this.#getter(...args);\n }\n\n compute() {\n Reactive.begin(this);\n try {\n this.cachedValue = this._pendingChange;\n this._pendingChange = undefined;\n this.isDirty = false;\n return this.cachedValue;\n } finally {\n Reactive.end(this);\n Reactive.callEffects(this);\n }\n }\n\n #getter(...args) {\n try {\n if (!this.detatched && Reactive.currentlyComputing && Reactive.currentlyComputing !== this && !this.dependantIds.has(Reactive.currentlyComputing._id)) {\n this.dependantIds.add(Reactive.currentlyComputing._id);\n this.dependants.add(new WeakRef(Reactive.currentlyComputing));\n }\n\n if (args.length > 0) {\n const signal = args[0];\n this._pendingChange = typeof signal === 'function' ? signal(this.cachedValue) : signal;\n Reactive.markAsDirty(this);\n return;\n }\n\n if (this.isDirty) {\n return Reactive.recompute(this);\n }\n\n return this.cachedValue;\n \n } catch (error) {\n throw error;\n } finally {\n if (this.onAccess) {\n this.onAccess(this.cachedValue);\n }\n }\n }\n}\n\nexport const createSignal = (initialValue, config = {}) => Signal.create(initialValue, config);\n\nexport const destroySignal = (getter) => {\n if (isSignal(getter)) {\n Reactive.destroy(getter);\n }\n}\n\nexport const isSignal = (getter) => {\n const signal = Reactive.reactives.get(getter);\n if (!signal) {\n return false;\n }\n\n return signal instanceof Signal;\n}\n\nexport const isDirtySignal = (getter) => {\n const signal = Reactive.reactives.get(getter);\n if (!signal) {\n return false;\n }\n\n return signal.isDirty;\n}", "import { Reactive } from './Reactive.js';\n\nexport class Subscriber {\n static create(getter, fn, config = {}) {\n const subscriber = new Subscriber(getter, fn, config);\n Reactive.reactives.set(subscriber.getter, subscriber);\n return () => Reactive.destroy(subscriber.getter);\n }\n\n constructor(getter, subscriber, config = {}) {\n this._id = Reactive.nextId();\n this.getter = getter;\n this.isDirty = false;\n this.subscriber = subscriber;\n this.debounce = config.debounce || 0;\n this.onAccess = config.onAccess || null;\n this.immediate = true;\n this._hasPendingDebounce = false;\n this._lastComputeTime = null;\n this._debounceTimer = null;\n this.dependants = new Set();\n this.dependantIds = new Set();\n this.unsubscribe = () => Reactive.computationManager.removeReactive(this);\n Reactive.begin(this);\n this.cachedValue = this.getter();\n this.subscriber(this.cachedValue); // Call subscriber with initial value\n Reactive.end(this);\n }\n\n compute() {\n try {\n this.cachedValue = this.getter();\n this.subscriber(this.cachedValue);\n this.isDirty = false;\n } catch (error) {\n throw error;\n }\n }\n}\n\nexport const createSubscriber = (getter, fn, config = {}) => Subscriber.create(getter, fn, config);\n\nexport const destroySubscriber = (getter) => {\n if (isSubscriber(getter)) {\n Reactive.destroy(getter);\n }\n}\n\nexport const isSubscriber = (getter) => {\n const subscriber = Reactive.reactives.get(getter);\n if (!subscriber) {\n return false;\n }\n\n return subscriber instanceof Subscriber;\n}", "const traversalFunctions = [\n null, // index 0 (unused)\n null, // index 1 (single property access doesn't need optimization)\n (obj, path) => obj?.[path[0]]?.[path[1]],\n (obj, path) => obj?.[path[0]]?.[path[1]]?.[path[2]],\n (obj, path) => obj?.[path[0]]?.[path[1]]?.[path[2]]?.[path[3]],\n (obj, path) => obj?.[path[0]]?.[path[1]]?.[path[2]]?.[path[3]]?.[path[4]],\n (obj, path) => obj?.[path[0]]?.[path[1]]?.[path[2]]?.[path[3]]?.[path[4]]?.[path[5]],\n (obj, path) => obj?.[path[0]]?.[path[1]]?.[path[2]]?.[path[3]]?.[path[4]]?.[path[5]]?.[path[6]],\n (obj, path) => obj?.[path[0]]?.[path[1]]?.[path[2]]?.[path[3]]?.[path[4]]?.[path[5]]?.[path[6]]?.[path[7]]\n]\n\nfunction createTraversalFunction(length) {\n const accessors = Array.from({ length }, (_, i) => `?.[path[${i}]]`);\n const expr = \"obj\" + accessors.join(\"\");\n const fn = new Function(\"obj\", \"path\", `return ${expr}`);\n traversalFunctions[length] = fn;\n return fn;\n}\n\nexport function traverse(state, path) {\n const len = path.length;\n if (len === 0) return state;\n if (len === 1) return state[path[0]];\n \n // Use existing function if available\n if (len < traversalFunctions.length && traversalFunctions[len]) {\n return traversalFunctions[len](state, path);\n }\n \n // Create and cache new function if needed\n if (!traversalFunctions[len]) {\n return createTraversalFunction(len)(state, path);\n }\n \n return traversalFunctions[len](state, path);\n}\n", "// Surface.js\nimport { createComputed, destroyComputed } from './Computed.js';\nimport { addEffect } from './Reactive.js';\nimport { createSignal } from './Signal.js';\nimport { traverse } from './lib/traverse.js';\n\nconst EMPTY_CACHE = Symbol();\n\nexport class Surface {\n static surfaces = new WeakMap();\n static plugins = new Map();\n\n static registerPlugin(name, plugin) {\n if (Surface.plugins.has(name)) {\n throw new Error(`Plugin \"${name}\" already registered`);\n }\n Surface.plugins.set(name, plugin());\n }\n\n static resetPlugins() {\n Surface.plugins.clear();\n }\n\n static create(setupFn, options = {}) {\n const instance = new Surface(options);\n const useSurface = instance.setup(setupFn);\n Surface.surfaces.set(useSurface, instance);\n return useSurface;\n }\n\n static createPlugin(name, fn, options = {}) {\n const plugin = Surface.create(fn, options);\n Surface.registerPlugin(name, plugin);\n return plugin;\n }\n\n constructor(options = {}) {\n this.options = options;\n this.setupFn = null;\n this.subscribers = new Set();\n this.subscribersQueued = false;\n this.destroyCallback = null;\n\n // Values, computeds, actions, and extensions that are pending to be bound to the surface\n this.values = new Set();\n this.computeds = new Set();\n this.actions = new Set();\n this.extensions = new Set();\n\n this.snapshotCache = EMPTY_CACHE;\n this.surface = this.#createSurface();\n this.useSurface = () => this.surface;\n }\n\n setup(setupFn) {\n if (!setupFn) {\n return null;\n }\n\n this.setupFn = setupFn;\n this.reset();\n\n const pendingReactives = new Set();\n\n try {\n let result;\n \n if (typeof setupFn === 'function') {\n result = this.#setupFromFunction(setupFn, pendingReactives);\n } else if (typeof setupFn === 'object' && setupFn !== null) {\n result = this.#setupFromObject(setupFn, pendingReactives);\n } else {\n throw new Error('setupFn must be a function or object configuration');\n }\n \n this.#bindSurface(result);\n pendingReactives.forEach(reactive => addEffect(reactive, () => this.#queueSubscribers()));\n this.#queueSubscribers(); \n return this.useSurface;\n } catch (error) {\n console.error('Error in setup function', error);\n throw error;\n }\n }\n\n reset() {\n this.subscribers.clear();\n this.subscribersQueued = false;\n this.values.clear();\n this.computeds.clear();\n this.actions.clear();\n this.extensions.clear();\n this.snapshotCache = EMPTY_CACHE;\n this.surface = this.#createSurface();\n }\n\n createValue(initial = undefined, cb) {\n const signal = createSignal(initial);\n const value = Object.create(null);\n Object.defineProperty(value, 'value', {\n get: () => signal(),\n set: (newValue) => signal(newValue),\n enumerable: true,\n });\n this.values.add(value);\n cb?.(signal);\n return value;\n }\n\n createComputed(fn, cb) {\n const computed = createComputed(fn, { context: this.surface });\n const computedValue = Object.create(null);\n Object.defineProperty(computedValue, 'value', {\n get: () => computed(),\n enumerable: true,\n });\n this.computeds.add(computedValue);\n cb?.(computed);\n return computedValue;\n }\n\n createAction(fn) {\n const action = fn.bind(this.surface, this.surface)\n this.actions.add(action);\n return action;\n }\n\n extend(useSurface) {\n \n if (!useSurface) throw new Error('No source surface provided');\n \n if (!isSurface(useSurface)) {\n throw new Error('Cannot extend non-surface');\n }\n const surface = useSurface();\n this.extensions.add(surface);\n return surface;\n }\n\n #setupFromFunction(setupFn, pendingReactives) {\n return setupFn({\n value: (initial = undefined) => this.createValue(initial, (signal) => pendingReactives.add(signal)),\n computed: (fn = () => {}) => this.createComputed(fn, (reactor) => pendingReactives.add(reactor)),\n action: (fn = () => {}) => this.createAction(fn),\n extend: (useSurface) => this.extend(useSurface),\n destroy: () => this.#destroy(),\n ...Object.fromEntries(Surface.plugins.entries())\n }) || {};\n }\n\n #processStateValue(stateConfig, isDev, key) {\n // Support shorthand: state: { count: 0 } instead of { count: { default: 0 } }\n if (typeof stateConfig !== 'object' || stateConfig === null) {\n return typeof stateConfig === 'function' ? stateConfig() : stateConfig;\n }\n \n // If it's an object but doesn't have 'default', treat as shorthand\n if (!('default' in stateConfig)) {\n // Validate state config in dev mode\n if (isDev && 'dummy' in stateConfig) {\n console.warn(`State \"${key}\" has dummy value but no default value`);\n }\n return typeof stateConfig === 'function' ? stateConfig() : stateConfig;\n }\n \n // Full config with default/dummy\n let value = isDev && 'dummy' in stateConfig ? stateConfig.dummy : stateConfig.default;\n return typeof value === 'function' ? value() : value;\n }\n\n #setupFromObject(config, pendingReactives) {\n const result = {};\n const isDev = this.options.mode === 'development' || this.options.mode === 'dev';\n\n // 1. Process extend array first (so extended properties are available)\n if (config.extend && Array.isArray(config.extend)) {\n for (const useSurface of config.extend) {\n this.extend(useSurface);\n }\n }\n\n // 2. Process plugins (if specified) - handled in #bindSurface via Surface.plugins\n // Note: Plugins are automatically added to all surfaces, so we don't need to add them to result\n // If you want selective plugin inclusion, you'd need to modify #bindSurface\n\n // 3. Process state definitions\n if (config.state && typeof config.state === 'object') {\n for (const [key, stateConfig] of Object.entries(config.state)) {\n const initialValue = this.#processStateValue(stateConfig, isDev, key);\n result[key] = this.createValue(initialValue, (signal) => pendingReactives.add(signal));\n }\n }\n\n // 4. Process computed properties\n if (config.computed && typeof config.computed === 'object') {\n for (const [key, fn] of Object.entries(config.computed)) {\n if (typeof fn === 'function') {\n result[key] = this.createComputed(fn, (reactor) => pendingReactives.add(reactor));\n }\n }\n }\n\n // 5. Process actions\n if (config.actions && typeof config.actions === 'object') {\n for (const [key, fn] of Object.entries(config.actions)) {\n if (typeof fn === 'function') {\n result[key] = this.createAction(fn);\n }\n }\n }\n\n // 6. Handle lifecycle hooks\n if (config.onInit && typeof config.onInit === 'function') {\n // Execute after setup is complete\n Promise.resolve().then(() => {\n try {\n config.onInit(this.surface);\n } catch (error) {\n console.error('Error in onInit callback', error);\n }\n });\n }\n\n if (config.onDestroy && typeof config.onDestroy === 'function') {\n // Store for later execution\n this.destroyCallback = config.onDestroy;\n }\n\n return result;\n }\n\n #createAdapter () { \n return [() => this.#getSnapshot(), (subscriber) => this.#subscribe(subscriber)];\n }\n\n #getSnapshot() {\n if (this.snapshotCache !== EMPTY_CACHE) {\n return this.snapshotCache;\n }\n\n const clone = Object.create(Object.getPrototypeOf(this.surface));\n Object.defineProperties(clone, Object.getOwnPropertyDescriptors(this.surface));\n this.snapshotCache = Object.freeze(clone);\n \n return this.snapshotCache;\n };\n\n #subscribe(listener) {\n this.subscribers.add(listener);\n return () => this.subscribers.delete(listener);\n }\n\n #callSubscribers(snapshot) {\n for (const subscriber of this.subscribers) {\n subscriber(snapshot);\n }\n }\n\n #queueSubscribers() {\n if (this.subscribers.size === 0 || this.subscribersQueued) return;\n this.subscribersQueued = true;\n Promise.resolve().then(() => {\n this.subscribersQueued = false;\n this.snapshotCache = EMPTY_CACHE;\n this.#callSubscribers(this.#getSnapshot());\n });\n }\n\n #createSurface(surface = Object.create(null)) {\n Object.defineProperty(surface, '$get', {\n value: (path) => this.#get(path),\n writable: false,\n enumerable: false,\n configurable: false\n });\n \n Object.defineProperty(surface, '$set', {\n value: (path, newValue) => this.#set(path, newValue),\n writable: false,\n enumerable: false,\n configurable: false\n });\n \n Object.defineProperty(surface, '$dispatch', {\n value: (name) => this.#dispatch(name),\n writable: false,\n enumerable: false,\n configurable: false\n });\n \n Object.defineProperty(surface, '$inject', {\n value: (overrides) => Object.assign({}, this.surface, overrides),\n writable: false,\n enumerable: false,\n configurable: false\n });\n\n Object.defineProperty(surface, '$snapshot', {\n value: () => this.#getSnapshot(),\n writable: false,\n enumerable: false,\n configurable: false\n });\n\n Object.defineProperty(surface, '$subscribe', {\n value: (listener) => this.#subscribe(listener),\n writable: false,\n enumerable: false,\n configurable: false\n });\n \n Object.defineProperty(surface, '$adapter', {\n value: () => this.#createAdapter(),\n writable: false,\n enumerable: false,\n configurable: false\n });\n\n Object.defineProperty(surface, '$destroy', {\n value: () => this.#destroy(),\n writable: false,\n enumerable: false,\n configurable: false\n });\n return surface;\n }\n\n #destroy() {\n // Call onDestroy callback if defined\n if (this.destroyCallback && typeof this.destroyCallback === 'function') {\n try {\n this.destroyCallback(this.surface);\n } catch (error) {\n console.error('Error in onDestroy callback', error);\n }\n }\n \n const surfaceComputed = this.surfaceComputed;\n this.surfaceComputed = null;\n Surface.surfaces.delete(surfaceComputed);\n destroyComputed(surfaceComputed);\n }\n\n #get(path = []) {\n return traverse(this.surface, path);\n }\n\n #set(name, newValue) {\n const value = this.values?.get?.(name);\n value.value = newValue;\n return this.surface;\n }\n\n #dispatch(name, ...args) {\n const action = this.actions.has(name)\n ? this.actions.get(name)\n : this.surface[name];\n\n if (typeof action === 'function') {\n return action(...args);\n }\n return this.surfaceComputed();\n }\n\n #bindSurface(result = {}) {\n const oldKeys = Object.keys(this.surface);\n\n while (oldKeys.length > 0) {\n const key = oldKeys.shift();\n if (key in this.surface) {\n delete this.surface[key];\n }\n }\n\n for (const [key, plugin] of Surface.plugins) {\n Object.defineProperty(this.surface, key, {\n value: plugin\n });\n }\n\n for (const extension of this.extensions) {\n const descriptors = Object.getOwnPropertyDescriptors(extension);\n // Filter out the special $ methods if you don't want to inherit those\n const filteredDescriptors = Object.fromEntries(\n Object.entries(descriptors).filter(([key]) => !key.startsWith('$'))\n );\n Object.defineProperties(this.surface, filteredDescriptors);\n }\n\n const entries = Object.entries(result);\n \n for (const [key, value] of entries) {\n if (this.values.has(value)) {\n Object.defineProperty(this.surface, key, {\n get: () => value.value,\n set: (newValue) => value.value = newValue\n });\n\n continue;\n }\n\n if (this.computeds.has(value)) {\n Object.defineProperty(this.surface, key, {\n get: () => value.value\n });\n continue;\n }\n \n if (this.actions.has(value)) {\n Object.defineProperty(this.surface, key, { value });\n continue;\n }\n\n this.surface[key] = value;\n }\n\n return this.surface;\n }\n}\n\nexport const defineSurface = (...args) => Surface.create(...args);\nexport const refreshSurface = (surfaceComputed) => {\n if (isSurface(surfaceComputed)) {\n const surfaceInstance = Surface.surfaces.get(surfaceComputed);\n if (surfaceInstance) {\n surfaceInstance.setup();\n }\n }\n}\nexport const definePlugin = (...args) => Surface.createPlugin(...args);\nexport const isSurface = (surfaceComputed) => Surface.surfaces.has(surfaceComputed);\n\nexport const destroySurface = (surfaceComputed) => {\n if (isSurface(surfaceComputed)) {\n Surface.surfaces.delete(surfaceComputed);\n }\n}\n"],
|
|
5
|
-
"mappings": "AAAO,SAASA,EAAaC,EAAU,CACrC,OAAI,OAAO,OAAW,KAAe,OAAO,oBACnC,OAAO,oBAAoBA,EAAU,CAAE,QAAS,GAAI,CAAC,EAI1D,OAAO,OAAW,IAEhB,OAAO,sBACF,OAAO,sBAAsB,IAAM,CACxC,WAAWA,EAAU,CAAC,CACxB,CAAC,EAGI,WAAWA,EAAU,CAAC,GAI3B,OAAOA,GAAa,YACtBA,EAAS,EAEJ,KACT,CCpBO,IAAMC,EAAN,KAAyB,CAC9B,aAAc,CACZ,KAAK,MAAQ,IAAI,IACjB,KAAK,QAAU,IAAI,IACnB,KAAK,oBAAsB,IAAI,IAC/B,KAAK,WAAa,IAAI,IACtB,KAAK,cAAgB,EACvB,CAEA,YAAYC,EAAU,CACpB,GAAI,CAACA,EAAS,UACZA,EAAS,QAAU,GAEfA,EAAS,SAAWA,EAAS,WAAcA,EAAS,SAAWA,EAAS,QAAQ,KAAO,EACzF,KAAK,sBAAsBA,CAAQ,GAEnC,KAAK,WAAW,IAAIA,CAAQ,EAEvB,KAAK,gBACR,KAAK,cAAgB,GACrBC,EAAa,IAAM,CACjB,QAAWD,KAAY,KAAK,WAC1B,KAAK,QAAQ,IAAIA,CAAQ,EAE3B,KAAK,MAAM,IAAI,EACf,KAAK,WAAW,MAAM,EACtB,KAAK,cAAgB,EACvB,CAAC,IAGDA,EAAS,YAAcA,EAAS,WAAW,KAAO,GAAG,CAEvD,IAAME,E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IdleTick", "callback", "ComputationManager", "reactive", "nextIdleTick", "deadRefs", "ids", "weakRef", "dependant", "ref", "now", "timeElapsed", "reactives", "sortedReactives", "callback", "error", "sorted", "visited", "visiting", "visit", "dependants", "Reactive", "_Reactive", "ComputationManager", "key", "value", "keys", "out", "i", "reactive", "reactorIndex", "cycle", "error", "r", "getter", "effect", "reactives", "deadRefs", "ids", "weakRef", "dependant", "ref", "isReactive", "getter", "Reactive", "addEffect", "effect", "removeEffect", "addContext", "key", "value", "Reactive", "useContext", "keys", "hasContext", "createAdapter", "getter", "path", "isReactive", "snapshotCache", "unsubscribeAll", "subscribers", "getSnapshot", "clone", "listener", "addEffect", "subscriber", "isAsyncFunction", "fn", "Computed", "_Computed", "fn", "config", "computed", "Reactive", "isAsyncFunction", "#getter", "computationId", "value", "resolve", "error", "reject", "createComputed", "destroyComputed", "target", "isComputed", "getter", "isDirtyComputed", "Signal", "_Signal", "initialValue", "config", "signal", "Reactive", "args", "#getter", "error", "createSignal", "destroySignal", "getter", "isSignal", "isDirtySignal", "Subscriber", "_Subscriber", "getter", "fn", "config", "subscriber", "Reactive", "error", "createSubscriber", "destroySubscriber", "isSubscriber", "traversalFunctions", "obj", "path", "createTraversalFunction", "length", "expr", "_", "i", "fn", "traverse", "state", "len", "EMPTY_CACHE", "Surface", "_Surface", "name", "plugin", "setupFn", "options", "instance", "useSurface", "fn", "#createSurface", "pendingReactives", "result", "#setupFromFunction", "#setupFromObject", "#bindSurface", "reactive", "addEffect", "#queueSubscribers", "error", "initial", "cb", "signal", "createSignal", "value", "newValue", "computed", "createComputed", "computedValue", "action", "isSurface", "surface", "reactor", "#destroy", "#processStateValue", "stateConfig", "isDev", "key", "config", "initialValue", "#createAdapter", "#getSnapshot", "subscriber", "#subscribe", "clone", "listener", "#callSubscribers", "snapshot", "path", "#get", "#set", "#dispatch", "overrides", "surfaceComputed", "destroyComputed", "traverse", "args", "oldKeys", "extension", "descriptors", "filteredDescriptors", "entries", "defineSurface", "refreshSurface", "surfaceInstance", "definePlugin"]
|
|
4
|
+
"sourcesContent": ["export function nextIdleTick(callback) {\n if (typeof window !== 'undefined' && window.requestIdleCallback) {\n return window.requestIdleCallback(callback, { timeout: 100 });\n }\n\n // Fallback for browsers without requestIdleCallback (Safari/WebKit)\n if (typeof window !== 'undefined') {\n // Use requestAnimationFrame + setTimeout for better idle approximation\n if (window.requestAnimationFrame) {\n return window.requestAnimationFrame(() => {\n setTimeout(callback, 0);\n });\n }\n // Final fallback to setTimeout\n return setTimeout(callback, 0);\n }\n\n // Server-side or no window object - execute immediately\n if (typeof callback === 'function') {\n callback();\n }\n return null;\n}\n", "import { nextIdleTick } from './utils/nextIdleTick.js';\n\nexport class ComputationManager {\n constructor() {\n this.roots = new Map();\n this.pending = new Set();\n this.onCompleteCallbacks = new Set();\n this.onNextIdle = new Set();\n this.idleScheduled = false;\n }\n\n markAsDirty(reactive) {\n if (!reactive.isDirty) {\n reactive.isDirty = true;\n \n if (reactive.isAsync || reactive.immediate || (reactive.effects && reactive.effects.size > 0)) {\n this.scheduleRecomputation(reactive);\n } else {\n this.onNextIdle.add(reactive);\n\n if (!this.idleScheduled) {\n this.idleScheduled = true;\n nextIdleTick(() => {\n for (const reactive of this.onNextIdle) {\n this.pending.add(reactive);\n }\n this.flush(null);\n this.onNextIdle.clear();\n this.idleScheduled = false; // \u2190 Reset flag\n });\n }\n }\n if (reactive.dependants && reactive.dependants.size > 0) {\n // Process WeakRefs and rebuild ID set with only alive IDs\n const deadRefs = [];\n const ids = new Set();\n reactive.dependants.forEach(weakRef => {\n const dependant = weakRef.deref();\n if (dependant) {\n this.markAsDirty(dependant);\n ids.add(dependant._id);\n } else {\n deadRefs.push(weakRef);\n }\n });\n // Clean up dead WeakRefs and sync IDs\n deadRefs.forEach(ref => reactive.dependants.delete(ref));\n reactive.dependantIds = ids;\n }\n }\n }\n\n scheduleRecomputation(reactive) {\n if (!reactive.debounce) {\n return this.recompute(reactive);\n }\n\n // Check if we can recompute (either first time or cooldown expired)\n const now = Date.now();\n const timeElapsed = reactive._lastComputeTime ? now - reactive._lastComputeTime : Infinity;\n const canRecompute = !reactive._hasPendingDebounce || timeElapsed >= reactive.debounce;\n\n if (canRecompute) {\n // Clear any existing timer and set up new cooldown period\n clearTimeout(reactive._debounceTimer);\n reactive._hasPendingDebounce = true;\n reactive._lastComputeTime = now;\n \n reactive._debounceTimer = setTimeout(() => {\n reactive._hasPendingDebounce = false;\n reactive._debounceTimer = null;\n }, reactive.debounce);\n \n return this.recompute(reactive);\n }\n\n // Still in cooldown period, return cached value\n return reactive.cachedValue;\n }\n\n removeReactive(reactive) {\n this.pending.delete(reactive);\n this.onNextIdle.delete(reactive);\n }\n\n recompute(reactive) {\n this.pending.add(reactive);\n return this.flush(reactive);\n }\n\n flush(reactive) {\n const reactives = Array.from(this.pending);\n this.pending.clear();\n\n // Sort by dependencies\n const sortedReactives = this.sortByDependencies(reactives);\n \n // Process in reverse order (dependencies first)\n for (const reactive of sortedReactives) {\n this.onNextIdle.delete(reactive);\n reactive.compute()\n }\n\n // Notify completion callbacks\n for (const callback of this.onCompleteCallbacks) {\n try {\n callback();\n } catch (error) {\n console.error('Error in batch completion callback:', error);\n }\n }\n\n // If we have a target ID, ensure it's computed and return its value\n if (reactive) {\n // Make sure the target computed is evaluated if it wasn't in the batch\n if (!sortedReactives.includes(reactive)) {\n reactive.compute();\n }\n return reactive.cachedValue;\n }\n \n return undefined;\n }\n\n sortByDependencies(reactives) {\n const sorted = [];\n const visited = new Set();\n const visiting = new Set();\n\n const visit = (reactive) => {\n if (visiting.has(reactive)) return;\n if (visited.has(reactive)) return;\n\n visiting.add(reactive);\n\n // Get dependant computed values (handle WeakRefs)\n const dependants = reactive.dependants;\n if (dependants && dependants.size > 0) {\n dependants.forEach(weakRef => {\n const dependant = weakRef.deref();\n if (dependant && reactives.includes(dependant)) {\n visit(dependant); // Visit dependants first\n }\n });\n }\n\n visiting.delete(reactive);\n visited.add(reactive);\n sorted.unshift(reactive); // Add to start of array instead of end\n };\n\n // Process all nodes\n for (const reactive of reactives) {\n if (!visited.has(reactive)) {\n visit(reactive);\n }\n }\n\n return sorted;\n }\n}", "import { ComputationManager } from './ComputationManager.js';\n\nexport class Reactive {\n static computationManager = new ComputationManager();\n static awaitingRecomputation = new Set();\n static reactives = new WeakMap();\n static currentlyComputing = null;\n static computationStack = [];\n static currentDepth = 0;\n static effectsCache = new Set();\n static processingEffects = false;\n static _nextId = 1; // Counter for unique reactive IDs\n static config = {\n maxDepth: 2000,\n }\n static ctx = {};\n \n static nextId() {\n return Reactive._nextId++;\n }\n\n static addContext(key, value) {\n if (!key || typeof key !== 'string') {\n throw new Error('Invalid context key');\n }\n \n if (typeof value === 'undefined') {\n throw new Error('Invalid context value');\n }\n \n if (key in Reactive.ctx) {\n throw new Error('Context key already exists');\n }\n \n Reactive.ctx[key] = value;\n }\n\n static useContext(keys) { \n if (!keys || keys.length === 0) return Reactive.ctx;\n if (keys.length === 1) return Reactive.ctx[keys[0]];\n\n const out = new Array(keys.length);\n for (let i = 0; i < keys.length; i++) {\n out[i] = Reactive.ctx[keys[i]];\n }\n return out;\n }\n\n static hasContext(keys) {\n if (!keys || keys.length === 0) return Object.keys(Reactive.ctx).length > 0;\n if (keys.length === 1) return keys[0] in Reactive.ctx;\n for (const key of keys) {\n if (!(key in Reactive.ctx)) return false;\n }\n return true;\n }\n\n static clearContext() {\n Reactive.ctx = {};\n }\n\n static begin(reactive) {\n if (Reactive.awaitingRecomputation.has(reactive)) {\n Reactive.awaitingRecomputation.delete(reactive);\n }\n\n const reactorIndex = Reactive.computationStack.indexOf(reactive);\n\n if (reactorIndex !== -1) {\n if (reactive.isAsync) {\n Reactive.computationStack.splice(reactorIndex, 1);\n Reactive.computationStack.push(reactive);\n Reactive.currentlyComputing = reactive;\n return;\n } \n const cycle = Reactive.computationStack.slice(reactorIndex).concat(reactive);\n const error = new Error(`Circular dependency detected: ${cycle.map(r => r).join(' -> ')}`);\n error.name = 'CircularDependencyError';\n error.displayed = false;\n throw error;\n }\n \n if (Reactive.currentDepth >= Reactive.config.maxDepth) {\n throw new Error(`Maximum reactive depth of ${Reactive.config.maxDepth} exceeded`);\n }\n \n Reactive.computationStack.push(reactive);\n Reactive.currentlyComputing = reactive;\n Reactive.currentDepth++;\n }\n \n static end(reactive) {\n if (reactive.isAsync) {\n Reactive.computationStack.splice(Reactive.computationStack.indexOf(reactive), 1);\n Reactive.currentlyComputing = Reactive.computationStack[Reactive.computationStack.length - 1] || null;\n Reactive.currentDepth--;\n return;\n }\n Reactive.computationStack.pop();\n Reactive.currentlyComputing = Reactive.computationStack[Reactive.computationStack.length - 1] || null;\n Reactive.currentDepth--;\n }\n\n static addEffect(getter, effect) {\n const reactive = Reactive.reactives.get(getter);\n \n // Compute if needed and notify with current value\n if (reactive.isDirty) {\n Reactive.computationManager.scheduleRecomputation(reactive);\n }\n \n if (!reactive.effects) {\n reactive.effects = new Set();\n }\n \n // Store the WeakRef instead of the raw effect\n reactive.effects.add(effect);\n \n // Return unsubscribe function\n return () => Reactive.removeEffect(getter, effect);\n }\n\n static removeEffect(getter, effect) {\n const reactive = Reactive.reactives.get(getter);\n if (reactive.effects) {\n reactive.effects.delete(effect);\n }\n }\n\n static recompute(reactive) {\n if (!Reactive.awaitingRecomputation.has(reactive)) {\n Reactive.awaitingRecomputation.add(reactive);\n }\n\n \n return Reactive.computationManager.scheduleRecomputation(reactive);\n }\n\n static callEffects(reactive) { \n Reactive.effectsCache.add(reactive);\n \n // Use a single setTimeout for batching\n if (!Reactive.processingEffects) {\n Reactive.processingEffects = true;\n setTimeout(() => {\n Reactive.processEffectsCache();\n Reactive.processingEffects = false;\n }, 0);\n }\n }\n\n static processEffectsCache() {\n const reactives = new Set(Reactive.effectsCache);\n Reactive.effectsCache.clear();\n \n for (const reactive of reactives) {\n try {\n // Process effects using WeakRefs\n const effects = reactive.effects || new Set();\n effects.forEach(effect => {\n if (effect) {\n effect(reactive.cachedValue);\n }\n });\n } catch (error) {\n console.error(`Error in reactive ${reactive._id} effect:`, error);\n }\n }\n \n // If new effects were added during processing, schedule another batch\n if (Reactive.effectsCache.size > 0) {\n setTimeout(() => {\n Reactive.processEffectsCache();\n }, 0);\n }\n }\n\n static markAsDirty(reactive) {\n if (!reactive.isDirty) {\n reactive.isDirty = true;\n \n if (reactive.immediate || (reactive.effects && reactive.effects.size > 0)) {\n Reactive.computationManager.scheduleRecomputation(reactive);\n }\n \n // Process WeakRefs and clean up dead ones\n const deadRefs = [];\n const ids = new Set();\n reactive.dependants.forEach(weakRef => {\n const dependant = weakRef.deref();\n if (dependant) {\n Reactive.markAsDirty(dependant);\n ids.add(dependant._id);\n } else {\n deadRefs.push(weakRef);\n }\n });\n // Clean up dead WeakRefs and sync IDs\n deadRefs.forEach(ref => reactive.dependants.delete(ref));\n reactive.dependantIds = ids;\n }\n }\n\n static destroy(getter) {\n const reactive = Reactive.reactives.get(getter);\n Reactive.computationManager.removeReactive(reactive);\n Reactive.reactives.delete(getter);\n }\n}\n\nexport const markAsDirty = (reactive) => {\n if (isReactive(reactive)) {\n const reactiveInstance = Reactive.reactives.get(reactive);\n if (reactiveInstance) {\n return Reactive.markAsDirty(reactiveInstance);\n }\n }\n}\n\nexport const isReactive = (getter) => {\n return Reactive.reactives.has(getter);\n}\n\nexport const addEffect = (getter, effect) => {\n if (!isReactive(getter)) {\n throw new Error('Invalid effect getter');\n \n }\n\n if (!effect || typeof effect !== 'function') {\n throw new Error('Invalid effect function');\n }\n\n return Reactive.addEffect(getter, effect);\n}\n\nexport const removeEffect = (getter, effect) => {\n if (isReactive(getter)) {\n return Reactive.removeEffect(getter, effect);\n }\n}\n\nexport const destroyReactive = (getter) => {\n if (isReactive(getter)) {\n return Reactive.destroy(getter);\n }\n}\n\nexport const addContext = (key, value) => Reactive.addContext(key, value)\n\nexport const useContext = (...keys) => {\n if (keys.length === 0) return Reactive.ctx;\n if (keys.length === 1) return Reactive.ctx[keys[0]];\n return keys.map(key => Reactive.ctx[key]);\n}\n\nexport const hasContext = (...keys) => Reactive.hasContext(keys)\n\nexport const createAdapter = (getter, path = []) => {\n if (!isReactive(getter)) {\n throw new Error('Invalid adapter getter');\n }\n\n let snapshotCache = undefined;\n let unsubscribeAll = null;\n const subscribers = new Set();\n\n const getSnapshot = () => {\n if (snapshotCache !== undefined) {\n return snapshotCache;\n }\n\n const value = path && path.length > 0 ? traverse(getter(), path) : getter();\n\n if (Array.isArray(value)) {\n snapshotCache = value.slice();\n } else if (typeof value === 'object' && value !== null) {\n const clone = Object.create(Object.getPrototypeOf(value));\n Object.defineProperties(clone, Object.getOwnPropertyDescriptors(value));\n snapshotCache = Object.freeze(clone);\n } else {\n snapshotCache = value;\n }\n \n return snapshotCache;\n };\n\n const subscribe = (listener) => {\n if (!unsubscribeAll) {\n unsubscribeAll = addEffect(getter, () => {\n snapshotCache = undefined;\n for (const subscriber of subscribers) {\n subscriber(getSnapshot);\n }\n });\n }\n \n subscribers.add(listener);\n return () => {\n subscribers.delete(listener);\n if (subscribers.size === 0) {\n unsubscribeAll();\n unsubscribeAll = null;\n }\n };\n };\n\n return [getSnapshot, subscribe];\n}", "export const isAsyncFunction = fn =>\n typeof fn === 'function' &&\n (fn.constructor.name === 'AsyncFunction' ||\n fn.constructor.name === 'AsyncGeneratorFunction');\n", "import { Reactive } from './Reactive.js';\nimport { isAsyncFunction } from './utils/isAsync.js';\n\nexport class Computed {\n static create(fn, config = {}) {\n const computed = new Computed(fn, config);\n Reactive.reactives.set(computed.getter, computed);\n return computed.getter;\n }\n\n constructor(fn, config = {}) {\n // Validate context must be a function if provided\n if (config.context && typeof config.context !== 'function') {\n throw new Error('Computed context must be a function');\n }\n \n this.fn = fn;\n this.isAsync = isAsyncFunction(fn);\n this.pendingResolve = undefined;\n this.roots = new Set();\n this.dependants = new Set();\n this.dependantIds = new Set();\n this.effects = new Set(Array.isArray(config.effects) ? config.effects : []);\n this.cachedValue = config.initialValue || undefined;\n this.isDirty = true;\n this.debounce = config.debounce || 0;\n this.onAccess = config.onAccess || undefined;\n this.detatched = config.detatched || false;\n this.immediate = config.immediate || false; \n this.useContext = config.context || (Reactive.hasContext() ? () => Reactive.useContext() : () => undefined);\n this.resolvers = [];\n this.rejectors = [];\n this._id = Reactive.nextId();\n this._lastComputeTime = undefined;\n this._hasPendingDebounce = false;\n this._debounceTimer = undefined;\n this._computationId = 0; // Track computation version\n this.getter = this.#getter.bind(this);\n \n\n if (this.immediate) {\n this.compute();\n }\n }\n\n compute() {\n Reactive.begin(this);\n try { \n if (!this.isAsync) {\n // Call context function if provided, otherwise use useContext\n const contextValue = this.useContext ? this.useContext() : undefined;\n this.cachedValue = this.fn(contextValue, this.cachedValue);\n this.isDirty = false;\n return this.cachedValue;\n }\n\n // Track this specific computation\n this._computationId = (this._computationId || 0) + 1;\n const computationId = this._computationId;\n\n const contextValue = this.useContext ? this.useContext() : undefined;\n this.pendingResolve = this.fn(contextValue, this.cachedValue);\n this.pendingResolve.then(value => {\n // Only update if this is still the latest computation\n if (this._computationId === computationId) {\n this.resolvers.forEach(resolve => resolve(value));\n this.resolvers = [];\n this.cachedValue = value;\n this.isDirty = false;\n }\n return value;\n }).catch(error => {\n if (this._computationId === computationId) {\n this.rejectors.forEach(reject => reject(error));\n this.rejectors = [];\n }\n }).finally(() => {\n this.pendingResolve = null; // Always clear pending promise\n // Only call end/effects if this is still the latest computation\n if (this._computationId === computationId) {\n Reactive.end(this);\n Reactive.callEffects(this);\n }\n });\n\n this.cachedValue = new Promise((resolve, reject) => {\n this.resolvers.push(resolve);\n this.rejectors.push(reject);\n });\n \n return this.cachedValue;\n } finally {\n if (!this.isAsync) {\n Reactive.end(this);\n Reactive.callEffects(this);\n }\n }\n }\n\n #getter() {\n try {\n if (!this.detatched && Reactive.currentlyComputing && Reactive.currentlyComputing !== this && !this.dependantIds.has(Reactive.currentlyComputing._id)) {\n this.dependantIds.add(Reactive.currentlyComputing._id);\n this.dependants.add(new WeakRef(Reactive.currentlyComputing));\n }\n \n if (!this.isDirty) {\n if (this.isAsync) {\n return Promise.resolve(this.cachedValue);\n }\n\n return this.cachedValue;\n }\n\n // If dirty, always start new computation (even if previous pending)\n return Reactive.recompute(this);\n } catch (error) {\n throw error;\n } finally {\n if (this.onAccess) {\n this.onAccess(this.cachedValue);\n }\n }\n }\n}\n\nexport const createComputed = (fn, config = {}) => Computed.create(fn, config);\n\nexport const destroyComputed = (target) => {\n if (isComputed(target)) {\n Reactive.destroy(target);\n }\n}\n\nexport const isComputed = (getter) => {\n const computed = Reactive.reactives.get(getter);\n if (!computed) {\n return false;\n }\n\n return computed instanceof Computed;\n}\n\nexport const isDirtyComputed = (getter) => {\n const computed = Reactive.reactives.get(getter);\n if (!computed) {\n return false;\n }\n\n return computed.isDirty;\n}\n", "import { Reactive } from './Reactive.js';\n\nexport class Signal {\n static create(initialValue, config = {}) {\n const signal = new Signal(initialValue, config);\n Reactive.reactives.set(signal.getter, signal);\n return signal.getter;\n }\n\n constructor(initialValue, config = {}) {\n this._id = Reactive.nextId();\n this.isAsync = false;\n this.cachedValue = undefined;\n this.dependants = new Set();\n this.dependantIds = new Set();\n this.roots = new Set();\n this.effects = new Set(Array.isArray(config.effects) ? config.effects : []);\n this.isDirty = true;\n this.debounce = config.debounce || 0;\n this.onAccess = config.onAccess || null;\n this.detatched = config.detatched || false;\n this.immediate = config.immediate || false;\n this._pendingChange = initialValue;\n this._lastComputeTime = null;\n this._hasPendingDebounce = false;\n this._debounceTimer = null;\n this.getter = (...args) => this.#getter(...args);\n }\n\n compute() {\n Reactive.begin(this);\n try {\n this.cachedValue = this._pendingChange;\n this._pendingChange = undefined;\n this.isDirty = false;\n return this.cachedValue;\n } finally {\n Reactive.end(this);\n Reactive.callEffects(this);\n }\n }\n\n #getter(...args) {\n try {\n if (!this.detatched && Reactive.currentlyComputing && Reactive.currentlyComputing !== this && !this.dependantIds.has(Reactive.currentlyComputing._id)) {\n this.dependantIds.add(Reactive.currentlyComputing._id);\n this.dependants.add(new WeakRef(Reactive.currentlyComputing));\n }\n\n if (args.length > 0) {\n const signal = args[0];\n this._pendingChange = typeof signal === 'function' ? signal(this.cachedValue) : signal;\n Reactive.markAsDirty(this);\n return;\n }\n\n if (this.isDirty) {\n return Reactive.recompute(this);\n }\n\n return this.cachedValue;\n \n } catch (error) {\n throw error;\n } finally {\n if (this.onAccess) {\n this.onAccess(this.cachedValue);\n }\n }\n }\n}\n\nexport const createSignal = (initialValue, config = {}) => Signal.create(initialValue, config);\n\nexport const destroySignal = (getter) => {\n if (isSignal(getter)) {\n Reactive.destroy(getter);\n }\n}\n\nexport const isSignal = (getter) => {\n const signal = Reactive.reactives.get(getter);\n if (!signal) {\n return false;\n }\n\n return signal instanceof Signal;\n}\n\nexport const isDirtySignal = (getter) => {\n const signal = Reactive.reactives.get(getter);\n if (!signal) {\n return false;\n }\n\n return signal.isDirty;\n}", "import { Reactive } from './Reactive.js';\n\nexport class Subscriber {\n static create(getter, fn, config = {}) {\n const subscriber = new Subscriber(getter, fn, config);\n Reactive.reactives.set(subscriber.getter, subscriber);\n return () => Reactive.destroy(subscriber.getter);\n }\n\n constructor(getter, subscriber, config = {}) {\n this._id = Reactive.nextId();\n this.getter = getter;\n this.isDirty = false;\n this.subscriber = subscriber;\n this.debounce = config.debounce || 0;\n this.onAccess = config.onAccess || null;\n this.immediate = true;\n this._hasPendingDebounce = false;\n this._lastComputeTime = null;\n this._debounceTimer = null;\n this.dependants = new Set();\n this.dependantIds = new Set();\n this.unsubscribe = () => Reactive.computationManager.removeReactive(this);\n Reactive.begin(this);\n this.cachedValue = this.getter();\n this.subscriber(this.cachedValue); // Call subscriber with initial value\n Reactive.end(this);\n }\n\n compute() {\n try {\n this.cachedValue = this.getter();\n this.subscriber(this.cachedValue);\n this.isDirty = false;\n } catch (error) {\n throw error;\n }\n }\n}\n\nexport const createSubscriber = (getter, fn, config = {}) => Subscriber.create(getter, fn, config);\n\nexport const destroySubscriber = (getter) => {\n if (isSubscriber(getter)) {\n Reactive.destroy(getter);\n }\n}\n\nexport const isSubscriber = (getter) => {\n const subscriber = Reactive.reactives.get(getter);\n if (!subscriber) {\n return false;\n }\n\n return subscriber instanceof Subscriber;\n}", "const traversalFunctions = [\n null, // index 0 (unused)\n null, // index 1 (single property access doesn't need optimization)\n (obj, path) => obj?.[path[0]]?.[path[1]],\n (obj, path) => obj?.[path[0]]?.[path[1]]?.[path[2]],\n (obj, path) => obj?.[path[0]]?.[path[1]]?.[path[2]]?.[path[3]],\n (obj, path) => obj?.[path[0]]?.[path[1]]?.[path[2]]?.[path[3]]?.[path[4]],\n (obj, path) => obj?.[path[0]]?.[path[1]]?.[path[2]]?.[path[3]]?.[path[4]]?.[path[5]],\n (obj, path) => obj?.[path[0]]?.[path[1]]?.[path[2]]?.[path[3]]?.[path[4]]?.[path[5]]?.[path[6]],\n (obj, path) => obj?.[path[0]]?.[path[1]]?.[path[2]]?.[path[3]]?.[path[4]]?.[path[5]]?.[path[6]]?.[path[7]]\n]\n\nfunction createTraversalFunction(length) {\n const accessors = Array.from({ length }, (_, i) => `?.[path[${i}]]`);\n const expr = \"obj\" + accessors.join(\"\");\n const fn = new Function(\"obj\", \"path\", `return ${expr}`);\n traversalFunctions[length] = fn;\n return fn;\n}\n\nexport function traverse(state, path) {\n const len = path.length;\n if (len === 0) return state;\n if (len === 1) return state[path[0]];\n \n // Use existing function if available\n if (len < traversalFunctions.length && traversalFunctions[len]) {\n return traversalFunctions[len](state, path);\n }\n \n // Create and cache new function if needed\n if (!traversalFunctions[len]) {\n return createTraversalFunction(len)(state, path);\n }\n \n return traversalFunctions[len](state, path);\n}\n", "// Surface.js\nimport { createComputed, destroyComputed } from './Computed.js';\nimport { addEffect } from './Reactive.js';\nimport { createSignal } from './Signal.js';\nimport { traverse } from './lib/traverse.js';\n\nconst EMPTY_CACHE = Symbol();\n\nexport class Surface {\n static surfaces = new WeakMap();\n static plugins = new Map();\n\n static registerPlugin(name, plugin) {\n if (Surface.plugins.has(name)) {\n throw new Error(`Plugin \"${name}\" already registered`);\n }\n Surface.plugins.set(name, plugin());\n }\n\n static resetPlugins() {\n Surface.plugins.clear();\n }\n\n static create(setupFn, options = {}) {\n const instance = new Surface(options);\n const useSurface = instance.setup(setupFn);\n Surface.surfaces.set(useSurface, instance);\n return useSurface;\n }\n\n static createPlugin(name, fn, options = {}) {\n const plugin = Surface.create(fn, options);\n Surface.registerPlugin(name, plugin);\n return plugin;\n }\n\n constructor(options = {}) {\n this.options = options;\n this.setupFn = null;\n this.subscribers = new Set();\n this.subscribersQueued = false;\n this.destroyCallback = null;\n\n // Values, computeds, actions, and extensions that are pending to be bound to the surface\n this.values = new Set();\n this.computeds = new Set();\n this.actions = new Set();\n this.extensions = new Set();\n\n this.snapshotCache = EMPTY_CACHE;\n this.surface = this.#createSurface();\n this.useSurface = () => this.surface;\n }\n\n setup(setupFn) {\n if (!setupFn) {\n return null;\n }\n\n this.setupFn = setupFn;\n this.reset();\n\n const pendingReactives = new Set();\n\n try {\n let result;\n \n if (typeof setupFn === 'function') {\n result = this.#setupFromFunction(setupFn, pendingReactives);\n } else if (typeof setupFn === 'object' && setupFn !== null) {\n result = this.#setupFromObject(setupFn, pendingReactives);\n } else {\n throw new Error('setupFn must be a function or object configuration');\n }\n \n this.#bindSurface(result);\n pendingReactives.forEach(reactive => addEffect(reactive, () => this.#queueSubscribers()));\n this.#queueSubscribers(); \n return this.useSurface;\n } catch (error) {\n console.error('Error in setup function', error);\n throw error;\n }\n }\n\n reset() {\n this.subscribers.clear();\n this.subscribersQueued = false;\n this.values.clear();\n this.computeds.clear();\n this.actions.clear();\n this.extensions.clear();\n this.snapshotCache = EMPTY_CACHE;\n this.surface = this.#createSurface();\n }\n\n createValue(initial = undefined, cb) {\n const signal = createSignal(initial);\n const value = Object.create(null);\n Object.defineProperty(value, 'value', {\n get: () => signal(),\n set: (newValue) => signal(newValue),\n enumerable: true,\n });\n this.values.add(value);\n cb?.(signal);\n return value;\n }\n\n createComputed(fn, cb) {\n const computed = createComputed(fn, { context: () => this.surface });\n const computedValue = Object.create(null);\n Object.defineProperty(computedValue, 'value', {\n get: () => computed(),\n enumerable: true,\n });\n this.computeds.add(computedValue);\n cb?.(computed);\n return computedValue;\n }\n\n createAction(fn) {\n const action = fn.bind(this.surface, this.surface)\n this.actions.add(action);\n return action;\n }\n\n extend(useSurface) {\n \n if (!useSurface) throw new Error('No source surface provided');\n \n if (!isSurface(useSurface)) {\n throw new Error('Cannot extend non-surface');\n }\n const surface = useSurface();\n this.extensions.add(surface);\n return surface;\n }\n\n #setupFromFunction(setupFn, pendingReactives) {\n return setupFn({\n value: (initial = undefined) => this.createValue(initial, (signal) => pendingReactives.add(signal)),\n computed: (fn = () => {}) => this.createComputed(fn, (reactor) => pendingReactives.add(reactor)),\n action: (fn = () => {}) => this.createAction(fn),\n extend: (useSurface) => this.extend(useSurface),\n destroy: () => this.#destroy(),\n ...Object.fromEntries(Surface.plugins.entries())\n }) || {};\n }\n\n #processStateValue(stateConfig, isDev, key) {\n // Support shorthand: state: { count: 0 } instead of { count: { default: 0 } }\n if (typeof stateConfig !== 'object' || stateConfig === null) {\n return typeof stateConfig === 'function' ? stateConfig() : stateConfig;\n }\n \n // If it's an object but doesn't have 'default', treat as shorthand\n if (!('default' in stateConfig)) {\n // Validate state config in dev mode\n if (isDev && 'dummy' in stateConfig) {\n console.warn(`State \"${key}\" has dummy value but no default value`);\n }\n return typeof stateConfig === 'function' ? stateConfig() : stateConfig;\n }\n \n // Full config with default/dummy\n let value = isDev && 'dummy' in stateConfig ? stateConfig.dummy : stateConfig.default;\n return typeof value === 'function' ? value() : value;\n }\n\n #setupFromObject(config, pendingReactives) {\n const result = {};\n const isDev = this.options.mode === 'development' || this.options.mode === 'dev';\n\n // 1. Process extend array first (so extended properties are available)\n if (config.extend && Array.isArray(config.extend)) {\n for (const useSurface of config.extend) {\n this.extend(useSurface);\n }\n }\n\n // 2. Process plugins (if specified) - handled in #bindSurface via Surface.plugins\n // Note: Plugins are automatically added to all surfaces, so we don't need to add them to result\n // If you want selective plugin inclusion, you'd need to modify #bindSurface\n\n // 3. Process state definitions\n if (config.state && typeof config.state === 'object') {\n for (const [key, stateConfig] of Object.entries(config.state)) {\n const initialValue = this.#processStateValue(stateConfig, isDev, key);\n result[key] = this.createValue(initialValue, (signal) => pendingReactives.add(signal));\n }\n }\n\n // 4. Process computed properties\n if (config.computed && typeof config.computed === 'object') {\n for (const [key, fn] of Object.entries(config.computed)) {\n if (typeof fn === 'function') {\n result[key] = this.createComputed(fn, (reactor) => pendingReactives.add(reactor));\n }\n }\n }\n\n // 5. Process actions\n if (config.actions && typeof config.actions === 'object') {\n for (const [key, fn] of Object.entries(config.actions)) {\n if (typeof fn === 'function') {\n result[key] = this.createAction(fn);\n }\n }\n }\n\n // 6. Handle lifecycle hooks\n if (config.onInit && typeof config.onInit === 'function') {\n // Execute after setup is complete\n Promise.resolve().then(() => {\n try {\n config.onInit(this.surface);\n } catch (error) {\n console.error('Error in onInit callback', error);\n }\n });\n }\n\n if (config.onDestroy && typeof config.onDestroy === 'function') {\n // Store for later execution\n this.destroyCallback = config.onDestroy;\n }\n\n return result;\n }\n\n #createAdapter () { \n return [() => this.#getSnapshot(), (subscriber) => this.#subscribe(subscriber)];\n }\n\n #getSnapshot() {\n if (this.snapshotCache !== EMPTY_CACHE) {\n return this.snapshotCache;\n }\n\n const clone = Object.create(Object.getPrototypeOf(this.surface));\n Object.defineProperties(clone, Object.getOwnPropertyDescriptors(this.surface));\n this.snapshotCache = Object.freeze(clone);\n \n return this.snapshotCache;\n };\n\n #subscribe(listener) {\n this.subscribers.add(listener);\n return () => this.subscribers.delete(listener);\n }\n\n #callSubscribers(snapshot) {\n for (const subscriber of this.subscribers) {\n subscriber(snapshot);\n }\n }\n\n #queueSubscribers() {\n if (this.subscribers.size === 0 || this.subscribersQueued) return;\n this.subscribersQueued = true;\n Promise.resolve().then(() => {\n this.subscribersQueued = false;\n this.snapshotCache = EMPTY_CACHE;\n this.#callSubscribers(this.#getSnapshot());\n });\n }\n\n #createSurface(surface = Object.create(null)) {\n Object.defineProperty(surface, '$get', {\n value: (path) => this.#get(path),\n writable: false,\n enumerable: false,\n configurable: false\n });\n \n Object.defineProperty(surface, '$set', {\n value: (path, newValue) => this.#set(path, newValue),\n writable: false,\n enumerable: false,\n configurable: false\n });\n \n Object.defineProperty(surface, '$dispatch', {\n value: (name) => this.#dispatch(name),\n writable: false,\n enumerable: false,\n configurable: false\n });\n \n Object.defineProperty(surface, '$inject', {\n value: (overrides) => Object.assign({}, this.surface, overrides),\n writable: false,\n enumerable: false,\n configurable: false\n });\n\n Object.defineProperty(surface, '$snapshot', {\n value: () => this.#getSnapshot(),\n writable: false,\n enumerable: false,\n configurable: false\n });\n\n Object.defineProperty(surface, '$subscribe', {\n value: (listener) => this.#subscribe(listener),\n writable: false,\n enumerable: false,\n configurable: false\n });\n \n Object.defineProperty(surface, '$adapter', {\n value: () => this.#createAdapter(),\n writable: false,\n enumerable: false,\n configurable: false\n });\n\n Object.defineProperty(surface, '$destroy', {\n value: () => this.#destroy(),\n writable: false,\n enumerable: false,\n configurable: false\n });\n return surface;\n }\n\n #destroy() {\n // Call onDestroy callback if defined\n if (this.destroyCallback && typeof this.destroyCallback === 'function') {\n try {\n this.destroyCallback(this.surface);\n } catch (error) {\n console.error('Error in onDestroy callback', error);\n }\n }\n \n const surfaceComputed = this.surfaceComputed;\n this.surfaceComputed = null;\n Surface.surfaces.delete(surfaceComputed);\n destroyComputed(surfaceComputed);\n }\n\n #get(path = []) {\n return traverse(this.surface, path);\n }\n\n #set(name, newValue) {\n const value = this.values?.get?.(name);\n value.value = newValue;\n return this.surface;\n }\n\n #dispatch(name, ...args) {\n const action = this.actions.has(name)\n ? this.actions.get(name)\n : this.surface[name];\n\n if (typeof action === 'function') {\n return action(...args);\n }\n return this.surfaceComputed();\n }\n\n #bindSurface(result = {}) {\n const oldKeys = Object.keys(this.surface);\n\n while (oldKeys.length > 0) {\n const key = oldKeys.shift();\n if (key in this.surface) {\n delete this.surface[key];\n }\n }\n\n for (const [key, plugin] of Surface.plugins) {\n Object.defineProperty(this.surface, key, {\n value: plugin\n });\n }\n\n for (const extension of this.extensions) {\n const descriptors = Object.getOwnPropertyDescriptors(extension);\n // Filter out the special $ methods if you don't want to inherit those\n const filteredDescriptors = Object.fromEntries(\n Object.entries(descriptors).filter(([key]) => !key.startsWith('$'))\n );\n Object.defineProperties(this.surface, filteredDescriptors);\n }\n\n const entries = Object.entries(result);\n \n for (const [key, value] of entries) {\n if (this.values.has(value)) {\n Object.defineProperty(this.surface, key, {\n get: () => value.value,\n set: (newValue) => value.value = newValue\n });\n\n continue;\n }\n\n if (this.computeds.has(value)) {\n Object.defineProperty(this.surface, key, {\n get: () => value.value\n });\n continue;\n }\n \n if (this.actions.has(value)) {\n Object.defineProperty(this.surface, key, { value });\n continue;\n }\n\n this.surface[key] = value;\n }\n\n return this.surface;\n }\n}\n\nexport const defineSurface = (...args) => Surface.create(...args);\nexport const refreshSurface = (surfaceComputed) => {\n if (isSurface(surfaceComputed)) {\n const surfaceInstance = Surface.surfaces.get(surfaceComputed);\n if (surfaceInstance) {\n surfaceInstance.setup();\n }\n }\n}\nexport const definePlugin = (...args) => Surface.createPlugin(...args);\nexport const isSurface = (surfaceComputed) => Surface.surfaces.has(surfaceComputed);\n\nexport const destroySurface = (surfaceComputed) => {\n if (isSurface(surfaceComputed)) {\n Surface.surfaces.delete(surfaceComputed);\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAO,SAASA,EAAaC,EAAU,CACrC,OAAI,OAAO,OAAW,KAAe,OAAO,oBACnC,OAAO,oBAAoBA,EAAU,CAAE,QAAS,GAAI,CAAC,EAI1D,OAAO,OAAW,IAEhB,OAAO,sBACF,OAAO,sBAAsB,IAAM,CACxC,WAAWA,EAAU,CAAC,CACxB,CAAC,EAGI,WAAWA,EAAU,CAAC,GAI3B,OAAOA,GAAa,YACtBA,EAAS,EAEJ,KACT,CCpBO,IAAMC,EAAN,KAAyB,CAC9B,aAAc,CACZ,KAAK,MAAQ,IAAI,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AaD,EAAM,MAAQC,CACnC,CAAC,EAED,QACF,CAEA,GAAI,KAAK,UAAU,IAAID,CAAK,EAAG,CAC7B,OAAO,eAAe,KAAK,QAASa,EAAK,CACvC,IAAK,IAAMb,EAAM,KACnB,CAAC,EACD,QACF,CAEA,GAAI,KAAK,QAAQ,IAAIA,CAAK,EAAG,CAC3B,OAAO,eAAe,KAAK,QAASa,EAAK,CAAE,MAAAb,CAAM,CAAC,EAClD,QACF,CAEA,KAAK,QAAQa,CAAG,EAAIb,CACtB,CAEA,OAAO,KAAK,OACd,CACF,EAEasC,EAAgB,IAAIN,IAASvD,EAAQ,OAAO,GAAGuD,CAAI,EACnDO,EAAkBV,GAAoB,CACjD,GAAIvB,EAAUuB,CAAe,EAAG,CAC9B,IAAMW,EAAkB/D,EAAQ,SAAS,IAAIoD,CAAe,EACxDW,GACFA,EAAgB,MAAM,CAE1B,CACF,EACaC,EAAe,IAAIT,IAASvD,EAAQ,aAAa,GAAGuD,CAAI,EACxD1B,EAAauB,GAAoBpD,EAAQ,SAAS,IAAIoD,CAAe",
|
|
6
|
+
"names": ["nextIdleTick", "callback", "ComputationManager", "reactive", "nextIdleTick", "deadRefs", "ids", "weakRef", "dependant", "ref", "now", "timeElapsed", "reactives", "sortedReactives", "callback", "error", "sorted", "visited", "visiting", "visit", "dependants", "Reactive", "_Reactive", "ComputationManager", "key", "value", "keys", "out", "i", "reactive", "reactorIndex", "cycle", "error", "r", "getter", "effect", "reactives", "deadRefs", "ids", "weakRef", "dependant", "ref", "isReactive", "getter", "Reactive", "addEffect", "effect", "removeEffect", "addContext", "key", "value", "Reactive", "useContext", "keys", "hasContext", "createAdapter", "getter", "path", "isReactive", "snapshotCache", "unsubscribeAll", "subscribers", "getSnapshot", "clone", "listener", "addEffect", "subscriber", "isAsyncFunction", "fn", "Computed", "_Computed", "fn", "config", "computed", "Reactive", "isAsyncFunction", "#getter", "contextValue", "computationId", "value", "resolve", "error", "reject", "createComputed", "destroyComputed", "target", "isComputed", "getter", "isDirtyComputed", "Signal", "_Signal", "initialValue", "config", "signal", "Reactive", "args", "#getter", "error", "createSignal", "destroySignal", "getter", "isSignal", "isDirtySignal", "Subscriber", "_Subscriber", "getter", "fn", "config", "subscriber", "Reactive", "error", "createSubscriber", "destroySubscriber", "isSubscriber", "traversalFunctions", "obj", "path", "createTraversalFunction", "length", "expr", "_", "i", "fn", "traverse", "state", "len", "EMPTY_CACHE", "Surface", "_Surface", "name", "plugin", "setupFn", "options", "instance", "useSurface", "fn", "#createSurface", "pendingReactives", "result", "#setupFromFunction", "#setupFromObject", "#bindSurface", "reactive", "addEffect", "#queueSubscribers", "error", "initial", "cb", "signal", "createSignal", "value", "newValue", "computed", "createComputed", "computedValue", "action", "isSurface", "surface", "reactor", "#destroy", "#processStateValue", "stateConfig", "isDev", "key", "config", "initialValue", "#createAdapter", "#getSnapshot", "subscriber", "#subscribe", "clone", "listener", "#callSubscribers", "snapshot", "path", "#get", "#set", "#dispatch", "overrides", "surfaceComputed", "destroyComputed", "traverse", "args", "oldKeys", "extension", "descriptors", "filteredDescriptors", "entries", "defineSurface", "refreshSurface", "surfaceInstance", "definePlugin"]
|
|
7
7
|
}
|
package/package.json
CHANGED