@vielzeug/ripple 26.10.7 → 26.10.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"ripple.js","names":[],"sources":["../src/errors.ts","../src/runtime.ts","../src/_async.ts","../src/_subscribable.ts","../src/_watch.ts","../src/_default.ts","../src/index.ts"],"sourcesContent":["export class RippleError extends Error {\n constructor(message: string, options?: ErrorOptions) {\n super(message, options);\n this.name = new.target.name;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\nexport class RippleComputedCycleError extends RippleError {}\nexport class RippleDisposedResourceError extends RippleError {}\nexport class RippleDisposedRuntimeError extends RippleError {}\nexport class RippleDisposedScopeError extends RippleError {}\nexport class RippleInfiniteLoopError extends RippleError {}\n","import {\n RippleComputedCycleError,\n RippleDisposedRuntimeError,\n RippleDisposedScopeError,\n RippleInfiniteLoopError,\n} from './errors';\nimport type {\n Cleanup,\n ComputedOptions,\n EffectHandle,\n EffectOptions,\n Readable,\n RippleErrorContext,\n RippleErrorPolicy,\n RippleEvent,\n RippleOptions,\n Scope,\n Signal,\n SignalOptions,\n Unsubscribe,\n} from './types';\n\nexport const REACTIVE = Symbol.for('@vielzeug/ripple/reactive');\nconst MAX_FLUSH_ITERATIONS = 100;\nconst UNSET = Symbol('ripple.unset');\n\ntype Dependency = ReactiveNode<unknown>;\n\n/** Anything that wants to hear that a dependency changed: the only member a producer may call. */\ntype Dependent = {\n onDependencyChanged(): void;\n};\n\n/** A subscribe() listener sink: enqueued as a unit so two subscriptions sharing one\n * callback each fire per flush, while one subscription never fires twice. */\ntype ListenerSink = Dependent & {\n readonly listener: () => void;\n};\n\n/** A dependency-collecting observer (computed or effect). Plain listener sinks need less. */\ntype ObserverNode = Dependent & {\n collecting?: Set<Dependency>;\n readonly dependencies: Set<Dependency>;\n};\n\ntype Owned = {\n dispose(): void;\n setOwner(owner: ScopeNode | undefined): void;\n};\n\nabstract class ReactiveNode<T> {\n readonly [REACTIVE] = true;\n readonly dependents = new Set<Dependent>();\n readonly name: string | undefined;\n protected readonly runtime: ReactiveRuntime;\n\n protected constructor(runtime: ReactiveRuntime, name?: string) {\n this.runtime = runtime;\n this.name = name;\n }\n\n abstract peek(): T;\n abstract get value(): T;\n\n subscribe(listener: () => void): Unsubscribe {\n this.runtime.assertActive();\n this.peek();\n\n // A listener sink never collects dependencies, so it is a bare dependent :\n // no dependency bookkeeping is allocated per subscription.\n const sink: ListenerSink = {\n listener,\n onDependencyChanged: () => this.runtime.enqueueListener(sink),\n };\n\n this.dependents.add(sink);\n\n return () => this.dependents.delete(sink);\n }\n\n protected notify(): void {\n for (const dependent of [...this.dependents]) dependent.onDependencyChanged();\n }\n}\n\nclass SignalNode<T> extends ReactiveNode<T> implements Signal<T> {\n private current: T;\n private readonly equals: (previous: T, next: T) => boolean;\n\n constructor(runtime: ReactiveRuntime, initial: T, options?: SignalOptions<T>) {\n super(runtime, options?.name);\n this.current = initial;\n this.equals = options?.equals ?? Object.is;\n }\n\n get value(): T {\n this.runtime.track(this);\n\n return this.current;\n }\n\n set value(next: T) {\n this.runtime.assertActive();\n\n if (this.equals(this.current, next)) return;\n\n const previous = this.current;\n\n this.current = next;\n this.runtime.emit({ name: this.name, next, previous, type: 'write' });\n this.runtime.propagate(() => this.notify());\n }\n\n peek(): T {\n return this.current;\n }\n\n update(updater: (prev: T) => T): void {\n this.value = updater(this.current);\n }\n}\n\nclass ComputedNode<T> extends ReactiveNode<T> implements ObserverNode, Owned {\n readonly dependencies = new Set<Dependency>();\n private computing = false;\n private disposed = false;\n private dirty = true;\n private current: T | typeof UNSET = UNSET;\n private readonly derive: () => T;\n private readonly equals: (previous: T, next: T) => boolean;\n private owner: ScopeNode | undefined;\n\n constructor(runtime: ReactiveRuntime, derive: () => T, options?: ComputedOptions<T>) {\n super(runtime, options?.name);\n this.derive = derive;\n this.equals = options?.equals ?? Object.is;\n }\n\n get value(): T {\n // Track before refresh: if refresh throws, the consumer still depends on\n // this computed and must be notified when a dependency change might let it\n // succeed. Without this, a first-run failure permanently severs the\n // consumer from the computed.\n this.runtime.track(this);\n this.refresh();\n\n return this.current as T;\n }\n\n peek(): T {\n this.refresh();\n\n return this.current as T;\n }\n\n onDependencyChanged(): void {\n if (this.disposed) return;\n\n if (!this.dirty) this.dirty = true;\n\n if (this.dependents.size > 0) {\n try {\n if (this.refresh()) this.notify();\n } catch (error) {\n this.runtime.report(error, { kind: 'computed', name: this.name });\n }\n }\n }\n\n setOwner(owner: ScopeNode | undefined): void {\n this.owner = owner;\n }\n\n dispose(): void {\n if (this.disposed) return;\n\n this.disposed = true;\n this.owner?.release(this);\n this.owner = undefined;\n this.runtime.clearDependencies(this);\n this.dependents.clear();\n }\n\n private refresh(): boolean {\n if (!this.dirty || this.disposed) return false;\n\n if (this.computing) {\n const label = this.name === undefined ? '' : ` \"${this.name}\"`;\n\n throw new RippleComputedCycleError(`computed cycle detected${label}`);\n }\n\n this.computing = true;\n this.runtime.emit({ name: this.name, type: 'compute' });\n\n try {\n const next = this.runtime.collect(this, this.derive);\n const changed = this.current === UNSET || !this.equals(this.current as T, next);\n\n this.current = next;\n this.dirty = false;\n\n return changed;\n } finally {\n this.computing = false;\n }\n }\n}\n\nclass ScopeNode implements Scope, Owned {\n readonly disposalController = new AbortController();\n readonly owned = new Set<Owned>();\n readonly name: string | undefined;\n private isDisposed = false;\n private owner: ScopeNode | undefined;\n private readonly runtime: ReactiveRuntime;\n\n constructor(runtime: ReactiveRuntime, name?: string) {\n this.runtime = runtime;\n this.name = name;\n }\n\n get disposed(): boolean {\n return this.isDisposed;\n }\n\n get disposalSignal(): AbortSignal {\n return this.disposalController.signal;\n }\n\n own(value: Owned): void {\n value.setOwner(this);\n this.owned.add(value);\n }\n\n release(value: Owned): void {\n this.owned.delete(value);\n }\n\n setOwner(owner: ScopeNode | undefined): void {\n this.owner = owner;\n }\n\n run<T>(fn: () => T): T {\n if (this.isDisposed) throw new RippleDisposedScopeError('Cannot run a disposed scope.');\n\n return this.runtime.withScope(this, fn);\n }\n\n dispose(): void {\n if (this.isDisposed) return;\n\n this.isDisposed = true;\n this.owner?.release(this);\n this.owner = undefined;\n for (const owned of [...this.owned].reverse()) owned.dispose();\n this.owned.clear();\n this.disposalController.abort();\n this.runtime.emit({ name: this.name, node: 'scope', type: 'dispose' });\n }\n\n [Symbol.dispose](): void {\n this.dispose();\n }\n}\n\nclass EffectNode implements ObserverNode, EffectHandle {\n readonly dependencies = new Set<Dependency>();\n readonly disposalController = new AbortController();\n private cleanup: Cleanup | undefined;\n private isDisposed = false;\n private ownershipScope: ScopeNode | undefined;\n private runScope: ScopeNode | undefined;\n private readonly callback: () => Cleanup | undefined;\n private readonly options: EffectOptions | undefined;\n private readonly runtime: ReactiveRuntime;\n\n constructor(runtime: ReactiveRuntime, callback: () => Cleanup | undefined, options?: EffectOptions) {\n this.runtime = runtime;\n this.callback = callback;\n this.options = options;\n }\n\n get disposed(): boolean {\n return this.isDisposed;\n }\n\n get disposalSignal(): AbortSignal {\n return this.disposalController.signal;\n }\n\n setOwner(owner: ScopeNode | undefined): void {\n this.ownershipScope = owner;\n }\n\n onDependencyChanged(): void {\n if (this.isDisposed) return;\n\n this.runtime.enqueue(this);\n }\n\n run(): void {\n if (this.isDisposed) return;\n\n this.runScope?.dispose();\n this.runScope = undefined;\n this.runCleanup();\n this.runtime.emit({ name: this.options?.name, type: 'effect' });\n\n const owner = new ScopeNode(this.runtime);\n\n try {\n const cleanup = this.runtime.withEffectScope(owner, () => this.runtime.collectEffect(this, this.callback));\n\n this.runScope = owner;\n this.cleanup = typeof cleanup === 'function' ? cleanup : undefined;\n if (this.isDisposed) {\n this.runScope.dispose();\n this.runScope = undefined;\n this.runCleanup();\n }\n } catch (error) {\n owner.dispose();\n this.runtime.report(error, { kind: 'effect', name: this.options?.name });\n }\n }\n\n dispose(): void {\n if (this.isDisposed) return;\n\n this.isDisposed = true;\n this.ownershipScope?.release(this);\n this.ownershipScope = undefined;\n this.runScope?.dispose();\n this.runScope = undefined;\n this.runtime.clearDependencies(this);\n this.runCleanup();\n this.disposalController.abort();\n this.runtime.emit({ name: this.options?.name, node: 'effect', type: 'dispose' });\n }\n\n [Symbol.dispose](): void {\n this.dispose();\n }\n\n private runCleanup(): void {\n const cleanup = this.cleanup;\n\n this.cleanup = undefined;\n\n if (cleanup === undefined) return;\n\n try {\n cleanup();\n } catch (error) {\n this.runtime.report(error, { kind: 'cleanup', name: this.options?.name });\n }\n }\n}\n\n/**\n * A runtime owns reactive graph state and lifetime. Separate instances isolate\n * applications and SSR requests without process-wide mutable hooks.\n */\nexport class ReactiveRuntime {\n private activeEffectScope: ScopeNode | undefined;\n private activeObserver: ObserverNode | undefined;\n private activeScope: ScopeNode;\n private isDisposed = false;\n private flushDepth = 0;\n private flushing = false;\n private readonly pending = new Set<EffectNode>();\n private readonly listeners = new Set<ListenerSink>();\n private readonly rootScope: ScopeNode;\n private readonly tappers = new Set<(event: RippleEvent) => void>();\n private readonly errorPolicy: RippleErrorPolicy;\n\n constructor(options?: RippleOptions) {\n this.errorPolicy = options?.errorPolicy ?? 'throw';\n this.rootScope = new ScopeNode(this, 'runtime');\n this.activeScope = this.rootScope;\n }\n\n get disposed(): boolean {\n return this.isDisposed;\n }\n\n get disposalSignal(): AbortSignal {\n return this.rootScope.disposalSignal;\n }\n\n readonly signal = <T>(initial: T, options?: SignalOptions<T>): Signal<T> => {\n this.assertActive();\n\n return new SignalNode(this, initial, options);\n };\n\n readonly computed = <T>(derive: () => T, options?: ComputedOptions<T>): Readable<T> => {\n this.assertActive();\n\n const node = new ComputedNode(this, derive, options);\n\n (this.activeEffectScope ?? this.activeScope).own(node);\n\n return node;\n };\n\n readonly effect = (callback: () => Cleanup | undefined, options?: EffectOptions): EffectHandle => {\n this.assertActive();\n\n const node = new EffectNode(this, callback, options);\n\n (this.activeEffectScope ?? this.activeScope).own(node);\n node.run();\n\n return node;\n };\n\n readonly createScope = (name?: string): Scope => {\n this.assertActive();\n\n const scope = new ScopeNode(this, name);\n\n // Scopes model explicit, caller-owned lifetimes. Unlike effects/computeds created during an\n // effect run, they deliberately attach to the enclosing scope rather than the per-run owner:\n // keyed DOM directives retain item scopes across reconciliation runs and dispose them only\n // when the item itself leaves the collection.\n this.activeScope.own(scope);\n\n return scope;\n };\n\n readonly batch = <T>(fn: () => T): T => {\n this.assertActive();\n\n return this.propagate(fn);\n };\n\n readonly untrack = <T>(fn: () => T): T => {\n this.assertActive();\n\n return this.withObserver(undefined, fn);\n };\n\n /** Runtime observability: see `Ripple.tap()`. */\n readonly tap = (handler: (event: RippleEvent) => void, options?: { signal?: AbortSignal }): Unsubscribe => {\n if (this.isDisposed) return () => {};\n\n const signal = options?.signal;\n\n if (signal?.aborted) {\n this.tappers.delete(handler);\n return () => {};\n }\n\n this.tappers.add(handler);\n\n if (signal) {\n const onAbort = () => this.tappers.delete(handler);\n\n signal.addEventListener('abort', onAbort, { once: true });\n\n return () => {\n this.tappers.delete(handler);\n signal.removeEventListener('abort', onAbort);\n };\n }\n\n return () => this.tappers.delete(handler);\n };\n\n dispose(): void {\n if (this.isDisposed) return;\n\n this.isDisposed = true;\n this.rootScope.dispose();\n this.emit({ node: 'graph', type: 'dispose' });\n this.tappers.clear();\n }\n\n /** Internal node guard: disposed runtimes allow inert reads but reject graph work and mutation. */\n assertActive(): void {\n if (this.isDisposed) throw new RippleDisposedRuntimeError('Cannot use a disposed Ripple runtime.');\n }\n\n track(node: Dependency): void {\n const observer = this.activeObserver;\n\n if (observer?.collecting === undefined) return;\n\n observer.collecting.add(node);\n }\n\n clearDependencies(observer: ObserverNode): void {\n for (const dependency of observer.dependencies) dependency.dependents.delete(observer);\n observer.dependencies.clear();\n }\n\n collect<T>(observer: ObserverNode, fn: () => T): T {\n // On first run (no prior dependencies), commit partial dependencies even if\n // derive throws, otherwise the computed would have zero dependencies and never\n // be notified when its source changes, permanently stuck until a manual read.\n // On subsequent runs, keep previous dependencies (tested behavior).\n return this.collectWith(observer, fn, observer.dependencies.size === 0);\n }\n\n collectEffect<T>(observer: ObserverNode, fn: () => T): T {\n return this.collectWith(observer, fn, true);\n }\n\n withEffectScope<T>(scope: ScopeNode, fn: () => T): T {\n const previous = this.activeEffectScope;\n\n this.activeEffectScope = scope;\n\n try {\n return fn();\n } finally {\n this.activeEffectScope = previous;\n }\n }\n\n withObserver<T>(observer: ObserverNode | undefined, fn: () => T): T {\n const previous = this.activeObserver;\n\n this.activeObserver = observer;\n\n try {\n return fn();\n } finally {\n this.activeObserver = previous;\n }\n }\n\n withScope<T>(scope: ScopeNode, fn: () => T): T {\n const previousEffectScope = this.activeEffectScope;\n const previousScope = this.activeScope;\n\n this.activeEffectScope = undefined;\n this.activeScope = scope;\n\n try {\n return fn();\n } finally {\n this.activeEffectScope = previousEffectScope;\n this.activeScope = previousScope;\n }\n }\n\n enqueue(effect: EffectNode): void {\n this.pending.add(effect);\n\n if (this.flushDepth === 0) this.flush();\n }\n\n enqueueListener(sink: ListenerSink): void {\n this.listeners.add(sink);\n\n if (this.flushDepth === 0) this.flush();\n }\n\n propagate<T>(fn: () => T): T {\n this.flushDepth++;\n\n try {\n return fn();\n } finally {\n this.flushDepth--;\n\n if (this.flushDepth === 0) this.flush();\n }\n }\n\n emit(event: RippleEvent): void {\n if (this.tappers.size === 0) return;\n\n for (const tapper of this.tappers) {\n try {\n tapper(event);\n } catch {\n // Observability must not affect runtime behavior.\n }\n }\n }\n\n report(error: unknown, context: RippleErrorContext): void {\n this.emit({ context, error, type: 'error' });\n\n if (this.errorPolicy === 'throw') {\n queueMicrotask(() => {\n throw error;\n });\n }\n }\n\n private collectWith<T>(observer: ObserverNode, fn: () => T, commitOnError: boolean): T {\n const previousObserver = this.activeObserver;\n const dependencies = new Set<Dependency>();\n\n observer.collecting = dependencies;\n this.activeObserver = observer;\n\n try {\n const result = fn();\n\n this.commitDependencies(observer, dependencies);\n\n return result;\n } catch (error) {\n if (commitOnError) this.commitDependencies(observer, dependencies);\n\n throw error;\n } finally {\n observer.collecting = undefined;\n this.activeObserver = previousObserver;\n }\n }\n\n private commitDependencies(observer: ObserverNode, next: Set<Dependency>): void {\n for (const dependency of observer.dependencies) {\n if (!next.has(dependency)) dependency.dependents.delete(observer);\n }\n\n for (const dependency of next) {\n if (!observer.dependencies.has(dependency)) dependency.dependents.add(observer);\n }\n\n observer.dependencies.clear();\n for (const dependency of next) observer.dependencies.add(dependency);\n }\n\n private flush(): void {\n if (this.flushing) return;\n\n this.flushing = true;\n\n let iterations = 0;\n\n try {\n while (this.pending.size > 0 || this.listeners.size > 0) {\n if (++iterations > MAX_FLUSH_ITERATIONS) {\n throw new RippleInfiniteLoopError(`infinite reactive flush (>${MAX_FLUSH_ITERATIONS} iterations)`);\n }\n\n const effects = [...this.pending];\n const listeners = [...this.listeners];\n\n this.pending.clear();\n this.listeners.clear();\n\n for (const effect of effects) effect.run();\n\n for (const sink of listeners) {\n try {\n sink.listener();\n } catch (error) {\n this.report(error, { kind: 'listener' });\n }\n }\n }\n } finally {\n this.flushing = false;\n }\n }\n}\n\nexport const isReactive = <T>(value: T | Readable<T>): value is Readable<T> => {\n if (typeof value !== 'object' || value === null || (value as { [REACTIVE]?: unknown })[REACTIVE] !== true)\n return false;\n\n const candidate = value as { peek?: unknown; subscribe?: unknown; value?: unknown };\n\n return 'value' in candidate && typeof candidate.peek === 'function' && typeof candidate.subscribe === 'function';\n};\n","import { RippleDisposedResourceError } from './errors';\nimport { REACTIVE } from './runtime';\nimport type { Disposable, EffectHandle, Readable, Signal } from './types';\n\nexport type AsyncState<T> =\n | { readonly previous?: T; readonly status: 'pending' }\n | { readonly status: 'success'; readonly value: T }\n | { readonly error: unknown; readonly previous?: T; readonly status: 'error' };\n\nexport interface Resource<T> extends Readable<AsyncState<T>>, Disposable {\n reload(): void;\n}\n\nexport type ResourceOptions = {\n name?: string;\n};\n\ntype AsyncRuntime = {\n effect(callback: () => undefined | (() => void), options?: { name?: string }): EffectHandle;\n signal<T>(initial: T, options?: { name?: string }): Signal<T>;\n};\n\n/** Resource only depends on primitive runtime methods; graph binding stays private. */\nexport const createResource =\n (runtime: AsyncRuntime) =>\n <Source, Value>(\n source: () => Source,\n loader: (source: Source, context: { readonly signal: AbortSignal }) => Promise<Value>,\n options?: ResourceOptions,\n ): Resource<Value> => {\n const state = runtime.signal<AsyncState<Value>>({ status: 'pending' }, { name: options?.name });\n const reloadEpoch = runtime.signal(0);\n let active: AbortController | undefined;\n let hasPrevious = false;\n let previousValue: Value | undefined;\n\n const run = (): void => {\n void reloadEpoch.value;\n active?.abort();\n\n let input: Source;\n\n try {\n input = source();\n } catch (error) {\n state.value = hasPrevious\n ? { error, previous: previousValue as Value, status: 'error' }\n : { error, status: 'error' };\n\n return;\n }\n\n const next = new AbortController();\n\n active = next;\n state.value = hasPrevious ? { previous: previousValue as Value, status: 'pending' } : { status: 'pending' };\n\n let request: Promise<Value>;\n\n try {\n request = Promise.resolve(loader(input, { signal: next.signal }));\n } catch (error) {\n request = Promise.reject(error);\n }\n\n void request.then(\n (value) => {\n if (!stop.disposed && !next.signal.aborted) {\n hasPrevious = true;\n previousValue = value;\n state.value = { status: 'success', value };\n }\n },\n (error: unknown) => {\n if (!stop.disposed && !next.signal.aborted) {\n state.value = hasPrevious\n ? { error, previous: previousValue as Value, status: 'error' }\n : { error, status: 'error' };\n }\n },\n );\n };\n\n const stop = runtime.effect(\n () => {\n run();\n\n return () => active?.abort();\n },\n { name: options?.name },\n );\n\n const assertActive = (): void => {\n if (stop.disposed) throw new RippleDisposedResourceError('Cannot use a disposed resource.');\n };\n const resource: Resource<Value> = {\n get disposalSignal() {\n return stop.disposalSignal;\n },\n dispose: () => stop.dispose(),\n get disposed() {\n return stop.disposed;\n },\n get name() {\n return state.name;\n },\n peek: () => state.peek(),\n reload: () => {\n assertActive();\n reloadEpoch.value = reloadEpoch.peek() + 1;\n },\n subscribe: (listener) => {\n assertActive();\n return state.subscribe(listener);\n },\n [Symbol.dispose]() {\n this.dispose();\n },\n get value() {\n return state.value;\n },\n };\n\n Object.defineProperty(resource, REACTIVE, { value: true });\n\n return resource;\n };\n","import { RippleError } from './errors';\nimport { REACTIVE } from './runtime';\nimport type { Disposable, EffectHandle, Readable, Signal, Subscribable } from './types';\n\ntype BridgeRuntime = {\n effect(callback: () => undefined | (() => void), options?: { name?: string }): EffectHandle;\n signal<T>(initial: T, options?: { name?: string }): Signal<T>;\n};\n\nexport type BridgedReadable<T> = Readable<T> & Disposable;\nexport type FromSubscribableOptions = { name?: string; signal?: AbortSignal };\n\nexport const createFromSubscribable =\n (runtime: BridgeRuntime) =>\n <T>(source: Subscribable<T>, options?: FromSubscribableOptions): BridgedReadable<T> => {\n const node = runtime.signal<T>(source.getSnapshot(), { name: options?.name });\n const stop = runtime.effect(\n () => {\n const sync = () => {\n node.value = source.getSnapshot();\n };\n let unsubscribe: (() => void) | undefined;\n\n try {\n unsubscribe = source.subscribe(sync);\n sync();\n } catch (error) {\n unsubscribe?.();\n throw error;\n }\n\n return unsubscribe;\n },\n { name: options?.name },\n );\n const abort = () => stop.dispose();\n\n options?.signal?.addEventListener('abort', abort, { once: true });\n if (options?.signal?.aborted) stop.dispose();\n\n const assertActive = (): void => {\n if (stop.disposed) throw new RippleError('Cannot subscribe to a disposed bridge.');\n };\n const dispose = (): void => {\n options?.signal?.removeEventListener('abort', abort);\n stop.dispose();\n };\n const readable: BridgedReadable<T> = {\n get disposalSignal() {\n return stop.disposalSignal;\n },\n dispose,\n get disposed() {\n return stop.disposed;\n },\n get name() {\n return node.name;\n },\n peek: () => node.peek(),\n subscribe(listener) {\n assertActive();\n return node.subscribe(listener);\n },\n [Symbol.dispose]: dispose,\n get value() {\n return node.value;\n },\n };\n\n Object.defineProperty(readable, REACTIVE, { value: true });\n return readable;\n };\n","import type { EffectHandle, Equality, Readable } from './types';\n\nexport type WatchOptions<T> = {\n equals?: Equality<T>;\n immediate?: boolean;\n name?: string;\n};\n\ntype WatchRuntime = {\n effect(callback: () => undefined | (() => void), options?: { name?: string }): EffectHandle;\n untrack<T>(fn: () => T): T;\n};\n\nexport const createWatch =\n (runtime: WatchRuntime) =>\n <T>(\n source: Readable<T> | (() => T),\n callback: (value: T, previous: T | undefined) => void,\n options?: WatchOptions<T>,\n ): EffectHandle => {\n const read = typeof source === 'function' ? source : () => source.value;\n const equals = options?.equals ?? Object.is;\n let initial = true;\n let previous: T | undefined;\n\n return runtime.effect(\n () => {\n const value = read();\n\n if (initial) {\n initial = false;\n previous = value;\n\n if (options?.immediate) runtime.untrack(() => callback(value, undefined));\n\n return;\n }\n\n if (equals(previous as T, value)) return;\n\n const oldValue = previous;\n\n previous = value;\n runtime.untrack(() => callback(value, oldValue));\n },\n { name: options?.name },\n );\n };\n","import { createResource, type Resource, type ResourceOptions } from './_async';\nimport { type BridgedReadable, createFromSubscribable, type FromSubscribableOptions } from './_subscribable';\nimport { createWatch, type WatchOptions } from './_watch';\nimport { ReactiveRuntime } from './runtime';\nimport type {\n Cleanup,\n ComputedOptions,\n Disposable,\n EffectHandle,\n EffectOptions,\n Readable,\n RippleEvent,\n RippleOptions,\n Scope,\n Signal,\n SignalOptions,\n Subscribable,\n Unsubscribe,\n} from './types';\n\nexport interface Ripple extends Disposable {\n batch<T>(fn: () => T): T;\n computed<T>(derive: () => T, options?: ComputedOptions<T>): Readable<T>;\n createScope(name?: string): Scope;\n effect(callback: () => Cleanup | undefined, options?: EffectOptions): EffectHandle;\n fromSubscribable<T>(source: Subscribable<T>, options?: FromSubscribableOptions): BridgedReadable<T>;\n resource<Source, Value>(\n source: () => Source,\n loader: (source: Source, context: { readonly signal: AbortSignal }) => Promise<Value>,\n options?: ResourceOptions,\n ): Resource<Value>;\n signal<T>(initial: T, options?: SignalOptions<T>): Signal<T>;\n tap(handler: (event: RippleEvent) => void, options?: { signal?: AbortSignal }): Unsubscribe;\n untrack<T>(fn: () => T): T;\n watch<T>(\n source: Readable<T> | (() => T),\n callback: (value: T, previous: T | undefined) => void,\n options?: WatchOptions<T>,\n ): EffectHandle;\n}\n\n/**\n * Creates one complete reactive graph with its own ownership boundary. All\n * factories on the returned object share its runtime. Use this for tests, SSR\n * requests, embedded applications, or independently disposable features.\n * `dispose()` is terminal: create a new graph for a new lifetime.\n */\nexport const createRipple = (options?: RippleOptions): Ripple => {\n const runtime = new ReactiveRuntime(options);\n const fromSubscribable = createFromSubscribable(runtime);\n const resource = createResource(runtime);\n\n return {\n batch: runtime.batch,\n computed: runtime.computed,\n createScope: runtime.createScope,\n get disposalSignal() {\n return runtime.disposalSignal;\n },\n dispose: () => runtime.dispose(),\n get disposed() {\n return runtime.disposed;\n },\n effect: runtime.effect,\n fromSubscribable,\n resource,\n signal: runtime.signal,\n tap: runtime.tap,\n untrack: runtime.untrack,\n watch: createWatch(runtime),\n [Symbol.dispose]: () => runtime.dispose(),\n };\n};\n\n/**\n * The shared default reactive graph: process-lifetime. Root helpers\n * (`signal`, `computed`, `effect`, `batch`, `createScope`, `untrack`, `watch`, `resource`, `fromSubscribable`)\n * are re-exported from the package root as bound methods on this single graph\n * instance. Use these only when the application has one graph for its entire\n * lifetime; they are never disposed. For isolated, disposable graphs (tests,\n * SSR, embedded features) use `createRipple()` instead.\n */\nexport const defaultRipple = createRipple();\n","export type { AsyncState, Resource, ResourceOptions } from './_async';\nexport { createRipple, type Ripple } from './_default';\nexport type { BridgedReadable, FromSubscribableOptions } from './_subscribable';\nexport type { WatchOptions } from './_watch';\nexport {\n RippleComputedCycleError,\n RippleDisposedResourceError,\n RippleDisposedRuntimeError,\n RippleDisposedScopeError,\n RippleError,\n RippleInfiniteLoopError,\n} from './errors';\nexport { isReactive } from './runtime';\nexport type {\n Cleanup,\n ComputedOptions,\n Disposable,\n EffectHandle,\n EffectOptions,\n Equality,\n Readable,\n RippleErrorContext,\n RippleErrorPolicy,\n RippleEvent,\n RippleOptions,\n Scope,\n Signal,\n SignalOptions,\n Subscribable,\n Unsubscribe,\n} from './types';\n\nimport { defaultRipple } from './_default';\n\nexport const signal = defaultRipple.signal;\nexport const computed = defaultRipple.computed;\nexport const effect = defaultRipple.effect;\nexport const batch = defaultRipple.batch;\nexport const createScope = defaultRipple.createScope;\nexport const untrack = defaultRipple.untrack;\nexport const watch = defaultRipple.watch;\nexport const resource = defaultRipple.resource;\nexport const fromSubscribable = defaultRipple.fromSubscribable;\n"],"mappings":"AAAA,IAAa,YAAb,cAAiC,KAAM,CACrC,YAAY,EAAiB,EAAwB,CACnD,MAAM,EAAS,CAAO,EACtB,KAAK,KAAO,WAAW,KACvB,OAAO,eAAe,KAAM,WAAW,SAAS,CAClD,CACF,EAEa,yBAAb,cAA8C,WAAY,CAAC,EAC9C,4BAAb,cAAiD,WAAY,CAAC,EACjD,2BAAb,cAAgD,WAAY,CAAC,EAChD,yBAAb,cAA8C,WAAY,CAAC,EAC9C,wBAAb,cAA6C,WAAY,CAAC,ECU7C,EAAW,OAAO,IAAI,2BAA2B,EACxD,EAAuB,IACvB,EAAQ,OAAO,cAAc,EA0BpB,aAAf,KAA+B,CAC7B,CAAU,GAAY,GACtB,WAAsB,IAAI,IAC1B,KACA,QAEA,YAAsB,EAA0B,EAAe,CAC7D,KAAK,QAAU,EACf,KAAK,KAAO,CACd,CAKA,UAAU,EAAmC,CAC3C,KAAK,QAAQ,aAAa,EAC1B,KAAK,KAAK,EAIV,IAAM,EAAqB,CACzB,WACA,wBAA2B,KAAK,QAAQ,gBAAgB,CAAI,CAC9D,EAIA,OAFA,KAAK,WAAW,IAAI,CAAI,MAEX,KAAK,WAAW,OAAO,CAAI,CAC1C,CAEA,QAAyB,CACvB,IAAK,IAAM,IAAa,CAAC,GAAG,KAAK,UAAU,EAAG,EAAU,oBAAoB,CAC9E,CACF,EAEM,WAAN,cAA4B,YAAqC,CAC/D,QACA,OAEA,YAAY,EAA0B,EAAY,EAA4B,CAC5E,MAAM,EAAS,GAAS,IAAI,EAC5B,KAAK,QAAU,EACf,KAAK,OAAS,GAAS,QAAU,OAAO,EAC1C,CAEA,IAAI,OAAW,CAGb,OAFA,KAAK,QAAQ,MAAM,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Ac,OACvB,EAAW,EAAc,SACzB,EAAS,EAAc,OACvB,EAAQ,EAAc,MACtB,EAAc,EAAc,YAC5B,EAAU,EAAc,QACxB,EAAQ,EAAc,MACtB,EAAW,EAAc,SACzB,EAAmB,EAAc"}
1
+ {"version":3,"file":"ripple.js","names":[],"sources":["../src/errors.ts","../src/runtime.ts","../src/_async.ts","../src/_subscribable.ts","../src/_watch.ts","../src/_default.ts","../src/index.ts"],"sourcesContent":["export class RippleError extends Error {\n constructor(message: string, options?: ErrorOptions) {\n super(message, options);\n this.name = new.target.name;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/** User code that never settles: a computed cycle or a runaway flush loop. */\nexport class RippleCycleError extends RippleError {}\n\n/** Any operation against a disposed runtime, scope, resource, or bridge. */\nexport class RippleDisposedError extends RippleError {}\n","import { RippleCycleError, RippleDisposedError } from './errors';\nimport type {\n Cleanup,\n ComputedOptions,\n EffectHandle,\n EffectOptions,\n Readable,\n RippleErrorContext,\n RippleOptions,\n Scope,\n Signal,\n SignalOptions,\n Unsubscribe,\n} from './types';\n\nexport const REACTIVE = Symbol.for('@vielzeug/ripple/reactive');\nconst MAX_FLUSH_ITERATIONS = 100;\nconst UNSET = Symbol('ripple.unset');\n\ntype Dependency = ReactiveNode<unknown>;\n\n/** Anything that wants to hear that a dependency changed: the only member a producer may call. */\ntype Dependent = {\n onDependencyChanged(): void;\n};\n\n/** A subscribe() listener sink: enqueued as a unit so two subscriptions sharing one\n * callback each fire per flush, while one subscription never fires twice. */\ntype ListenerSink = Dependent & {\n readonly listener: () => void;\n};\n\n/** A dependency-collecting observer (computed or effect). Plain listener sinks need less. */\ntype ObserverNode = Dependent & {\n collecting?: Set<Dependency>;\n readonly dependencies: Set<Dependency>;\n};\n\ntype Owned = {\n dispose(): void;\n setOwner(owner: ScopeNode | undefined): void;\n};\n\nabstract class ReactiveNode<T> {\n readonly [REACTIVE] = true;\n readonly dependents = new Set<Dependent>();\n readonly name: string | undefined;\n protected readonly runtime: ReactiveRuntime;\n\n protected constructor(runtime: ReactiveRuntime, name?: string) {\n this.runtime = runtime;\n this.name = name;\n }\n\n abstract peek(): T;\n abstract get value(): T;\n\n subscribe(listener: () => void): Unsubscribe {\n this.runtime.assertActive();\n this.peek();\n\n // A listener sink never collects dependencies, so it is a bare dependent :\n // no dependency bookkeeping is allocated per subscription.\n const sink: ListenerSink = {\n listener,\n onDependencyChanged: () => this.runtime.enqueueListener(sink),\n };\n\n this.dependents.add(sink);\n\n return () => this.dependents.delete(sink);\n }\n\n protected notify(): void {\n for (const dependent of [...this.dependents]) dependent.onDependencyChanged();\n }\n}\n\nclass SignalNode<T> extends ReactiveNode<T> implements Signal<T> {\n private current: T;\n private readonly equals: (previous: T, next: T) => boolean;\n\n constructor(runtime: ReactiveRuntime, initial: T, options?: SignalOptions<T>) {\n super(runtime, options?.name);\n this.current = initial;\n this.equals = options?.equals ?? Object.is;\n }\n\n get value(): T {\n this.runtime.track(this);\n\n return this.current;\n }\n\n set value(next: T) {\n this.runtime.assertActive();\n\n if (this.equals(this.current, next)) return;\n\n this.current = next;\n this.runtime.propagate(() => this.notify());\n }\n\n peek(): T {\n return this.current;\n }\n\n update(updater: (prev: T) => T): void {\n this.value = updater(this.current);\n }\n}\n\nclass ComputedNode<T> extends ReactiveNode<T> implements ObserverNode, Owned {\n readonly dependencies = new Set<Dependency>();\n private computing = false;\n private disposed = false;\n private dirty = true;\n private current: T | typeof UNSET = UNSET;\n private readonly derive: () => T;\n private readonly equals: (previous: T, next: T) => boolean;\n private owner: ScopeNode | undefined;\n\n constructor(runtime: ReactiveRuntime, derive: () => T, options?: ComputedOptions<T>) {\n super(runtime, options?.name);\n this.derive = derive;\n this.equals = options?.equals ?? Object.is;\n }\n\n get value(): T {\n // Track before refresh: if refresh throws, the consumer still depends on\n // this computed and must be notified when a dependency change might let it\n // succeed. Without this, a first-run failure permanently severs the\n // consumer from the computed.\n this.runtime.track(this);\n this.refresh();\n\n return this.evaluated();\n }\n\n peek(): T {\n this.refresh();\n\n return this.evaluated();\n }\n\n private evaluated(): T {\n if (this.current === UNSET) {\n const label = this.name === undefined ? '' : ` \"${this.name}\"`;\n\n throw new RippleDisposedError(`computed${label} was disposed before it was ever evaluated`);\n }\n\n return this.current as T;\n }\n\n onDependencyChanged(): void {\n if (this.disposed) return;\n\n if (!this.dirty) this.dirty = true;\n\n if (this.dependents.size > 0) {\n try {\n if (this.refresh()) this.notify();\n } catch (error) {\n this.runtime.report(error, { kind: 'computed', name: this.name });\n }\n }\n }\n\n setOwner(owner: ScopeNode | undefined): void {\n this.owner = owner;\n }\n\n dispose(): void {\n if (this.disposed) return;\n\n this.disposed = true;\n this.owner?.release(this);\n this.owner = undefined;\n this.runtime.clearDependencies(this);\n this.dependents.clear();\n }\n\n private refresh(): boolean {\n if (!this.dirty || this.disposed) return false;\n\n if (this.computing) {\n const label = this.name === undefined ? '' : ` \"${this.name}\"`;\n\n throw new RippleCycleError(`computed cycle detected${label}`);\n }\n\n this.computing = true;\n\n try {\n const next = this.runtime.collect(this, this.derive);\n const changed = this.current === UNSET || !this.equals(this.current as T, next);\n\n this.current = next;\n this.dirty = false;\n\n return changed;\n } finally {\n this.computing = false;\n }\n }\n}\n\nclass ScopeNode implements Scope, Owned {\n readonly disposalController = new AbortController();\n readonly owned = new Set<Owned>();\n readonly name: string | undefined;\n private isDisposed = false;\n private owner: ScopeNode | undefined;\n private readonly runtime: ReactiveRuntime;\n\n constructor(runtime: ReactiveRuntime, name?: string) {\n this.runtime = runtime;\n this.name = name;\n }\n\n get disposed(): boolean {\n return this.isDisposed;\n }\n\n get disposalSignal(): AbortSignal {\n return this.disposalController.signal;\n }\n\n own(value: Owned): void {\n value.setOwner(this);\n this.owned.add(value);\n }\n\n release(value: Owned): void {\n this.owned.delete(value);\n }\n\n setOwner(owner: ScopeNode | undefined): void {\n this.owner = owner;\n }\n\n run<T>(fn: () => T): T {\n if (this.isDisposed) throw new RippleDisposedError('Cannot run a disposed scope.');\n\n return this.runtime.withScope(this, fn);\n }\n\n dispose(): void {\n if (this.isDisposed) return;\n\n this.isDisposed = true;\n this.owner?.release(this);\n this.owner = undefined;\n for (const owned of [...this.owned].reverse()) owned.dispose();\n this.owned.clear();\n this.disposalController.abort();\n }\n\n [Symbol.dispose](): void {\n this.dispose();\n }\n}\n\nclass EffectNode implements ObserverNode, EffectHandle {\n readonly dependencies = new Set<Dependency>();\n readonly disposalController = new AbortController();\n private cleanup: Cleanup | undefined;\n private isDisposed = false;\n private ownershipScope: ScopeNode | undefined;\n private runScope: ScopeNode | undefined;\n private readonly callback: () => Cleanup | undefined;\n private readonly options: EffectOptions | undefined;\n private readonly runtime: ReactiveRuntime;\n\n constructor(runtime: ReactiveRuntime, callback: () => Cleanup | undefined, options?: EffectOptions) {\n this.runtime = runtime;\n this.callback = callback;\n this.options = options;\n }\n\n get disposed(): boolean {\n return this.isDisposed;\n }\n\n get disposalSignal(): AbortSignal {\n return this.disposalController.signal;\n }\n\n setOwner(owner: ScopeNode | undefined): void {\n this.ownershipScope = owner;\n }\n\n onDependencyChanged(): void {\n if (this.isDisposed) return;\n\n this.runtime.enqueue(this);\n }\n\n run(): void {\n if (this.isDisposed) return;\n\n this.runScope?.dispose();\n this.runScope = undefined;\n this.runCleanup();\n\n const owner = new ScopeNode(this.runtime);\n\n try {\n const cleanup = this.runtime.withEffectScope(owner, () => this.runtime.collectEffect(this, this.callback));\n\n this.runScope = owner;\n this.cleanup = typeof cleanup === 'function' ? cleanup : undefined;\n if (this.isDisposed) {\n this.runScope.dispose();\n this.runScope = undefined;\n this.runCleanup();\n }\n } catch (error) {\n owner.dispose();\n this.runtime.report(error, { kind: 'effect', name: this.options?.name });\n }\n }\n\n dispose(): void {\n if (this.isDisposed) return;\n\n this.isDisposed = true;\n this.ownershipScope?.release(this);\n this.ownershipScope = undefined;\n this.runScope?.dispose();\n this.runScope = undefined;\n this.runtime.clearDependencies(this);\n this.runCleanup();\n this.disposalController.abort();\n }\n\n [Symbol.dispose](): void {\n this.dispose();\n }\n\n private runCleanup(): void {\n const cleanup = this.cleanup;\n\n this.cleanup = undefined;\n\n if (cleanup === undefined) return;\n\n try {\n cleanup();\n } catch (error) {\n this.runtime.report(error, { kind: 'cleanup', name: this.options?.name });\n }\n }\n}\n\n/**\n * A runtime owns reactive graph state and lifetime. Separate instances isolate\n * applications and SSR requests without process-wide mutable hooks.\n */\nexport class ReactiveRuntime {\n private activeEffectScope: ScopeNode | undefined;\n private activeObserver: ObserverNode | undefined;\n private activeScope: ScopeNode;\n private isDisposed = false;\n private flushDepth = 0;\n private flushing = false;\n private readonly pending = new Set<EffectNode>();\n private readonly listeners = new Set<ListenerSink>();\n private readonly rootScope: ScopeNode;\n private readonly onError: (error: unknown, context: RippleErrorContext) => void;\n\n constructor(options?: RippleOptions) {\n this.onError =\n options?.onError ??\n ((error) => {\n queueMicrotask(() => {\n throw error;\n });\n });\n this.rootScope = new ScopeNode(this, 'runtime');\n this.activeScope = this.rootScope;\n }\n\n get disposed(): boolean {\n return this.isDisposed;\n }\n\n get disposalSignal(): AbortSignal {\n return this.rootScope.disposalSignal;\n }\n\n readonly signal = <T>(initial: T, options?: SignalOptions<T>): Signal<T> => {\n this.assertActive();\n\n return new SignalNode(this, initial, options);\n };\n\n readonly computed = <T>(derive: () => T, options?: ComputedOptions<T>): Readable<T> => {\n this.assertActive();\n\n const node = new ComputedNode(this, derive, options);\n\n (this.activeEffectScope ?? this.activeScope).own(node);\n\n return node;\n };\n\n readonly effect = (callback: () => Cleanup | undefined, options?: EffectOptions): EffectHandle => {\n this.assertActive();\n\n const node = new EffectNode(this, callback, options);\n\n (this.activeEffectScope ?? this.activeScope).own(node);\n node.run();\n\n return node;\n };\n\n readonly createScope = (name?: string): Scope => {\n this.assertActive();\n\n const scope = new ScopeNode(this, name);\n\n // Scopes model explicit, caller-owned lifetimes. Unlike effects/computeds created during an\n // effect run, they deliberately attach to the enclosing scope rather than the per-run owner:\n // keyed DOM directives retain item scopes across reconciliation runs and dispose them only\n // when the item itself leaves the collection.\n this.activeScope.own(scope);\n\n return scope;\n };\n\n readonly batch = <T>(fn: () => T): T => {\n this.assertActive();\n\n return this.propagate(fn);\n };\n\n readonly untrack = <T>(fn: () => T): T => {\n this.assertActive();\n\n return this.withObserver(undefined, fn);\n };\n\n dispose(): void {\n if (this.isDisposed) return;\n\n this.isDisposed = true;\n this.rootScope.dispose();\n }\n\n /** Internal node guard: disposed runtimes allow inert reads but reject graph work and mutation. */\n assertActive(): void {\n if (this.isDisposed) throw new RippleDisposedError('Cannot use a disposed Ripple runtime.');\n }\n\n track(node: Dependency): void {\n const observer = this.activeObserver;\n\n if (observer?.collecting === undefined) return;\n\n observer.collecting.add(node);\n }\n\n clearDependencies(observer: ObserverNode): void {\n for (const dependency of observer.dependencies) dependency.dependents.delete(observer);\n observer.dependencies.clear();\n }\n\n collect<T>(observer: ObserverNode, fn: () => T): T {\n // On first run (no prior dependencies), commit partial dependencies even if\n // derive throws, otherwise the computed would have zero dependencies and never\n // be notified when its source changes, permanently stuck until a manual read.\n // On subsequent runs, keep previous dependencies (tested behavior).\n return this.collectWith(observer, fn, observer.dependencies.size === 0);\n }\n\n collectEffect<T>(observer: ObserverNode, fn: () => T): T {\n return this.collectWith(observer, fn, true);\n }\n\n withEffectScope<T>(scope: ScopeNode, fn: () => T): T {\n const previous = this.activeEffectScope;\n\n this.activeEffectScope = scope;\n\n try {\n return fn();\n } finally {\n this.activeEffectScope = previous;\n }\n }\n\n withObserver<T>(observer: ObserverNode | undefined, fn: () => T): T {\n const previous = this.activeObserver;\n\n this.activeObserver = observer;\n\n try {\n return fn();\n } finally {\n this.activeObserver = previous;\n }\n }\n\n withScope<T>(scope: ScopeNode, fn: () => T): T {\n const previousEffectScope = this.activeEffectScope;\n const previousScope = this.activeScope;\n\n this.activeEffectScope = undefined;\n this.activeScope = scope;\n\n try {\n return fn();\n } finally {\n this.activeEffectScope = previousEffectScope;\n this.activeScope = previousScope;\n }\n }\n\n enqueue(effect: EffectNode): void {\n this.pending.add(effect);\n\n if (this.flushDepth === 0) this.flush();\n }\n\n enqueueListener(sink: ListenerSink): void {\n this.listeners.add(sink);\n\n if (this.flushDepth === 0) this.flush();\n }\n\n propagate<T>(fn: () => T): T {\n this.flushDepth++;\n\n try {\n return fn();\n } finally {\n this.flushDepth--;\n\n if (this.flushDepth === 0) this.flush();\n }\n }\n\n report(error: unknown, context: RippleErrorContext): void {\n try {\n this.onError(error, context);\n } catch {\n // A failing error handler must not corrupt the graph or mask the\n // original failure; the default handler rethrows asynchronously instead.\n }\n }\n\n private collectWith<T>(observer: ObserverNode, fn: () => T, commitOnError: boolean): T {\n const previousObserver = this.activeObserver;\n const dependencies = new Set<Dependency>();\n\n observer.collecting = dependencies;\n this.activeObserver = observer;\n\n try {\n const result = fn();\n\n this.commitDependencies(observer, dependencies);\n\n return result;\n } catch (error) {\n if (commitOnError) this.commitDependencies(observer, dependencies);\n\n throw error;\n } finally {\n observer.collecting = undefined;\n this.activeObserver = previousObserver;\n }\n }\n\n private commitDependencies(observer: ObserverNode, next: Set<Dependency>): void {\n for (const dependency of observer.dependencies) {\n if (!next.has(dependency)) dependency.dependents.delete(observer);\n }\n\n for (const dependency of next) {\n if (!observer.dependencies.has(dependency)) dependency.dependents.add(observer);\n }\n\n observer.dependencies.clear();\n for (const dependency of next) observer.dependencies.add(dependency);\n }\n\n private flush(): void {\n if (this.flushing) return;\n\n this.flushing = true;\n\n let iterations = 0;\n\n try {\n while (this.pending.size > 0 || this.listeners.size > 0) {\n if (++iterations > MAX_FLUSH_ITERATIONS) {\n // A runaway effect (one that keeps re-triggering itself): report it\n // through the error channel and abandon this flush. Throwing from\n // here would unwind into the innocent write site that happened to\n // trigger the flush, after its value was already applied.\n this.report(new RippleCycleError(`infinite reactive flush (>${MAX_FLUSH_ITERATIONS} iterations)`), {\n kind: 'flush',\n });\n this.pending.clear();\n this.listeners.clear();\n break;\n }\n\n const effects = [...this.pending];\n const listeners = [...this.listeners];\n\n this.pending.clear();\n this.listeners.clear();\n\n for (const effect of effects) effect.run();\n\n for (const sink of listeners) {\n try {\n sink.listener();\n } catch (error) {\n this.report(error, { kind: 'listener' });\n }\n }\n }\n } finally {\n this.flushing = false;\n }\n }\n}\n\nexport const isReactive = <T>(value: T | Readable<T>): value is Readable<T> => {\n if (typeof value !== 'object' || value === null || (value as { [REACTIVE]?: unknown })[REACTIVE] !== true)\n return false;\n\n const candidate = value as { peek?: unknown; subscribe?: unknown; value?: unknown };\n\n return 'value' in candidate && typeof candidate.peek === 'function' && typeof candidate.subscribe === 'function';\n};\n","import { RippleDisposedError } from './errors';\nimport { REACTIVE } from './runtime';\nimport type { Disposable, EffectHandle, Readable, Signal } from './types';\n\nexport type AsyncState<T> =\n | { readonly previous?: T; readonly status: 'pending' }\n | { readonly status: 'success'; readonly value: T }\n | { readonly error: unknown; readonly previous?: T; readonly status: 'error' };\n\nexport interface Resource<T> extends Readable<AsyncState<T>>, Disposable {\n reload(): void;\n}\n\nexport type ResourceOptions = {\n name?: string;\n};\n\ntype AsyncRuntime = {\n effect(callback: () => undefined | (() => void), options?: { name?: string }): EffectHandle;\n signal<T>(initial: T, options?: { name?: string }): Signal<T>;\n};\n\n/** Resource only depends on primitive runtime methods; graph binding stays private. */\nexport const createResource =\n (runtime: AsyncRuntime) =>\n <Source, Value>(\n source: () => Source,\n loader: (source: Source, context: { readonly signal: AbortSignal }) => Promise<Value>,\n options?: ResourceOptions,\n ): Resource<Value> => {\n const state = runtime.signal<AsyncState<Value>>({ status: 'pending' }, { name: options?.name });\n const reloadEpoch = runtime.signal(0);\n let active: AbortController | undefined;\n let hasPrevious = false;\n let previousValue: Value | undefined;\n\n const run = (): void => {\n void reloadEpoch.value;\n active?.abort();\n\n let input: Source;\n\n try {\n input = source();\n } catch (error) {\n state.value = hasPrevious\n ? { error, previous: previousValue as Value, status: 'error' }\n : { error, status: 'error' };\n\n return;\n }\n\n const next = new AbortController();\n\n active = next;\n state.value = hasPrevious ? { previous: previousValue as Value, status: 'pending' } : { status: 'pending' };\n\n let request: Promise<Value>;\n\n try {\n request = Promise.resolve(loader(input, { signal: next.signal }));\n } catch (error) {\n request = Promise.reject(error);\n }\n\n void request.then(\n (value) => {\n if (!stop.disposed && !next.signal.aborted) {\n hasPrevious = true;\n previousValue = value;\n state.value = { status: 'success', value };\n }\n },\n (error: unknown) => {\n if (!stop.disposed && !next.signal.aborted) {\n state.value = hasPrevious\n ? { error, previous: previousValue as Value, status: 'error' }\n : { error, status: 'error' };\n }\n },\n );\n };\n\n const stop = runtime.effect(\n () => {\n run();\n\n return () => active?.abort();\n },\n { name: options?.name },\n );\n\n const assertActive = (): void => {\n if (stop.disposed) throw new RippleDisposedError('Cannot use a disposed resource.');\n };\n const resource: Resource<Value> = {\n get disposalSignal() {\n return stop.disposalSignal;\n },\n dispose: () => stop.dispose(),\n get disposed() {\n return stop.disposed;\n },\n get name() {\n return state.name;\n },\n peek: () => state.peek(),\n reload: () => {\n assertActive();\n reloadEpoch.value = reloadEpoch.peek() + 1;\n },\n subscribe: (listener) => {\n assertActive();\n return state.subscribe(listener);\n },\n [Symbol.dispose]() {\n this.dispose();\n },\n get value() {\n return state.value;\n },\n };\n\n Object.defineProperty(resource, REACTIVE, { value: true });\n\n return resource;\n };\n","import { RippleError } from './errors';\nimport { REACTIVE } from './runtime';\nimport type { Disposable, EffectHandle, Readable, Signal, Subscribable } from './types';\n\ntype BridgeRuntime = {\n effect(callback: () => undefined | (() => void), options?: { name?: string }): EffectHandle;\n signal<T>(initial: T, options?: { name?: string }): Signal<T>;\n};\n\nexport type BridgedReadable<T> = Readable<T> & Disposable;\nexport type FromSubscribableOptions = { name?: string; signal?: AbortSignal };\n\nexport const createFromSubscribable =\n (runtime: BridgeRuntime) =>\n <T>(source: Subscribable<T>, options?: FromSubscribableOptions): BridgedReadable<T> => {\n const node = runtime.signal<T>(source.getSnapshot(), { name: options?.name });\n const stop = runtime.effect(\n () => {\n const sync = () => {\n node.value = source.getSnapshot();\n };\n let unsubscribe: (() => void) | undefined;\n\n try {\n unsubscribe = source.subscribe(sync);\n sync();\n } catch (error) {\n unsubscribe?.();\n throw error;\n }\n\n return unsubscribe;\n },\n { name: options?.name },\n );\n const abort = () => stop.dispose();\n\n options?.signal?.addEventListener('abort', abort, { once: true });\n if (options?.signal?.aborted) stop.dispose();\n\n const assertActive = (): void => {\n if (stop.disposed) throw new RippleError('Cannot subscribe to a disposed bridge.');\n };\n const dispose = (): void => {\n options?.signal?.removeEventListener('abort', abort);\n stop.dispose();\n };\n const readable: BridgedReadable<T> = {\n get disposalSignal() {\n return stop.disposalSignal;\n },\n dispose,\n get disposed() {\n return stop.disposed;\n },\n get name() {\n return node.name;\n },\n peek: () => node.peek(),\n subscribe(listener) {\n assertActive();\n return node.subscribe(listener);\n },\n [Symbol.dispose]: dispose,\n get value() {\n return node.value;\n },\n };\n\n Object.defineProperty(readable, REACTIVE, { value: true });\n return readable;\n };\n","import type { EffectHandle, Equality, Readable } from './types';\n\nexport type WatchOptions<T> = {\n equals?: Equality<T>;\n /** Run the callback once at setup, before returning the handle. */\n immediate?: boolean;\n name?: string;\n};\n\ntype WatchRuntime = {\n effect(callback: () => undefined | (() => void), options?: { name?: string }): EffectHandle;\n untrack<T>(fn: () => T): T;\n};\n\nexport const createWatch =\n (runtime: WatchRuntime) =>\n <T>(\n source: Readable<T> | (() => T),\n callback: (value: T, previous: T | undefined) => void,\n options?: WatchOptions<T>,\n ): EffectHandle => {\n const read = typeof source === 'function' ? source : () => source.value;\n const equals = options?.equals ?? Object.is;\n let initial = true;\n let previous: T | undefined;\n\n return runtime.effect(\n () => {\n const value = read();\n\n if (initial) {\n initial = false;\n previous = value;\n\n if (options?.immediate) runtime.untrack(() => callback(value, undefined));\n\n return;\n }\n\n if (equals(previous as T, value)) return;\n\n const oldValue = previous;\n\n previous = value;\n runtime.untrack(() => callback(value, oldValue));\n },\n { name: options?.name },\n );\n };\n","import { createResource, type Resource, type ResourceOptions } from './_async';\nimport { type BridgedReadable, createFromSubscribable, type FromSubscribableOptions } from './_subscribable';\nimport { createWatch, type WatchOptions } from './_watch';\nimport { ReactiveRuntime } from './runtime';\nimport type {\n Cleanup,\n ComputedOptions,\n Disposable,\n EffectHandle,\n EffectOptions,\n Readable,\n RippleOptions,\n Scope,\n Signal,\n SignalOptions,\n Subscribable,\n} from './types';\n\nexport interface Ripple extends Disposable {\n batch<T>(fn: () => T): T;\n computed<T>(derive: () => T, options?: ComputedOptions<T>): Readable<T>;\n createScope(name?: string): Scope;\n effect(callback: () => Cleanup | undefined, options?: EffectOptions): EffectHandle;\n fromSubscribable<T>(source: Subscribable<T>, options?: FromSubscribableOptions): BridgedReadable<T>;\n resource<Source, Value>(\n source: () => Source,\n loader: (source: Source, context: { readonly signal: AbortSignal }) => Promise<Value>,\n options?: ResourceOptions,\n ): Resource<Value>;\n signal<T>(initial: T, options?: SignalOptions<T>): Signal<T>;\n untrack<T>(fn: () => T): T;\n watch<T>(\n source: Readable<T> | (() => T),\n callback: (value: T, previous: T | undefined) => void,\n options?: WatchOptions<T>,\n ): EffectHandle;\n}\n\n/**\n * Creates one complete reactive graph with its own ownership boundary. All\n * factories on the returned object share its runtime. Use this for tests, SSR\n * requests, embedded applications, or independently disposable features.\n * `dispose()` is terminal: create a new graph for a new lifetime.\n */\nexport const createRipple = (options?: RippleOptions): Ripple => {\n const runtime = new ReactiveRuntime(options);\n const fromSubscribable = createFromSubscribable(runtime);\n const resource = createResource(runtime);\n\n return {\n batch: runtime.batch,\n computed: runtime.computed,\n createScope: runtime.createScope,\n get disposalSignal() {\n return runtime.disposalSignal;\n },\n dispose: () => runtime.dispose(),\n get disposed() {\n return runtime.disposed;\n },\n effect: runtime.effect,\n fromSubscribable,\n resource,\n signal: runtime.signal,\n untrack: runtime.untrack,\n watch: createWatch(runtime),\n [Symbol.dispose]: () => runtime.dispose(),\n };\n};\n\n/**\n * The shared default reactive graph: process-lifetime. Root helpers\n * (`signal`, `computed`, `effect`, `batch`, `createScope`, `untrack`, `watch`, `resource`, `fromSubscribable`)\n * are re-exported from the package root as bound methods on this single graph\n * instance. Use these only when the application has one graph for its entire\n * lifetime; they are never disposed. For isolated, disposable graphs (tests,\n * SSR, embedded features) use `createRipple()` instead.\n */\nexport const defaultRipple = createRipple();\n","export type { AsyncState, Resource, ResourceOptions } from './_async';\nexport { createRipple, type Ripple } from './_default';\nexport type { BridgedReadable, FromSubscribableOptions } from './_subscribable';\nexport type { WatchOptions } from './_watch';\nexport { RippleCycleError, RippleDisposedError, RippleError } from './errors';\nexport { isReactive } from './runtime';\nexport type {\n Cleanup,\n ComputedOptions,\n Disposable,\n EffectHandle,\n EffectOptions,\n Equality,\n Readable,\n RippleErrorContext,\n RippleOptions,\n Scope,\n Signal,\n SignalOptions,\n Subscribable,\n Unsubscribe,\n} from './types';\n\nimport { defaultRipple } from './_default';\n\nexport const signal = defaultRipple.signal;\nexport const computed = defaultRipple.computed;\nexport const effect = defaultRipple.effect;\nexport const batch = defaultRipple.batch;\nexport const createScope = defaultRipple.createScope;\nexport const untrack = defaultRipple.untrack;\nexport const watch = defaultRipple.watch;\nexport const resource = defaultRipple.resource;\nexport const fromSubscribable = defaultRipple.fromSubscribable;\n"],"mappings":"AAAA,IAAa,YAAb,cAAiC,KAAM,CACrC,YAAY,EAAiB,EAAwB,CACnD,MAAM,EAAS,CAAO,EACtB,KAAK,KAAO,WAAW,KACvB,OAAO,eAAe,KAAM,WAAW,SAAS,CAClD,CACF,EAGa,iBAAb,cAAsC,WAAY,CAAC,EAGtC,oBAAb,cAAyC,WAAY,CAAC,ECGzC,EAAW,OAAO,IAAI,2BAA2B,EACxD,EAAuB,IACvB,EAAQ,OAAO,cAAc,EA0BpB,aAAf,KAA+B,CAC7B,CAAU,GAAY,GACtB,WAAsB,IAAI,IAC1B,KACA,QAEA,YAAsB,EAA0B,EAAe,CAC7D,KAAK,QAAU,EACf,KAAK,KAAO,CACd,CAKA,UAAU,EAAmC,CAC3C,KAAK,QAAQ,aAAa,EAC1B,KAAK,KAAK,EAIV,I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AAS,QAAU,OAAO,GACrC,EAAU,GACV,EAEJ,OAAO,EAAQ,WACP,CACJ,IAAM,EAAQ,EAAK,EAEnB,GAAI,EAAS,CACX,EAAU,GACV,EAAW,EAEP,GAAS,WAAW,EAAQ,YAAc,EAAS,EAAO,IAAA,EAAS,CAAC,EAExE,MACF,CAEA,GAAI,EAAO,EAAe,CAAK,EAAG,OAElC,IAAM,EAAW,EAEjB,EAAW,EACX,EAAQ,YAAc,EAAS,EAAO,CAAQ,CAAC,CACjD,EACA,CAAE,KAAM,GAAS,IAAK,CACxB,CACF,ECJW,aAAgB,GAAoC,CAC/D,IAAM,EAAU,IAAI,gBAAgB,CAAO,EACrC,EAAmB,uBAAuB,CAAO,EACjD,EAAW,eAAe,CAAO,EAEvC,MAAO,CACL,MAAO,EAAQ,MACf,SAAU,EAAQ,SAClB,YAAa,EAAQ,YACrB,IAAI,gBAAiB,CACnB,OAAO,EAAQ,cACjB,EACA,YAAe,EAAQ,QAAQ,EAC/B,IAAI,UAAW,CACb,OAAO,EAAQ,QACjB,EACA,OAAQ,EAAQ,OAChB,mBACA,WACA,OAAQ,EAAQ,OAChB,QAAS,EAAQ,QACjB,MAAO,YAAY,CAAO,GACzB,OAAO,aAAgB,EAAQ,QAAQ,CAC1C,CACF,EAUa,EAAgB,aAAa,ECrD7B,EAAS,EAAc,OACvB,EAAW,EAAc,SACzB,EAAS,EAAc,OACvB,EAAQ,EAAc,MACtB,EAAc,EAAc,YAC5B,EAAU,EAAc,QACxB,EAAQ,EAAc,MACtB,EAAW,EAAc,SACzB,EAAmB,EAAc"}
package/dist/runtime.cjs CHANGED
@@ -1,2 +1,2 @@
1
- const e=require("./errors.cjs");var t=Symbol.for(`@vielzeug/ripple/reactive`),n=100,r=Symbol(`ripple.unset`),ReactiveNode=class{[t]=!0;dependents=new Set;name;runtime;constructor(e,t){this.runtime=e,this.name=t}subscribe(e){this.runtime.assertActive(),this.peek();let t={listener:e,onDependencyChanged:()=>this.runtime.enqueueListener(t)};return this.dependents.add(t),()=>this.dependents.delete(t)}notify(){for(let e of[...this.dependents])e.onDependencyChanged()}},SignalNode=class extends ReactiveNode{current;equals;constructor(e,t,n){super(e,n?.name),this.current=t,this.equals=n?.equals??Object.is}get value(){return this.runtime.track(this),this.current}set value(e){if(this.runtime.assertActive(),this.equals(this.current,e))return;let t=this.current;this.current=e,this.runtime.emit({name:this.name,next:e,previous:t,type:`write`}),this.runtime.propagate(()=>this.notify())}peek(){return this.current}update(e){this.value=e(this.current)}},ComputedNode=class extends ReactiveNode{dependencies=new Set;computing=!1;disposed=!1;dirty=!0;current=r;derive;equals;owner;constructor(e,t,n){super(e,n?.name),this.derive=t,this.equals=n?.equals??Object.is}get value(){return this.runtime.track(this),this.refresh(),this.current}peek(){return this.refresh(),this.current}onDependencyChanged(){if(!this.disposed&&(this.dirty||=!0,this.dependents.size>0))try{this.refresh()&&this.notify()}catch(e){this.runtime.report(e,{kind:`computed`,name:this.name})}}setOwner(e){this.owner=e}dispose(){this.disposed||(this.disposed=!0,this.owner?.release(this),this.owner=void 0,this.runtime.clearDependencies(this),this.dependents.clear())}refresh(){if(!this.dirty||this.disposed)return!1;if(this.computing){let t=this.name===void 0?``:` "${this.name}"`;throw new e.RippleComputedCycleError(`computed cycle detected${t}`)}this.computing=!0,this.runtime.emit({name:this.name,type:`compute`});try{let e=this.runtime.collect(this,this.derive),t=this.current===r||!this.equals(this.current,e);return this.current=e,this.dirty=!1,t}finally{this.computing=!1}}},ScopeNode=class{disposalController=new AbortController;owned=new Set;name;isDisposed=!1;owner;runtime;constructor(e,t){this.runtime=e,this.name=t}get disposed(){return this.isDisposed}get disposalSignal(){return this.disposalController.signal}own(e){e.setOwner(this),this.owned.add(e)}release(e){this.owned.delete(e)}setOwner(e){this.owner=e}run(t){if(this.isDisposed)throw new e.RippleDisposedScopeError(`Cannot run a disposed scope.`);return this.runtime.withScope(this,t)}dispose(){if(!this.isDisposed){this.isDisposed=!0,this.owner?.release(this),this.owner=void 0;for(let e of[...this.owned].reverse())e.dispose();this.owned.clear(),this.disposalController.abort(),this.runtime.emit({name:this.name,node:`scope`,type:`dispose`})}}[Symbol.dispose](){this.dispose()}},EffectNode=class{dependencies=new Set;disposalController=new AbortController;cleanup;isDisposed=!1;ownershipScope;runScope;callback;options;runtime;constructor(e,t,n){this.runtime=e,this.callback=t,this.options=n}get disposed(){return this.isDisposed}get disposalSignal(){return this.disposalController.signal}setOwner(e){this.ownershipScope=e}onDependencyChanged(){this.isDisposed||this.runtime.enqueue(this)}run(){if(this.isDisposed)return;this.runScope?.dispose(),this.runScope=void 0,this.runCleanup(),this.runtime.emit({name:this.options?.name,type:`effect`});let e=new ScopeNode(this.runtime);try{let t=this.runtime.withEffectScope(e,()=>this.runtime.collectEffect(this,this.callback));this.runScope=e,this.cleanup=typeof t==`function`?t:void 0,this.isDisposed&&(this.runScope.dispose(),this.runScope=void 0,this.runCleanup())}catch(t){e.dispose(),this.runtime.report(t,{kind:`effect`,name:this.options?.name})}}dispose(){this.isDisposed||(this.isDisposed=!0,this.ownershipScope?.release(this),this.ownershipScope=void 0,this.runScope?.dispose(),this.runScope=void 0,this.runtime.clearDependencies(this),this.runCleanup(),this.disposalController.abort(),this.runtime.emit({name:this.options?.name,node:`effect`,type:`dispose`}))}[Symbol.dispose](){this.dispose()}runCleanup(){let e=this.cleanup;if(this.cleanup=void 0,e!==void 0)try{e()}catch(e){this.runtime.report(e,{kind:`cleanup`,name:this.options?.name})}}},ReactiveRuntime=class{activeEffectScope;activeObserver;activeScope;isDisposed=!1;flushDepth=0;flushing=!1;pending=new Set;listeners=new Set;rootScope;tappers=new Set;errorPolicy;constructor(e){this.errorPolicy=e?.errorPolicy??`throw`,this.rootScope=new ScopeNode(this,`runtime`),this.activeScope=this.rootScope}get disposed(){return this.isDisposed}get disposalSignal(){return this.rootScope.disposalSignal}signal=(e,t)=>(this.assertActive(),new SignalNode(this,e,t));computed=(e,t)=>{this.assertActive();let n=new ComputedNode(this,e,t);return(this.activeEffectScope??this.activeScope).own(n),n};effect=(e,t)=>{this.assertActive();let n=new EffectNode(this,e,t);return(this.activeEffectScope??this.activeScope).own(n),n.run(),n};createScope=e=>{this.assertActive();let t=new ScopeNode(this,e);return this.activeScope.own(t),t};batch=e=>(this.assertActive(),this.propagate(e));untrack=e=>(this.assertActive(),this.withObserver(void 0,e));tap=(e,t)=>{if(this.isDisposed)return()=>{};let n=t?.signal;if(n?.aborted)return this.tappers.delete(e),()=>{};if(this.tappers.add(e),n){let onAbort=()=>this.tappers.delete(e);return n.addEventListener(`abort`,onAbort,{once:!0}),()=>{this.tappers.delete(e),n.removeEventListener(`abort`,onAbort)}}return()=>this.tappers.delete(e)};dispose(){this.isDisposed||(this.isDisposed=!0,this.rootScope.dispose(),this.emit({node:`graph`,type:`dispose`}),this.tappers.clear())}assertActive(){if(this.isDisposed)throw new e.RippleDisposedRuntimeError(`Cannot use a disposed Ripple runtime.`)}track(e){let t=this.activeObserver;t?.collecting!==void 0&&t.collecting.add(e)}clearDependencies(e){for(let t of e.dependencies)t.dependents.delete(e);e.dependencies.clear()}collect(e,t){return this.collectWith(e,t,e.dependencies.size===0)}collectEffect(e,t){return this.collectWith(e,t,!0)}withEffectScope(e,t){let n=this.activeEffectScope;this.activeEffectScope=e;try{return t()}finally{this.activeEffectScope=n}}withObserver(e,t){let n=this.activeObserver;this.activeObserver=e;try{return t()}finally{this.activeObserver=n}}withScope(e,t){let n=this.activeEffectScope,r=this.activeScope;this.activeEffectScope=void 0,this.activeScope=e;try{return t()}finally{this.activeEffectScope=n,this.activeScope=r}}enqueue(e){this.pending.add(e),this.flushDepth===0&&this.flush()}enqueueListener(e){this.listeners.add(e),this.flushDepth===0&&this.flush()}propagate(e){this.flushDepth++;try{return e()}finally{this.flushDepth--,this.flushDepth===0&&this.flush()}}emit(e){if(this.tappers.size!==0)for(let t of this.tappers)try{t(e)}catch{}}report(e,t){this.emit({context:t,error:e,type:`error`}),this.errorPolicy===`throw`&&queueMicrotask(()=>{throw e})}collectWith(e,t,n){let r=this.activeObserver,i=new Set;e.collecting=i,this.activeObserver=e;try{let n=t();return this.commitDependencies(e,i),n}catch(t){throw n&&this.commitDependencies(e,i),t}finally{e.collecting=void 0,this.activeObserver=r}}commitDependencies(e,t){for(let n of e.dependencies)t.has(n)||n.dependents.delete(e);for(let n of t)e.dependencies.has(n)||n.dependents.add(e);e.dependencies.clear();for(let n of t)e.dependencies.add(n)}flush(){if(this.flushing)return;this.flushing=!0;let t=0;try{for(;this.pending.size>0||this.listeners.size>0;){if(++t>n)throw new e.RippleInfiniteLoopError(`infinite reactive flush (>${n} iterations)`);let r=[...this.pending],i=[...this.listeners];this.pending.clear(),this.listeners.clear();for(let e of r)e.run();for(let e of i)try{e.listener()}catch(e){this.report(e,{kind:`listener`})}}}finally{this.flushing=!1}}},isReactive=e=>{if(typeof e!=`object`||!e||e[t]!==!0)return!1;let n=e;return`value`in n&&typeof n.peek==`function`&&typeof n.subscribe==`function`};exports.REACTIVE=t,exports.ReactiveRuntime=ReactiveRuntime,exports.isReactive=isReactive;
1
+ const e=require("./errors.cjs");var t=Symbol.for(`@vielzeug/ripple/reactive`),n=100,r=Symbol(`ripple.unset`),ReactiveNode=class{[t]=!0;dependents=new Set;name;runtime;constructor(e,t){this.runtime=e,this.name=t}subscribe(e){this.runtime.assertActive(),this.peek();let t={listener:e,onDependencyChanged:()=>this.runtime.enqueueListener(t)};return this.dependents.add(t),()=>this.dependents.delete(t)}notify(){for(let e of[...this.dependents])e.onDependencyChanged()}},SignalNode=class extends ReactiveNode{current;equals;constructor(e,t,n){super(e,n?.name),this.current=t,this.equals=n?.equals??Object.is}get value(){return this.runtime.track(this),this.current}set value(e){this.runtime.assertActive(),!this.equals(this.current,e)&&(this.current=e,this.runtime.propagate(()=>this.notify()))}peek(){return this.current}update(e){this.value=e(this.current)}},ComputedNode=class extends ReactiveNode{dependencies=new Set;computing=!1;disposed=!1;dirty=!0;current=r;derive;equals;owner;constructor(e,t,n){super(e,n?.name),this.derive=t,this.equals=n?.equals??Object.is}get value(){return this.runtime.track(this),this.refresh(),this.evaluated()}peek(){return this.refresh(),this.evaluated()}evaluated(){if(this.current===r){let t=this.name===void 0?``:` "${this.name}"`;throw new e.RippleDisposedError(`computed${t} was disposed before it was ever evaluated`)}return this.current}onDependencyChanged(){if(!this.disposed&&(this.dirty||=!0,this.dependents.size>0))try{this.refresh()&&this.notify()}catch(e){this.runtime.report(e,{kind:`computed`,name:this.name})}}setOwner(e){this.owner=e}dispose(){this.disposed||(this.disposed=!0,this.owner?.release(this),this.owner=void 0,this.runtime.clearDependencies(this),this.dependents.clear())}refresh(){if(!this.dirty||this.disposed)return!1;if(this.computing){let t=this.name===void 0?``:` "${this.name}"`;throw new e.RippleCycleError(`computed cycle detected${t}`)}this.computing=!0;try{let e=this.runtime.collect(this,this.derive),t=this.current===r||!this.equals(this.current,e);return this.current=e,this.dirty=!1,t}finally{this.computing=!1}}},ScopeNode=class{disposalController=new AbortController;owned=new Set;name;isDisposed=!1;owner;runtime;constructor(e,t){this.runtime=e,this.name=t}get disposed(){return this.isDisposed}get disposalSignal(){return this.disposalController.signal}own(e){e.setOwner(this),this.owned.add(e)}release(e){this.owned.delete(e)}setOwner(e){this.owner=e}run(t){if(this.isDisposed)throw new e.RippleDisposedError(`Cannot run a disposed scope.`);return this.runtime.withScope(this,t)}dispose(){if(!this.isDisposed){this.isDisposed=!0,this.owner?.release(this),this.owner=void 0;for(let e of[...this.owned].reverse())e.dispose();this.owned.clear(),this.disposalController.abort()}}[Symbol.dispose](){this.dispose()}},EffectNode=class{dependencies=new Set;disposalController=new AbortController;cleanup;isDisposed=!1;ownershipScope;runScope;callback;options;runtime;constructor(e,t,n){this.runtime=e,this.callback=t,this.options=n}get disposed(){return this.isDisposed}get disposalSignal(){return this.disposalController.signal}setOwner(e){this.ownershipScope=e}onDependencyChanged(){this.isDisposed||this.runtime.enqueue(this)}run(){if(this.isDisposed)return;this.runScope?.dispose(),this.runScope=void 0,this.runCleanup();let e=new ScopeNode(this.runtime);try{let t=this.runtime.withEffectScope(e,()=>this.runtime.collectEffect(this,this.callback));this.runScope=e,this.cleanup=typeof t==`function`?t:void 0,this.isDisposed&&(this.runScope.dispose(),this.runScope=void 0,this.runCleanup())}catch(t){e.dispose(),this.runtime.report(t,{kind:`effect`,name:this.options?.name})}}dispose(){this.isDisposed||(this.isDisposed=!0,this.ownershipScope?.release(this),this.ownershipScope=void 0,this.runScope?.dispose(),this.runScope=void 0,this.runtime.clearDependencies(this),this.runCleanup(),this.disposalController.abort())}[Symbol.dispose](){this.dispose()}runCleanup(){let e=this.cleanup;if(this.cleanup=void 0,e!==void 0)try{e()}catch(e){this.runtime.report(e,{kind:`cleanup`,name:this.options?.name})}}},ReactiveRuntime=class{activeEffectScope;activeObserver;activeScope;isDisposed=!1;flushDepth=0;flushing=!1;pending=new Set;listeners=new Set;rootScope;onError;constructor(e){this.onError=e?.onError??(e=>{queueMicrotask(()=>{throw e})}),this.rootScope=new ScopeNode(this,`runtime`),this.activeScope=this.rootScope}get disposed(){return this.isDisposed}get disposalSignal(){return this.rootScope.disposalSignal}signal=(e,t)=>(this.assertActive(),new SignalNode(this,e,t));computed=(e,t)=>{this.assertActive();let n=new ComputedNode(this,e,t);return(this.activeEffectScope??this.activeScope).own(n),n};effect=(e,t)=>{this.assertActive();let n=new EffectNode(this,e,t);return(this.activeEffectScope??this.activeScope).own(n),n.run(),n};createScope=e=>{this.assertActive();let t=new ScopeNode(this,e);return this.activeScope.own(t),t};batch=e=>(this.assertActive(),this.propagate(e));untrack=e=>(this.assertActive(),this.withObserver(void 0,e));dispose(){this.isDisposed||(this.isDisposed=!0,this.rootScope.dispose())}assertActive(){if(this.isDisposed)throw new e.RippleDisposedError(`Cannot use a disposed Ripple runtime.`)}track(e){let t=this.activeObserver;t?.collecting!==void 0&&t.collecting.add(e)}clearDependencies(e){for(let t of e.dependencies)t.dependents.delete(e);e.dependencies.clear()}collect(e,t){return this.collectWith(e,t,e.dependencies.size===0)}collectEffect(e,t){return this.collectWith(e,t,!0)}withEffectScope(e,t){let n=this.activeEffectScope;this.activeEffectScope=e;try{return t()}finally{this.activeEffectScope=n}}withObserver(e,t){let n=this.activeObserver;this.activeObserver=e;try{return t()}finally{this.activeObserver=n}}withScope(e,t){let n=this.activeEffectScope,r=this.activeScope;this.activeEffectScope=void 0,this.activeScope=e;try{return t()}finally{this.activeEffectScope=n,this.activeScope=r}}enqueue(e){this.pending.add(e),this.flushDepth===0&&this.flush()}enqueueListener(e){this.listeners.add(e),this.flushDepth===0&&this.flush()}propagate(e){this.flushDepth++;try{return e()}finally{this.flushDepth--,this.flushDepth===0&&this.flush()}}report(e,t){try{this.onError(e,t)}catch{}}collectWith(e,t,n){let r=this.activeObserver,i=new Set;e.collecting=i,this.activeObserver=e;try{let n=t();return this.commitDependencies(e,i),n}catch(t){throw n&&this.commitDependencies(e,i),t}finally{e.collecting=void 0,this.activeObserver=r}}commitDependencies(e,t){for(let n of e.dependencies)t.has(n)||n.dependents.delete(e);for(let n of t)e.dependencies.has(n)||n.dependents.add(e);e.dependencies.clear();for(let n of t)e.dependencies.add(n)}flush(){if(this.flushing)return;this.flushing=!0;let t=0;try{for(;this.pending.size>0||this.listeners.size>0;){if(++t>n){this.report(new e.RippleCycleError(`infinite reactive flush (>${n} iterations)`),{kind:`flush`}),this.pending.clear(),this.listeners.clear();break}let r=[...this.pending],i=[...this.listeners];this.pending.clear(),this.listeners.clear();for(let e of r)e.run();for(let e of i)try{e.listener()}catch(e){this.report(e,{kind:`listener`})}}}finally{this.flushing=!1}}},isReactive=e=>{if(typeof e!=`object`||!e||e[t]!==!0)return!1;let n=e;return`value`in n&&typeof n.peek==`function`&&typeof n.subscribe==`function`};exports.REACTIVE=t,exports.ReactiveRuntime=ReactiveRuntime,exports.isReactive=isReactive;
2
2
  //# sourceMappingURL=runtime.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"runtime.cjs","names":[],"sources":["../src/runtime.ts"],"sourcesContent":["import {\n RippleComputedCycleError,\n RippleDisposedRuntimeError,\n RippleDisposedScopeError,\n RippleInfiniteLoopError,\n} from './errors';\nimport type {\n Cleanup,\n ComputedOptions,\n EffectHandle,\n EffectOptions,\n Readable,\n RippleErrorContext,\n RippleErrorPolicy,\n RippleEvent,\n RippleOptions,\n Scope,\n Signal,\n SignalOptions,\n Unsubscribe,\n} from './types';\n\nexport const REACTIVE = Symbol.for('@vielzeug/ripple/reactive');\nconst MAX_FLUSH_ITERATIONS = 100;\nconst UNSET = Symbol('ripple.unset');\n\ntype Dependency = ReactiveNode<unknown>;\n\n/** Anything that wants to hear that a dependency changed: the only member a producer may call. */\ntype Dependent = {\n onDependencyChanged(): void;\n};\n\n/** A subscribe() listener sink: enqueued as a unit so two subscriptions sharing one\n * callback each fire per flush, while one subscription never fires twice. */\ntype ListenerSink = Dependent & {\n readonly listener: () => void;\n};\n\n/** A dependency-collecting observer (computed or effect). Plain listener sinks need less. */\ntype ObserverNode = Dependent & {\n collecting?: Set<Dependency>;\n readonly dependencies: Set<Dependency>;\n};\n\ntype Owned = {\n dispose(): void;\n setOwner(owner: ScopeNode | undefined): void;\n};\n\nabstract class ReactiveNode<T> {\n readonly [REACTIVE] = true;\n readonly dependents = new Set<Dependent>();\n readonly name: string | undefined;\n protected readonly runtime: ReactiveRuntime;\n\n protected constructor(runtime: ReactiveRuntime, name?: string) {\n this.runtime = runtime;\n this.name = name;\n }\n\n abstract peek(): T;\n abstract get value(): T;\n\n subscribe(listener: () => void): Unsubscribe {\n this.runtime.assertActive();\n this.peek();\n\n // A listener sink never collects dependencies, so it is a bare dependent :\n // no dependency bookkeeping is allocated per subscription.\n const sink: ListenerSink = {\n listener,\n onDependencyChanged: () => this.runtime.enqueueListener(sink),\n };\n\n this.dependents.add(sink);\n\n return () => this.dependents.delete(sink);\n }\n\n protected notify(): void {\n for (const dependent of [...this.dependents]) dependent.onDependencyChanged();\n }\n}\n\nclass SignalNode<T> extends ReactiveNode<T> implements Signal<T> {\n private current: T;\n private readonly equals: (previous: T, next: T) => boolean;\n\n constructor(runtime: ReactiveRuntime, initial: T, options?: SignalOptions<T>) {\n super(runtime, options?.name);\n this.current = initial;\n this.equals = options?.equals ?? Object.is;\n }\n\n get value(): T {\n this.runtime.track(this);\n\n return this.current;\n }\n\n set value(next: T) {\n this.runtime.assertActive();\n\n if (this.equals(this.current, next)) return;\n\n const previous = this.current;\n\n this.current = next;\n this.runtime.emit({ name: this.name, next, previous, type: 'write' });\n this.runtime.propagate(() => this.notify());\n }\n\n peek(): T {\n return this.current;\n }\n\n update(updater: (prev: T) => T): void {\n this.value = updater(this.current);\n }\n}\n\nclass ComputedNode<T> extends ReactiveNode<T> implements ObserverNode, Owned {\n readonly dependencies = new Set<Dependency>();\n private computing = false;\n private disposed = false;\n private dirty = true;\n private current: T | typeof UNSET = UNSET;\n private readonly derive: () => T;\n private readonly equals: (previous: T, next: T) => boolean;\n private owner: ScopeNode | undefined;\n\n constructor(runtime: ReactiveRuntime, derive: () => T, options?: ComputedOptions<T>) {\n super(runtime, options?.name);\n this.derive = derive;\n this.equals = options?.equals ?? Object.is;\n }\n\n get value(): T {\n // Track before refresh: if refresh throws, the consumer still depends on\n // this computed and must be notified when a dependency change might let it\n // succeed. Without this, a first-run failure permanently severs the\n // consumer from the computed.\n this.runtime.track(this);\n this.refresh();\n\n return this.current as T;\n }\n\n peek(): T {\n this.refresh();\n\n return this.current as T;\n }\n\n onDependencyChanged(): void {\n if (this.disposed) return;\n\n if (!this.dirty) this.dirty = true;\n\n if (this.dependents.size > 0) {\n try {\n if (this.refresh()) this.notify();\n } catch (error) {\n this.runtime.report(error, { kind: 'computed', name: this.name });\n }\n }\n }\n\n setOwner(owner: ScopeNode | undefined): void {\n this.owner = owner;\n }\n\n dispose(): void {\n if (this.disposed) return;\n\n this.disposed = true;\n this.owner?.release(this);\n this.owner = undefined;\n this.runtime.clearDependencies(this);\n this.dependents.clear();\n }\n\n private refresh(): boolean {\n if (!this.dirty || this.disposed) return false;\n\n if (this.computing) {\n const label = this.name === undefined ? '' : ` \"${this.name}\"`;\n\n throw new RippleComputedCycleError(`computed cycle detected${label}`);\n }\n\n this.computing = true;\n this.runtime.emit({ name: this.name, type: 'compute' });\n\n try {\n const next = this.runtime.collect(this, this.derive);\n const changed = this.current === UNSET || !this.equals(this.current as T, next);\n\n this.current = next;\n this.dirty = false;\n\n return changed;\n } finally {\n this.computing = false;\n }\n }\n}\n\nclass ScopeNode implements Scope, Owned {\n readonly disposalController = new AbortController();\n readonly owned = new Set<Owned>();\n readonly name: string | undefined;\n private isDisposed = false;\n private owner: ScopeNode | undefined;\n private readonly runtime: ReactiveRuntime;\n\n constructor(runtime: ReactiveRuntime, name?: string) {\n this.runtime = runtime;\n this.name = name;\n }\n\n get disposed(): boolean {\n return this.isDisposed;\n }\n\n get disposalSignal(): AbortSignal {\n return this.disposalController.signal;\n }\n\n own(value: Owned): void {\n value.setOwner(this);\n this.owned.add(value);\n }\n\n release(value: Owned): void {\n this.owned.delete(value);\n }\n\n setOwner(owner: ScopeNode | undefined): void {\n this.owner = owner;\n }\n\n run<T>(fn: () => T): T {\n if (this.isDisposed) throw new RippleDisposedScopeError('Cannot run a disposed scope.');\n\n return this.runtime.withScope(this, fn);\n }\n\n dispose(): void {\n if (this.isDisposed) return;\n\n this.isDisposed = true;\n this.owner?.release(this);\n this.owner = undefined;\n for (const owned of [...this.owned].reverse()) owned.dispose();\n this.owned.clear();\n this.disposalController.abort();\n this.runtime.emit({ name: this.name, node: 'scope', type: 'dispose' });\n }\n\n [Symbol.dispose](): void {\n this.dispose();\n }\n}\n\nclass EffectNode implements ObserverNode, EffectHandle {\n readonly dependencies = new Set<Dependency>();\n readonly disposalController = new AbortController();\n private cleanup: Cleanup | undefined;\n private isDisposed = false;\n private ownershipScope: ScopeNode | undefined;\n private runScope: ScopeNode | undefined;\n private readonly callback: () => Cleanup | undefined;\n private readonly options: EffectOptions | undefined;\n private readonly runtime: ReactiveRuntime;\n\n constructor(runtime: ReactiveRuntime, callback: () => Cleanup | undefined, options?: EffectOptions) {\n this.runtime = runtime;\n this.callback = callback;\n this.options = options;\n }\n\n get disposed(): boolean {\n return this.isDisposed;\n }\n\n get disposalSignal(): AbortSignal {\n return this.disposalController.signal;\n }\n\n setOwner(owner: ScopeNode | undefined): void {\n this.ownershipScope = owner;\n }\n\n onDependencyChanged(): void {\n if (this.isDisposed) return;\n\n this.runtime.enqueue(this);\n }\n\n run(): void {\n if (this.isDisposed) return;\n\n this.runScope?.dispose();\n this.runScope = undefined;\n this.runCleanup();\n this.runtime.emit({ name: this.options?.name, type: 'effect' });\n\n const owner = new ScopeNode(this.runtime);\n\n try {\n const cleanup = this.runtime.withEffectScope(owner, () => this.runtime.collectEffect(this, this.callback));\n\n this.runScope = owner;\n this.cleanup = typeof cleanup === 'function' ? cleanup : undefined;\n if (this.isDisposed) {\n this.runScope.dispose();\n this.runScope = undefined;\n this.runCleanup();\n }\n } catch (error) {\n owner.dispose();\n this.runtime.report(error, { kind: 'effect', name: this.options?.name });\n }\n }\n\n dispose(): void {\n if (this.isDisposed) return;\n\n this.isDisposed = true;\n this.ownershipScope?.release(this);\n this.ownershipScope = undefined;\n this.runScope?.dispose();\n this.runScope = undefined;\n this.runtime.clearDependencies(this);\n this.runCleanup();\n this.disposalController.abort();\n this.runtime.emit({ name: this.options?.name, node: 'effect', type: 'dispose' });\n }\n\n [Symbol.dispose](): void {\n this.dispose();\n }\n\n private runCleanup(): void {\n const cleanup = this.cleanup;\n\n this.cleanup = undefined;\n\n if (cleanup === undefined) return;\n\n try {\n cleanup();\n } catch (error) {\n this.runtime.report(error, { kind: 'cleanup', name: this.options?.name });\n }\n }\n}\n\n/**\n * A runtime owns reactive graph state and lifetime. Separate instances isolate\n * applications and SSR requests without process-wide mutable hooks.\n */\nexport class ReactiveRuntime {\n private activeEffectScope: ScopeNode | undefined;\n private activeObserver: ObserverNode | undefined;\n private activeScope: ScopeNode;\n private isDisposed = false;\n private flushDepth = 0;\n private flushing = false;\n private readonly pending = new Set<EffectNode>();\n private readonly listeners = new Set<ListenerSink>();\n private readonly rootScope: ScopeNode;\n private readonly tappers = new Set<(event: RippleEvent) => void>();\n private readonly errorPolicy: RippleErrorPolicy;\n\n constructor(options?: RippleOptions) {\n this.errorPolicy = options?.errorPolicy ?? 'throw';\n this.rootScope = new ScopeNode(this, 'runtime');\n this.activeScope = this.rootScope;\n }\n\n get disposed(): boolean {\n return this.isDisposed;\n }\n\n get disposalSignal(): AbortSignal {\n return this.rootScope.disposalSignal;\n }\n\n readonly signal = <T>(initial: T, options?: SignalOptions<T>): Signal<T> => {\n this.assertActive();\n\n return new SignalNode(this, initial, options);\n };\n\n readonly computed = <T>(derive: () => T, options?: ComputedOptions<T>): Readable<T> => {\n this.assertActive();\n\n const node = new ComputedNode(this, derive, options);\n\n (this.activeEffectScope ?? this.activeScope).own(node);\n\n return node;\n };\n\n readonly effect = (callback: () => Cleanup | undefined, options?: EffectOptions): EffectHandle => {\n this.assertActive();\n\n const node = new EffectNode(this, callback, options);\n\n (this.activeEffectScope ?? this.activeScope).own(node);\n node.run();\n\n return node;\n };\n\n readonly createScope = (name?: string): Scope => {\n this.assertActive();\n\n const scope = new ScopeNode(this, name);\n\n // Scopes model explicit, caller-owned lifetimes. Unlike effects/computeds created during an\n // effect run, they deliberately attach to the enclosing scope rather than the per-run owner:\n // keyed DOM directives retain item scopes across reconciliation runs and dispose them only\n // when the item itself leaves the collection.\n this.activeScope.own(scope);\n\n return scope;\n };\n\n readonly batch = <T>(fn: () => T): T => {\n this.assertActive();\n\n return this.propagate(fn);\n };\n\n readonly untrack = <T>(fn: () => T): T => {\n this.assertActive();\n\n return this.withObserver(undefined, fn);\n };\n\n /** Runtime observability: see `Ripple.tap()`. */\n readonly tap = (handler: (event: RippleEvent) => void, options?: { signal?: AbortSignal }): Unsubscribe => {\n if (this.isDisposed) return () => {};\n\n const signal = options?.signal;\n\n if (signal?.aborted) {\n this.tappers.delete(handler);\n return () => {};\n }\n\n this.tappers.add(handler);\n\n if (signal) {\n const onAbort = () => this.tappers.delete(handler);\n\n signal.addEventListener('abort', onAbort, { once: true });\n\n return () => {\n this.tappers.delete(handler);\n signal.removeEventListener('abort', onAbort);\n };\n }\n\n return () => this.tappers.delete(handler);\n };\n\n dispose(): void {\n if (this.isDisposed) return;\n\n this.isDisposed = true;\n this.rootScope.dispose();\n this.emit({ node: 'graph', type: 'dispose' });\n this.tappers.clear();\n }\n\n /** Internal node guard: disposed runtimes allow inert reads but reject graph work and mutation. */\n assertActive(): void {\n if (this.isDisposed) throw new RippleDisposedRuntimeError('Cannot use a disposed Ripple runtime.');\n }\n\n track(node: Dependency): void {\n const observer = this.activeObserver;\n\n if (observer?.collecting === undefined) return;\n\n observer.collecting.add(node);\n }\n\n clearDependencies(observer: ObserverNode): void {\n for (const dependency of observer.dependencies) dependency.dependents.delete(observer);\n observer.dependencies.clear();\n }\n\n collect<T>(observer: ObserverNode, fn: () => T): T {\n // On first run (no prior dependencies), commit partial dependencies even if\n // derive throws, otherwise the computed would have zero dependencies and never\n // be notified when its source changes, permanently stuck until a manual read.\n // On subsequent runs, keep previous dependencies (tested behavior).\n return this.collectWith(observer, fn, observer.dependencies.size === 0);\n }\n\n collectEffect<T>(observer: ObserverNode, fn: () => T): T {\n return this.collectWith(observer, fn, true);\n }\n\n withEffectScope<T>(scope: ScopeNode, fn: () => T): T {\n const previous = this.activeEffectScope;\n\n this.activeEffectScope = scope;\n\n try {\n return fn();\n } finally {\n this.activeEffectScope = previous;\n }\n }\n\n withObserver<T>(observer: ObserverNode | undefined, fn: () => T): T {\n const previous = this.activeObserver;\n\n this.activeObserver = observer;\n\n try {\n return fn();\n } finally {\n this.activeObserver = previous;\n }\n }\n\n withScope<T>(scope: ScopeNode, fn: () => T): T {\n const previousEffectScope = this.activeEffectScope;\n const previousScope = this.activeScope;\n\n this.activeEffectScope = undefined;\n this.activeScope = scope;\n\n try {\n return fn();\n } finally {\n this.activeEffectScope = previousEffectScope;\n this.activeScope = previousScope;\n }\n }\n\n enqueue(effect: EffectNode): void {\n this.pending.add(effect);\n\n if (this.flushDepth === 0) this.flush();\n }\n\n enqueueListener(sink: ListenerSink): void {\n this.listeners.add(sink);\n\n if (this.flushDepth === 0) this.flush();\n }\n\n propagate<T>(fn: () => T): T {\n this.flushDepth++;\n\n try {\n return fn();\n } finally {\n this.flushDepth--;\n\n if (this.flushDepth === 0) this.flush();\n }\n }\n\n emit(event: RippleEvent): void {\n if (this.tappers.size === 0) return;\n\n for (const tapper of this.tappers) {\n try {\n tapper(event);\n } catch {\n // Observability must not affect runtime behavior.\n }\n }\n }\n\n report(error: unknown, context: RippleErrorContext): void {\n this.emit({ context, error, type: 'error' });\n\n if (this.errorPolicy === 'throw') {\n queueMicrotask(() => {\n throw error;\n });\n }\n }\n\n private collectWith<T>(observer: ObserverNode, fn: () => T, commitOnError: boolean): T {\n const previousObserver = this.activeObserver;\n const dependencies = new Set<Dependency>();\n\n observer.collecting = dependencies;\n this.activeObserver = observer;\n\n try {\n const result = fn();\n\n this.commitDependencies(observer, dependencies);\n\n return result;\n } catch (error) {\n if (commitOnError) this.commitDependencies(observer, dependencies);\n\n throw error;\n } finally {\n observer.collecting = undefined;\n this.activeObserver = previousObserver;\n }\n }\n\n private commitDependencies(observer: ObserverNode, next: Set<Dependency>): void {\n for (const dependency of observer.dependencies) {\n if (!next.has(dependency)) dependency.dependents.delete(observer);\n }\n\n for (const dependency of next) {\n if (!observer.dependencies.has(dependency)) dependency.dependents.add(observer);\n }\n\n observer.dependencies.clear();\n for (const dependency of next) observer.dependencies.add(dependency);\n }\n\n private flush(): void {\n if (this.flushing) return;\n\n this.flushing = true;\n\n let iterations = 0;\n\n try {\n while (this.pending.size > 0 || this.listeners.size > 0) {\n if (++iterations > MAX_FLUSH_ITERATIONS) {\n throw new RippleInfiniteLoopError(`infinite reactive flush (>${MAX_FLUSH_ITERATIONS} iterations)`);\n }\n\n const effects = [...this.pending];\n const listeners = [...this.listeners];\n\n this.pending.clear();\n this.listeners.clear();\n\n for (const effect of effects) effect.run();\n\n for (const sink of listeners) {\n try {\n sink.listener();\n } catch (error) {\n this.report(error, { kind: 'listener' });\n }\n }\n }\n } finally {\n this.flushing = false;\n }\n }\n}\n\nexport const isReactive = <T>(value: T | Readable<T>): value is Readable<T> => {\n if (typeof value !== 'object' || value === null || (value as { [REACTIVE]?: unknown })[REACTIVE] !== true)\n return false;\n\n const candidate = value as { peek?: unknown; subscribe?: unknown; value?: unknown };\n\n return 'value' in candidate && typeof candidate.peek === 'function' && typeof candidate.subscribe === 'function';\n};\n"],"mappings":"gCAsBA,IAAa,EAAW,OAAO,IAAI,2BAA2B,EACxD,EAAuB,IACvB,EAAQ,OAAO,cAAc,EA0BpB,aAAf,KAA+B,CAC7B,CAAU,GAAY,GACtB,WAAsB,IAAI,IAC1B,KACA,QAEA,YAAsB,EAA0B,EAAe,CAC7D,KAAK,QAAU,EACf,KAAK,KAAO,CACd,CAKA,UAAU,EAAmC,CAC3C,KAAK,QAAQ,aAAa,EAC1B,KAAK,KAAK,EAIV,IAAM,EAAqB,CACzB,WACA,wBAA2B,KAAK,QAAQ,gBAAgB,CAAI,CAC9D,EAIA,OAFA,KAAK,WAAW,IAAI,CAAI,MAEX,KAAK,WAAW,OAAO,CAAI,CAC1C,CAEA,QAAyB,CACvB,IAAK,IAAM,IAAa,CAAC,GAAG,KAAK,UAAU,EAAG,EAAU,oBAAoB,CAC9E,CACF,EAEM,WAAN,cAA4B,YAAqC,CAC/D,QACA,OAEA,YAAY,EAA0B,EAAY,EAA4B,CAC5E,MAAM,EAAS,GAAS,IAAI,EAC5B,KAAK,QAAU,EACf,KAAK,OAAS,GAAS,QAAU,OAAO,EAC1C,CAEA,IAAI,OAAW,CAGb,OAFA,KAAK,QAAQ,MAAM,IAAI,EAEhB,KAAK,OACd,CAEA,IAAI,MAAM,EAAS,CAGjB,GAFA,KAAK,QAAQ,aAAa,EAEtB,KAAK,OAAO,KAAK,QAAS,CAAI,EAAG,OAErC,IAAM,EAAW,KAAK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AM,EAAY,EAElB,MAAO,UAAW,GAAa,OAAO,EAAU,MAAS,YAAc,OAAO,EAAU,WAAc,UACxG"}
1
+ {"version":3,"file":"runtime.cjs","names":[],"sources":["../src/runtime.ts"],"sourcesContent":["import { RippleCycleError, RippleDisposedError } from './errors';\nimport type {\n Cleanup,\n ComputedOptions,\n EffectHandle,\n EffectOptions,\n Readable,\n RippleErrorContext,\n RippleOptions,\n Scope,\n Signal,\n SignalOptions,\n Unsubscribe,\n} from './types';\n\nexport const REACTIVE = Symbol.for('@vielzeug/ripple/reactive');\nconst MAX_FLUSH_ITERATIONS = 100;\nconst UNSET = Symbol('ripple.unset');\n\ntype Dependency = ReactiveNode<unknown>;\n\n/** Anything that wants to hear that a dependency changed: the only member a producer may call. */\ntype Dependent = {\n onDependencyChanged(): void;\n};\n\n/** A subscribe() listener sink: enqueued as a unit so two subscriptions sharing one\n * callback each fire per flush, while one subscription never fires twice. */\ntype ListenerSink = Dependent & {\n readonly listener: () => void;\n};\n\n/** A dependency-collecting observer (computed or effect). Plain listener sinks need less. */\ntype ObserverNode = Dependent & {\n collecting?: Set<Dependency>;\n readonly dependencies: Set<Dependency>;\n};\n\ntype Owned = {\n dispose(): void;\n setOwner(owner: ScopeNode | undefined): void;\n};\n\nabstract class ReactiveNode<T> {\n readonly [REACTIVE] = true;\n readonly dependents = new Set<Dependent>();\n readonly name: string | undefined;\n protected readonly runtime: ReactiveRuntime;\n\n protected constructor(runtime: ReactiveRuntime, name?: string) {\n this.runtime = runtime;\n this.name = name;\n }\n\n abstract peek(): T;\n abstract get value(): T;\n\n subscribe(listener: () => void): Unsubscribe {\n this.runtime.assertActive();\n this.peek();\n\n // A listener sink never collects dependencies, so it is a bare dependent :\n // no dependency bookkeeping is allocated per subscription.\n const sink: ListenerSink = {\n listener,\n onDependencyChanged: () => this.runtime.enqueueListener(sink),\n };\n\n this.dependents.add(sink);\n\n return () => this.dependents.delete(sink);\n }\n\n protected notify(): void {\n for (const dependent of [...this.dependents]) dependent.onDependencyChanged();\n }\n}\n\nclass SignalNode<T> extends ReactiveNode<T> implements Signal<T> {\n private current: T;\n private readonly equals: (previous: T, next: T) => boolean;\n\n constructor(runtime: ReactiveRuntime, initial: T, options?: SignalOptions<T>) {\n super(runtime, options?.name);\n this.current = initial;\n this.equals = options?.equals ?? Object.is;\n }\n\n get value(): T {\n this.runtime.track(this);\n\n return this.current;\n }\n\n set value(next: T) {\n this.runtime.assertActive();\n\n if (this.equals(this.current, next)) return;\n\n this.current = next;\n this.runtime.propagate(() => this.notify());\n }\n\n peek(): T {\n return this.current;\n }\n\n update(updater: (prev: T) => T): void {\n this.value = updater(this.current);\n }\n}\n\nclass ComputedNode<T> extends ReactiveNode<T> implements ObserverNode, Owned {\n readonly dependencies = new Set<Dependency>();\n private computing = false;\n private disposed = false;\n private dirty = true;\n private current: T | typeof UNSET = UNSET;\n private readonly derive: () => T;\n private readonly equals: (previous: T, next: T) => boolean;\n private owner: ScopeNode | undefined;\n\n constructor(runtime: ReactiveRuntime, derive: () => T, options?: ComputedOptions<T>) {\n super(runtime, options?.name);\n this.derive = derive;\n this.equals = options?.equals ?? Object.is;\n }\n\n get value(): T {\n // Track before refresh: if refresh throws, the consumer still depends on\n // this computed and must be notified when a dependency change might let it\n // succeed. Without this, a first-run failure permanently severs the\n // consumer from the computed.\n this.runtime.track(this);\n this.refresh();\n\n return this.evaluated();\n }\n\n peek(): T {\n this.refresh();\n\n return this.evaluated();\n }\n\n private evaluated(): T {\n if (this.current === UNSET) {\n const label = this.name === undefined ? '' : ` \"${this.name}\"`;\n\n throw new RippleDisposedError(`computed${label} was disposed before it was ever evaluated`);\n }\n\n return this.current as T;\n }\n\n onDependencyChanged(): void {\n if (this.disposed) return;\n\n if (!this.dirty) this.dirty = true;\n\n if (this.dependents.size > 0) {\n try {\n if (this.refresh()) this.notify();\n } catch (error) {\n this.runtime.report(error, { kind: 'computed', name: this.name });\n }\n }\n }\n\n setOwner(owner: ScopeNode | undefined): void {\n this.owner = owner;\n }\n\n dispose(): void {\n if (this.disposed) return;\n\n this.disposed = true;\n this.owner?.release(this);\n this.owner = undefined;\n this.runtime.clearDependencies(this);\n this.dependents.clear();\n }\n\n private refresh(): boolean {\n if (!this.dirty || this.disposed) return false;\n\n if (this.computing) {\n const label = this.name === undefined ? '' : ` \"${this.name}\"`;\n\n throw new RippleCycleError(`computed cycle detected${label}`);\n }\n\n this.computing = true;\n\n try {\n const next = this.runtime.collect(this, this.derive);\n const changed = this.current === UNSET || !this.equals(this.current as T, next);\n\n this.current = next;\n this.dirty = false;\n\n return changed;\n } finally {\n this.computing = false;\n }\n }\n}\n\nclass ScopeNode implements Scope, Owned {\n readonly disposalController = new AbortController();\n readonly owned = new Set<Owned>();\n readonly name: string | undefined;\n private isDisposed = false;\n private owner: ScopeNode | undefined;\n private readonly runtime: ReactiveRuntime;\n\n constructor(runtime: ReactiveRuntime, name?: string) {\n this.runtime = runtime;\n this.name = name;\n }\n\n get disposed(): boolean {\n return this.isDisposed;\n }\n\n get disposalSignal(): AbortSignal {\n return this.disposalController.signal;\n }\n\n own(value: Owned): void {\n value.setOwner(this);\n this.owned.add(value);\n }\n\n release(value: Owned): void {\n this.owned.delete(value);\n }\n\n setOwner(owner: ScopeNode | undefined): void {\n this.owner = owner;\n }\n\n run<T>(fn: () => T): T {\n if (this.isDisposed) throw new RippleDisposedError('Cannot run a disposed scope.');\n\n return this.runtime.withScope(this, fn);\n }\n\n dispose(): void {\n if (this.isDisposed) return;\n\n this.isDisposed = true;\n this.owner?.release(this);\n this.owner = undefined;\n for (const owned of [...this.owned].reverse()) owned.dispose();\n this.owned.clear();\n this.disposalController.abort();\n }\n\n [Symbol.dispose](): void {\n this.dispose();\n }\n}\n\nclass EffectNode implements ObserverNode, EffectHandle {\n readonly dependencies = new Set<Dependency>();\n readonly disposalController = new AbortController();\n private cleanup: Cleanup | undefined;\n private isDisposed = false;\n private ownershipScope: ScopeNode | undefined;\n private runScope: ScopeNode | undefined;\n private readonly callback: () => Cleanup | undefined;\n private readonly options: EffectOptions | undefined;\n private readonly runtime: ReactiveRuntime;\n\n constructor(runtime: ReactiveRuntime, callback: () => Cleanup | undefined, options?: EffectOptions) {\n this.runtime = runtime;\n this.callback = callback;\n this.options = options;\n }\n\n get disposed(): boolean {\n return this.isDisposed;\n }\n\n get disposalSignal(): AbortSignal {\n return this.disposalController.signal;\n }\n\n setOwner(owner: ScopeNode | undefined): void {\n this.ownershipScope = owner;\n }\n\n onDependencyChanged(): void {\n if (this.isDisposed) return;\n\n this.runtime.enqueue(this);\n }\n\n run(): void {\n if (this.isDisposed) return;\n\n this.runScope?.dispose();\n this.runScope = undefined;\n this.runCleanup();\n\n const owner = new ScopeNode(this.runtime);\n\n try {\n const cleanup = this.runtime.withEffectScope(owner, () => this.runtime.collectEffect(this, this.callback));\n\n this.runScope = owner;\n this.cleanup = typeof cleanup === 'function' ? cleanup : undefined;\n if (this.isDisposed) {\n this.runScope.dispose();\n this.runScope = undefined;\n this.runCleanup();\n }\n } catch (error) {\n owner.dispose();\n this.runtime.report(error, { kind: 'effect', name: this.options?.name });\n }\n }\n\n dispose(): void {\n if (this.isDisposed) return;\n\n this.isDisposed = true;\n this.ownershipScope?.release(this);\n this.ownershipScope = undefined;\n this.runScope?.dispose();\n this.runScope = undefined;\n this.runtime.clearDependencies(this);\n this.runCleanup();\n this.disposalController.abort();\n }\n\n [Symbol.dispose](): void {\n this.dispose();\n }\n\n private runCleanup(): void {\n const cleanup = this.cleanup;\n\n this.cleanup = undefined;\n\n if (cleanup === undefined) return;\n\n try {\n cleanup();\n } catch (error) {\n this.runtime.report(error, { kind: 'cleanup', name: this.options?.name });\n }\n }\n}\n\n/**\n * A runtime owns reactive graph state and lifetime. Separate instances isolate\n * applications and SSR requests without process-wide mutable hooks.\n */\nexport class ReactiveRuntime {\n private activeEffectScope: ScopeNode | undefined;\n private activeObserver: ObserverNode | undefined;\n private activeScope: ScopeNode;\n private isDisposed = false;\n private flushDepth = 0;\n private flushing = false;\n private readonly pending = new Set<EffectNode>();\n private readonly listeners = new Set<ListenerSink>();\n private readonly rootScope: ScopeNode;\n private readonly onError: (error: unknown, context: RippleErrorContext) => void;\n\n constructor(options?: RippleOptions) {\n this.onError =\n options?.onError ??\n ((error) => {\n queueMicrotask(() => {\n throw error;\n });\n });\n this.rootScope = new ScopeNode(this, 'runtime');\n this.activeScope = this.rootScope;\n }\n\n get disposed(): boolean {\n return this.isDisposed;\n }\n\n get disposalSignal(): AbortSignal {\n return this.rootScope.disposalSignal;\n }\n\n readonly signal = <T>(initial: T, options?: SignalOptions<T>): Signal<T> => {\n this.assertActive();\n\n return new SignalNode(this, initial, options);\n };\n\n readonly computed = <T>(derive: () => T, options?: ComputedOptions<T>): Readable<T> => {\n this.assertActive();\n\n const node = new ComputedNode(this, derive, options);\n\n (this.activeEffectScope ?? this.activeScope).own(node);\n\n return node;\n };\n\n readonly effect = (callback: () => Cleanup | undefined, options?: EffectOptions): EffectHandle => {\n this.assertActive();\n\n const node = new EffectNode(this, callback, options);\n\n (this.activeEffectScope ?? this.activeScope).own(node);\n node.run();\n\n return node;\n };\n\n readonly createScope = (name?: string): Scope => {\n this.assertActive();\n\n const scope = new ScopeNode(this, name);\n\n // Scopes model explicit, caller-owned lifetimes. Unlike effects/computeds created during an\n // effect run, they deliberately attach to the enclosing scope rather than the per-run owner:\n // keyed DOM directives retain item scopes across reconciliation runs and dispose them only\n // when the item itself leaves the collection.\n this.activeScope.own(scope);\n\n return scope;\n };\n\n readonly batch = <T>(fn: () => T): T => {\n this.assertActive();\n\n return this.propagate(fn);\n };\n\n readonly untrack = <T>(fn: () => T): T => {\n this.assertActive();\n\n return this.withObserver(undefined, fn);\n };\n\n dispose(): void {\n if (this.isDisposed) return;\n\n this.isDisposed = true;\n this.rootScope.dispose();\n }\n\n /** Internal node guard: disposed runtimes allow inert reads but reject graph work and mutation. */\n assertActive(): void {\n if (this.isDisposed) throw new RippleDisposedError('Cannot use a disposed Ripple runtime.');\n }\n\n track(node: Dependency): void {\n const observer = this.activeObserver;\n\n if (observer?.collecting === undefined) return;\n\n observer.collecting.add(node);\n }\n\n clearDependencies(observer: ObserverNode): void {\n for (const dependency of observer.dependencies) dependency.dependents.delete(observer);\n observer.dependencies.clear();\n }\n\n collect<T>(observer: ObserverNode, fn: () => T): T {\n // On first run (no prior dependencies), commit partial dependencies even if\n // derive throws, otherwise the computed would have zero dependencies and never\n // be notified when its source changes, permanently stuck until a manual read.\n // On subsequent runs, keep previous dependencies (tested behavior).\n return this.collectWith(observer, fn, observer.dependencies.size === 0);\n }\n\n collectEffect<T>(observer: ObserverNode, fn: () => T): T {\n return this.collectWith(observer, fn, true);\n }\n\n withEffectScope<T>(scope: ScopeNode, fn: () => T): T {\n const previous = this.activeEffectScope;\n\n this.activeEffectScope = scope;\n\n try {\n return fn();\n } finally {\n this.activeEffectScope = previous;\n }\n }\n\n withObserver<T>(observer: ObserverNode | undefined, fn: () => T): T {\n const previous = this.activeObserver;\n\n this.activeObserver = observer;\n\n try {\n return fn();\n } finally {\n this.activeObserver = previous;\n }\n }\n\n withScope<T>(scope: ScopeNode, fn: () => T): T {\n const previousEffectScope = this.activeEffectScope;\n const previousScope = this.activeScope;\n\n this.activeEffectScope = undefined;\n this.activeScope = scope;\n\n try {\n return fn();\n } finally {\n this.activeEffectScope = previousEffectScope;\n this.activeScope = previousScope;\n }\n }\n\n enqueue(effect: EffectNode): void {\n this.pending.add(effect);\n\n if (this.flushDepth === 0) this.flush();\n }\n\n enqueueListener(sink: ListenerSink): void {\n this.listeners.add(sink);\n\n if (this.flushDepth === 0) this.flush();\n }\n\n propagate<T>(fn: () => T): T {\n this.flushDepth++;\n\n try {\n return fn();\n } finally {\n this.flushDepth--;\n\n if (this.flushDepth === 0) this.flush();\n }\n }\n\n report(error: unknown, context: RippleErrorContext): void {\n try {\n this.onError(error, context);\n } catch {\n // A failing error handler must not corrupt the graph or mask the\n // original failure; the default handler rethrows asynchronously instead.\n }\n }\n\n private collectWith<T>(observer: ObserverNode, fn: () => T, commitOnError: boolean): T {\n const previousObserver = this.activeObserver;\n const dependencies = new Set<Dependency>();\n\n observer.collecting = dependencies;\n this.activeObserver = observer;\n\n try {\n const result = fn();\n\n this.commitDependencies(observer, dependencies);\n\n return result;\n } catch (error) {\n if (commitOnError) this.commitDependencies(observer, dependencies);\n\n throw error;\n } finally {\n observer.collecting = undefined;\n this.activeObserver = previousObserver;\n }\n }\n\n private commitDependencies(observer: ObserverNode, next: Set<Dependency>): void {\n for (const dependency of observer.dependencies) {\n if (!next.has(dependency)) dependency.dependents.delete(observer);\n }\n\n for (const dependency of next) {\n if (!observer.dependencies.has(dependency)) dependency.dependents.add(observer);\n }\n\n observer.dependencies.clear();\n for (const dependency of next) observer.dependencies.add(dependency);\n }\n\n private flush(): void {\n if (this.flushing) return;\n\n this.flushing = true;\n\n let iterations = 0;\n\n try {\n while (this.pending.size > 0 || this.listeners.size > 0) {\n if (++iterations > MAX_FLUSH_ITERATIONS) {\n // A runaway effect (one that keeps re-triggering itself): report it\n // through the error channel and abandon this flush. Throwing from\n // here would unwind into the innocent write site that happened to\n // trigger the flush, after its value was already applied.\n this.report(new RippleCycleError(`infinite reactive flush (>${MAX_FLUSH_ITERATIONS} iterations)`), {\n kind: 'flush',\n });\n this.pending.clear();\n this.listeners.clear();\n break;\n }\n\n const effects = [...this.pending];\n const listeners = [...this.listeners];\n\n this.pending.clear();\n this.listeners.clear();\n\n for (const effect of effects) effect.run();\n\n for (const sink of listeners) {\n try {\n sink.listener();\n } catch (error) {\n this.report(error, { kind: 'listener' });\n }\n }\n }\n } finally {\n this.flushing = false;\n }\n }\n}\n\nexport const isReactive = <T>(value: T | Readable<T>): value is Readable<T> => {\n if (typeof value !== 'object' || value === null || (value as { [REACTIVE]?: unknown })[REACTIVE] !== true)\n return false;\n\n const candidate = value as { peek?: unknown; subscribe?: unknown; value?: unknown };\n\n return 'value' in candidate && typeof candidate.peek === 'function' && typeof candidate.subscribe === 'function';\n};\n"],"mappings":"gCAeA,IA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GAAiD,CAC7E,GAAI,OAAO,GAAU,WAAY,GAAmB,EAAmC,KAAc,GACnG,MAAO,GAET,IAAM,EAAY,EAElB,MAAO,UAAW,GAAa,OAAO,EAAU,MAAS,YAAc,OAAO,EAAU,WAAc,UACxG"}
package/dist/runtime.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Cleanup, ComputedOptions, EffectHandle, EffectOptions, Readable, RippleErrorContext, RippleEvent, RippleOptions, Scope, Signal, SignalOptions, Unsubscribe } from './types';
1
+ import type { Cleanup, ComputedOptions, EffectHandle, EffectOptions, Readable, RippleErrorContext, RippleOptions, Scope, Signal, SignalOptions, Unsubscribe } from './types';
2
2
  export declare const REACTIVE: unique symbol;
3
3
  type Dependency = ReactiveNode<unknown>;
4
4
  /** Anything that wants to hear that a dependency changed: the only member a producer may call. */
@@ -81,8 +81,7 @@ export declare class ReactiveRuntime {
81
81
  private readonly pending;
82
82
  private readonly listeners;
83
83
  private readonly rootScope;
84
- private readonly tappers;
85
- private readonly errorPolicy;
84
+ private readonly onError;
86
85
  constructor(options?: RippleOptions);
87
86
  get disposed(): boolean;
88
87
  get disposalSignal(): AbortSignal;
@@ -92,10 +91,6 @@ export declare class ReactiveRuntime {
92
91
  readonly createScope: (name?: string) => Scope;
93
92
  readonly batch: <T>(fn: () => T) => T;
94
93
  readonly untrack: <T>(fn: () => T) => T;
95
- /** Runtime observability: see `Ripple.tap()`. */
96
- readonly tap: (handler: (event: RippleEvent) => void, options?: {
97
- signal?: AbortSignal;
98
- }) => Unsubscribe;
99
94
  dispose(): void;
100
95
  /** Internal node guard: disposed runtimes allow inert reads but reject graph work and mutation. */
101
96
  assertActive(): void;
@@ -109,7 +104,6 @@ export declare class ReactiveRuntime {
109
104
  enqueue(effect: EffectNode): void;
110
105
  enqueueListener(sink: ListenerSink): void;
111
106
  propagate<T>(fn: () => T): T;
112
- emit(event: RippleEvent): void;
113
107
  report(error: unknown, context: RippleErrorContext): void;
114
108
  private collectWith;
115
109
  private commitDepend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GAAG,IAAI;IAMjC,eAAe,CAAC,IAAI,EAAE,YAAY,GAAG,IAAI;IAMzC,SAAS,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC;IAY5B,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,kBAAkB,GAAG,IAAI;IASzD,OAAO,CAAC,WAAW;IAuBnB,OAAO,CAAC,kBAAkB;IAa1B,OAAO,CAAC,KAAK;CA0Cd;AAED,eAAO,MAAM,UAAU,GAAI,CAAC,EAAE,OAAO,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,KAAG,KAAK,IAAI,QAAQ,CAAC,CAAC,CAOzE,CAAC"}
package/dist/runtime.js CHANGED
@@ -1,2 +1,2 @@
1
- import{RippleComputedCycleError as e,RippleDisposedRuntimeError as t,RippleDisposedScopeError as n,RippleInfiniteLoopError as r}from"./errors.js";var i=Symbol.for(`@vielzeug/ripple/reactive`),a=100,o=Symbol(`ripple.unset`),ReactiveNode=class{[i]=!0;dependents=new Set;name;runtime;constructor(e,t){this.runtime=e,this.name=t}subscribe(e){this.runtime.assertActive(),this.peek();let t={listener:e,onDependencyChanged:()=>this.runtime.enqueueListener(t)};return this.dependents.add(t),()=>this.dependents.delete(t)}notify(){for(let e of[...this.dependents])e.onDependencyChanged()}},SignalNode=class extends ReactiveNode{current;equals;constructor(e,t,n){super(e,n?.name),this.current=t,this.equals=n?.equals??Object.is}get value(){return this.runtime.track(this),this.current}set value(e){if(this.runtime.assertActive(),this.equals(this.current,e))return;let t=this.current;this.current=e,this.runtime.emit({name:this.name,next:e,previous:t,type:`write`}),this.runtime.propagate(()=>this.notify())}peek(){return this.current}update(e){this.value=e(this.current)}},ComputedNode=class extends ReactiveNode{dependencies=new Set;computing=!1;disposed=!1;dirty=!0;current=o;derive;equals;owner;constructor(e,t,n){super(e,n?.name),this.derive=t,this.equals=n?.equals??Object.is}get value(){return this.runtime.track(this),this.refresh(),this.current}peek(){return this.refresh(),this.current}onDependencyChanged(){if(!this.disposed&&(this.dirty||=!0,this.dependents.size>0))try{this.refresh()&&this.notify()}catch(e){this.runtime.report(e,{kind:`computed`,name:this.name})}}setOwner(e){this.owner=e}dispose(){this.disposed||(this.disposed=!0,this.owner?.release(this),this.owner=void 0,this.runtime.clearDependencies(this),this.dependents.clear())}refresh(){if(!this.dirty||this.disposed)return!1;if(this.computing){let t=this.name===void 0?``:` "${this.name}"`;throw new e(`computed cycle detected${t}`)}this.computing=!0,this.runtime.emit({name:this.name,type:`compute`});try{let e=this.runtime.collect(this,this.derive),t=this.current===o||!this.equals(this.current,e);return this.current=e,this.dirty=!1,t}finally{this.computing=!1}}},ScopeNode=class{disposalController=new AbortController;owned=new Set;name;isDisposed=!1;owner;runtime;constructor(e,t){this.runtime=e,this.name=t}get disposed(){return this.isDisposed}get disposalSignal(){return this.disposalController.signal}own(e){e.setOwner(this),this.owned.add(e)}release(e){this.owned.delete(e)}setOwner(e){this.owner=e}run(e){if(this.isDisposed)throw new n(`Cannot run a disposed scope.`);return this.runtime.withScope(this,e)}dispose(){if(!this.isDisposed){this.isDisposed=!0,this.owner?.release(this),this.owner=void 0;for(let e of[...this.owned].reverse())e.dispose();this.owned.clear(),this.disposalController.abort(),this.runtime.emit({name:this.name,node:`scope`,type:`dispose`})}}[Symbol.dispose](){this.dispose()}},EffectNode=class{dependencies=new Set;disposalController=new AbortController;cleanup;isDisposed=!1;ownershipScope;runScope;callback;options;runtime;constructor(e,t,n){this.runtime=e,this.callback=t,this.options=n}get disposed(){return this.isDisposed}get disposalSignal(){return this.disposalController.signal}setOwner(e){this.ownershipScope=e}onDependencyChanged(){this.isDisposed||this.runtime.enqueue(this)}run(){if(this.isDisposed)return;this.runScope?.dispose(),this.runScope=void 0,this.runCleanup(),this.runtime.emit({name:this.options?.name,type:`effect`});let e=new ScopeNode(this.runtime);try{let t=this.runtime.withEffectScope(e,()=>this.runtime.collectEffect(this,this.callback));this.runScope=e,this.cleanup=typeof t==`function`?t:void 0,this.isDisposed&&(this.runScope.dispose(),this.runScope=void 0,this.runCleanup())}catch(t){e.dispose(),this.runtime.report(t,{kind:`effect`,name:this.options?.name})}}dispose(){this.isDisposed||(this.isDisposed=!0,this.ownershipScope?.release(this),this.ownershipScope=void 0,this.runScope?.dispose(),this.runScope=void 0,this.runtime.clearDependencies(this),this.runCleanup(),this.disposalController.abort(),this.runtime.emit({name:this.options?.name,node:`effect`,type:`dispose`}))}[Symbol.dispose](){this.dispose()}runCleanup(){let e=this.cleanup;if(this.cleanup=void 0,e!==void 0)try{e()}catch(e){this.runtime.report(e,{kind:`cleanup`,name:this.options?.name})}}},ReactiveRuntime=class{activeEffectScope;activeObserver;activeScope;isDisposed=!1;flushDepth=0;flushing=!1;pending=new Set;listeners=new Set;rootScope;tappers=new Set;errorPolicy;constructor(e){this.errorPolicy=e?.errorPolicy??`throw`,this.rootScope=new ScopeNode(this,`runtime`),this.activeScope=this.rootScope}get disposed(){return this.isDisposed}get disposalSignal(){return this.rootScope.disposalSignal}signal=(e,t)=>(this.assertActive(),new SignalNode(this,e,t));computed=(e,t)=>{this.assertActive();let n=new ComputedNode(this,e,t);return(this.activeEffectScope??this.activeScope).own(n),n};effect=(e,t)=>{this.assertActive();let n=new EffectNode(this,e,t);return(this.activeEffectScope??this.activeScope).own(n),n.run(),n};createScope=e=>{this.assertActive();let t=new ScopeNode(this,e);return this.activeScope.own(t),t};batch=e=>(this.assertActive(),this.propagate(e));untrack=e=>(this.assertActive(),this.withObserver(void 0,e));tap=(e,t)=>{if(this.isDisposed)return()=>{};let n=t?.signal;if(n?.aborted)return this.tappers.delete(e),()=>{};if(this.tappers.add(e),n){let onAbort=()=>this.tappers.delete(e);return n.addEventListener(`abort`,onAbort,{once:!0}),()=>{this.tappers.delete(e),n.removeEventListener(`abort`,onAbort)}}return()=>this.tappers.delete(e)};dispose(){this.isDisposed||(this.isDisposed=!0,this.rootScope.dispose(),this.emit({node:`graph`,type:`dispose`}),this.tappers.clear())}assertActive(){if(this.isDisposed)throw new t(`Cannot use a disposed Ripple runtime.`)}track(e){let t=this.activeObserver;t?.collecting!==void 0&&t.collecting.add(e)}clearDependencies(e){for(let t of e.dependencies)t.dependents.delete(e);e.dependencies.clear()}collect(e,t){return this.collectWith(e,t,e.dependencies.size===0)}collectEffect(e,t){return this.collectWith(e,t,!0)}withEffectScope(e,t){let n=this.activeEffectScope;this.activeEffectScope=e;try{return t()}finally{this.activeEffectScope=n}}withObserver(e,t){let n=this.activeObserver;this.activeObserver=e;try{return t()}finally{this.activeObserver=n}}withScope(e,t){let n=this.activeEffectScope,r=this.activeScope;this.activeEffectScope=void 0,this.activeScope=e;try{return t()}finally{this.activeEffectScope=n,this.activeScope=r}}enqueue(e){this.pending.add(e),this.flushDepth===0&&this.flush()}enqueueListener(e){this.listeners.add(e),this.flushDepth===0&&this.flush()}propagate(e){this.flushDepth++;try{return e()}finally{this.flushDepth--,this.flushDepth===0&&this.flush()}}emit(e){if(this.tappers.size!==0)for(let t of this.tappers)try{t(e)}catch{}}report(e,t){this.emit({context:t,error:e,type:`error`}),this.errorPolicy===`throw`&&queueMicrotask(()=>{throw e})}collectWith(e,t,n){let r=this.activeObserver,i=new Set;e.collecting=i,this.activeObserver=e;try{let n=t();return this.commitDependencies(e,i),n}catch(t){throw n&&this.commitDependencies(e,i),t}finally{e.collecting=void 0,this.activeObserver=r}}commitDependencies(e,t){for(let n of e.dependencies)t.has(n)||n.dependents.delete(e);for(let n of t)e.dependencies.has(n)||n.dependents.add(e);e.dependencies.clear();for(let n of t)e.dependencies.add(n)}flush(){if(this.flushing)return;this.flushing=!0;let e=0;try{for(;this.pending.size>0||this.listeners.size>0;){if(++e>a)throw new r(`infinite reactive flush (>${a} iterations)`);let t=[...this.pending],n=[...this.listeners];this.pending.clear(),this.listeners.clear();for(let e of t)e.run();for(let e of n)try{e.listener()}catch(e){this.report(e,{kind:`listener`})}}}finally{this.flushing=!1}}},isReactive=e=>{if(typeof e!=`object`||!e||e[i]!==!0)return!1;let t=e;return`value`in t&&typeof t.peek==`function`&&typeof t.subscribe==`function`};export{i as REACTIVE,ReactiveRuntime,isReactive};
1
+ import{RippleCycleError as e,RippleDisposedError as t}from"./errors.js";var n=Symbol.for(`@vielzeug/ripple/reactive`),r=100,i=Symbol(`ripple.unset`),ReactiveNode=class{[n]=!0;dependents=new Set;name;runtime;constructor(e,t){this.runtime=e,this.name=t}subscribe(e){this.runtime.assertActive(),this.peek();let t={listener:e,onDependencyChanged:()=>this.runtime.enqueueListener(t)};return this.dependents.add(t),()=>this.dependents.delete(t)}notify(){for(let e of[...this.dependents])e.onDependencyChanged()}},SignalNode=class extends ReactiveNode{current;equals;constructor(e,t,n){super(e,n?.name),this.current=t,this.equals=n?.equals??Object.is}get value(){return this.runtime.track(this),this.current}set value(e){this.runtime.assertActive(),!this.equals(this.current,e)&&(this.current=e,this.runtime.propagate(()=>this.notify()))}peek(){return this.current}update(e){this.value=e(this.current)}},ComputedNode=class extends ReactiveNode{dependencies=new Set;computing=!1;disposed=!1;dirty=!0;current=i;derive;equals;owner;constructor(e,t,n){super(e,n?.name),this.derive=t,this.equals=n?.equals??Object.is}get value(){return this.runtime.track(this),this.refresh(),this.evaluated()}peek(){return this.refresh(),this.evaluated()}evaluated(){if(this.current===i){let e=this.name===void 0?``:` "${this.name}"`;throw new t(`computed${e} was disposed before it was ever evaluated`)}return this.current}onDependencyChanged(){if(!this.disposed&&(this.dirty||=!0,this.dependents.size>0))try{this.refresh()&&this.notify()}catch(e){this.runtime.report(e,{kind:`computed`,name:this.name})}}setOwner(e){this.owner=e}dispose(){this.disposed||(this.disposed=!0,this.owner?.release(this),this.owner=void 0,this.runtime.clearDependencies(this),this.dependents.clear())}refresh(){if(!this.dirty||this.disposed)return!1;if(this.computing){let t=this.name===void 0?``:` "${this.name}"`;throw new e(`computed cycle detected${t}`)}this.computing=!0;try{let e=this.runtime.collect(this,this.derive),t=this.current===i||!this.equals(this.current,e);return this.current=e,this.dirty=!1,t}finally{this.computing=!1}}},ScopeNode=class{disposalController=new AbortController;owned=new Set;name;isDisposed=!1;owner;runtime;constructor(e,t){this.runtime=e,this.name=t}get disposed(){return this.isDisposed}get disposalSignal(){return this.disposalController.signal}own(e){e.setOwner(this),this.owned.add(e)}release(e){this.owned.delete(e)}setOwner(e){this.owner=e}run(e){if(this.isDisposed)throw new t(`Cannot run a disposed scope.`);return this.runtime.withScope(this,e)}dispose(){if(!this.isDisposed){this.isDisposed=!0,this.owner?.release(this),this.owner=void 0;for(let e of[...this.owned].reverse())e.dispose();this.owned.clear(),this.disposalController.abort()}}[Symbol.dispose](){this.dispose()}},EffectNode=class{dependencies=new Set;disposalController=new AbortController;cleanup;isDisposed=!1;ownershipScope;runScope;callback;options;runtime;constructor(e,t,n){this.runtime=e,this.callback=t,this.options=n}get disposed(){return this.isDisposed}get disposalSignal(){return this.disposalController.signal}setOwner(e){this.ownershipScope=e}onDependencyChanged(){this.isDisposed||this.runtime.enqueue(this)}run(){if(this.isDisposed)return;this.runScope?.dispose(),this.runScope=void 0,this.runCleanup();let e=new ScopeNode(this.runtime);try{let t=this.runtime.withEffectScope(e,()=>this.runtime.collectEffect(this,this.callback));this.runScope=e,this.cleanup=typeof t==`function`?t:void 0,this.isDisposed&&(this.runScope.dispose(),this.runScope=void 0,this.runCleanup())}catch(t){e.dispose(),this.runtime.report(t,{kind:`effect`,name:this.options?.name})}}dispose(){this.isDisposed||(this.isDisposed=!0,this.ownershipScope?.release(this),this.ownershipScope=void 0,this.runScope?.dispose(),this.runScope=void 0,this.runtime.clearDependencies(this),this.runCleanup(),this.disposalController.abort())}[Symbol.dispose](){this.dispose()}runCleanup(){let e=this.cleanup;if(this.cleanup=void 0,e!==void 0)try{e()}catch(e){this.runtime.report(e,{kind:`cleanup`,name:this.options?.name})}}},ReactiveRuntime=class{activeEffectScope;activeObserver;activeScope;isDisposed=!1;flushDepth=0;flushing=!1;pending=new Set;listeners=new Set;rootScope;onError;constructor(e){this.onError=e?.onError??(e=>{queueMicrotask(()=>{throw e})}),this.rootScope=new ScopeNode(this,`runtime`),this.activeScope=this.rootScope}get disposed(){return this.isDisposed}get disposalSignal(){return this.rootScope.disposalSignal}signal=(e,t)=>(this.assertActive(),new SignalNode(this,e,t));computed=(e,t)=>{this.assertActive();let n=new ComputedNode(this,e,t);return(this.activeEffectScope??this.activeScope).own(n),n};effect=(e,t)=>{this.assertActive();let n=new EffectNode(this,e,t);return(this.activeEffectScope??this.activeScope).own(n),n.run(),n};createScope=e=>{this.assertActive();let t=new ScopeNode(this,e);return this.activeScope.own(t),t};batch=e=>(this.assertActive(),this.propagate(e));untrack=e=>(this.assertActive(),this.withObserver(void 0,e));dispose(){this.isDisposed||(this.isDisposed=!0,this.rootScope.dispose())}assertActive(){if(this.isDisposed)throw new t(`Cannot use a disposed Ripple runtime.`)}track(e){let t=this.activeObserver;t?.collecting!==void 0&&t.collecting.add(e)}clearDependencies(e){for(let t of e.dependencies)t.dependents.delete(e);e.dependencies.clear()}collect(e,t){return this.collectWith(e,t,e.dependencies.size===0)}collectEffect(e,t){return this.collectWith(e,t,!0)}withEffectScope(e,t){let n=this.activeEffectScope;this.activeEffectScope=e;try{return t()}finally{this.activeEffectScope=n}}withObserver(e,t){let n=this.activeObserver;this.activeObserver=e;try{return t()}finally{this.activeObserver=n}}withScope(e,t){let n=this.activeEffectScope,r=this.activeScope;this.activeEffectScope=void 0,this.activeScope=e;try{return t()}finally{this.activeEffectScope=n,this.activeScope=r}}enqueue(e){this.pending.add(e),this.flushDepth===0&&this.flush()}enqueueListener(e){this.listeners.add(e),this.flushDepth===0&&this.flush()}propagate(e){this.flushDepth++;try{return e()}finally{this.flushDepth--,this.flushDepth===0&&this.flush()}}report(e,t){try{this.onError(e,t)}catch{}}collectWith(e,t,n){let r=this.activeObserver,i=new Set;e.collecting=i,this.activeObserver=e;try{let n=t();return this.commitDependencies(e,i),n}catch(t){throw n&&this.commitDependencies(e,i),t}finally{e.collecting=void 0,this.activeObserver=r}}commitDependencies(e,t){for(let n of e.dependencies)t.has(n)||n.dependents.delete(e);for(let n of t)e.dependencies.has(n)||n.dependents.add(e);e.dependencies.clear();for(let n of t)e.dependencies.add(n)}flush(){if(this.flushing)return;this.flushing=!0;let t=0;try{for(;this.pending.size>0||this.listeners.size>0;){if(++t>r){this.report(new e(`infinite reactive flush (>${r} iterations)`),{kind:`flush`}),this.pending.clear(),this.listeners.clear();break}let n=[...this.pending],i=[...this.listeners];this.pending.clear(),this.listeners.clear();for(let e of n)e.run();for(let e of i)try{e.listener()}catch(e){this.report(e,{kind:`listener`})}}}finally{this.flushing=!1}}},isReactive=e=>{if(typeof e!=`object`||!e||e[n]!==!0)return!1;let t=e;return`value`in t&&typeof t.peek==`function`&&typeof t.subscribe==`function`};export{n as REACTIVE,ReactiveRuntime,isReactive};
2
2
  //# sourceMappingURL=runtime.js.map