uneventful 0.0.7 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{call-or-wait-DHkBd_bM.mjs → call-or-wait-COAmx32w.mjs} +24 -92
- package/dist/call-or-wait-COAmx32w.mjs.map +1 -0
- package/dist/mod.d.ts +1 -1
- package/dist/mod.mjs +7 -4
- package/dist/mod.mjs.map +1 -1
- package/dist/signals.d.ts +47 -22
- package/dist/signals.mjs +143 -58
- package/dist/signals.mjs.map +1 -1
- package/dist/{sinks-kEzJo6Hc.d.ts → sinks-5TuxCRtX.d.ts} +26 -1
- package/dist/utils-P0JEpWXG.mjs +87 -0
- package/dist/utils-P0JEpWXG.mjs.map +1 -0
- package/dist/utils.d.ts +93 -1
- package/dist/utils.mjs +1 -17
- package/dist/utils.mjs.map +1 -1
- package/package.json +1 -1
- package/dist/call-or-wait-DHkBd_bM.mjs.map +0 -1
package/dist/signals.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signals.mjs","sources":["../src/cells.ts","../src/rules.ts","../src/signals.ts"],"sourcesContent":["import { Context, current, makeCtx, swapCtx } from \"./ambient.ts\";\nimport { type RuleQueue, currentRule, ruleQueue, defaultQ, ruleStops } from \"./scheduling.ts\";\nimport { Job, OptionalCleanup, RecalcSource } from \"./types.ts\"\nimport { detached, getJob, makeJob } from \"./tracking.ts\";\nimport { Connection, Inlet, IsStream, Sink, Source, backpressure } from \"./streams.ts\";\nimport { apply, setMap } from \"./utils.ts\";\nimport { isError, markHandled } from \"./results.ts\";\nimport { nullCtx } from \"./internals.ts\";\nimport { defer } from \"./defer.ts\";\n\n/**\n * Error indicating a rule has attempted to write a value it indirectly\n * depends on, or which has already been read by another rule in the current\n * batch. (Also thrown when a cached function attempts to write a value at all,\n * directly or indirectly.)\n *\n * @category Errors\n */\nexport class WriteConflict extends Error {}\n\n/**\n * Error indicating a rule has attempted to write a value it directly depends\n * on, or a cached function has called itself, directly or indirectly.\n *\n * @category Errors\n */\nexport class CircularDependency extends Error {}\n\nvar timestamp = 1;\n\n/** recalcWhen(fn): map fn -> signal */\nconst fntrackers = new WeakMap<Function, () => number>();\n\n/** recalcWhen(key, factory): map factory -> key -> signal */\nconst obtrackers = new WeakMap<Function, WeakMap<WeakKey, () => number>>();\n\n/** stream controllers for stream+recalcWhen signals */\nconst streamtrackers = new WeakMap<Cell, ()=>void>();\n\nconst dirtyStack: Cell[] = [];\n\nfunction markDependentsDirty(cell: Cell) {\n // We don't set validThrough here because that's how we tell the cell's been read/depended on\n const latestSource = cell.latestSource = timestamp;\n for(; cell; cell = dirtyStack.pop()) {\n for (let sub=cell.subscribers; sub; sub = sub.nT) {\n const tgt = sub.tgt;\n if (tgt.latestSource >= latestSource) continue;\n tgt.latestSource = latestSource;\n tgt.queue?.add(tgt);\n if (tgt.subscribers) dirtyStack.push(tgt);\n }\n }\n}\n\n// The .compute for a cell whose value has been explicitly set\nfunction returnValue(this: Cell) {\n return this.value;\n}\n\n// The compute for a cell whose value is an explicit error\nfunction throwValue(this: Cell) {\n throw this.value;\n}\n\n/**\n * Cells that are known to be clean as of this timestamp, but have not been\n * marked as read yet (and whose sources might also not be marked read). This\n * lets us lazily determine if a cell's value has been depended on (i.e.\n * \"virtually read\") in this timestamp, even if it wasn't *actually* read.\n */\nconst notCaughtUp = [] as Cell[];\n\nconst enum Is {\n Compute = 1 << 2,\n Error = 1 << 4,\n Running = 1 << 5,\n Stream = 1 << 6,\n Mutable = 1 << 7,\n Demanded = 1 << 8, // Stream has been queued for demand update\n Demand = Stream | Demanded, // Mask for checking if stream + unqueued\n Variable = Compute | Mutable,\n}\n\ntype Subscription = {\n /** Source of the subscription */\n src: Cell\n nS: Subscription,\n pS: Subscription,\n\n /** Subscriber */\n tgt: Cell\n nT: Subscription,\n pT: Subscription,\n\n ts: number,\n\n /* stack for active subscriptions on sources */\n old: Subscription\n}\n\nvar freesubs: Subscription;\n\nfunction mksub(source: Cell, target: Cell) {\n let sub: Subscription = freesubs;\n if (sub) {\n freesubs = sub.old;\n sub.src = source; sub.nS = undefined; sub.pS = target.sources;\n sub.tgt = target; sub.nT = sub.pT = undefined;\n sub.ts = source.lastChanged; sub.old = source.adding;\n } else sub = {\n src: source, nS: undefined, pS: target.sources,\n tgt: target, nT: undefined, pT: undefined,\n ts: source.lastChanged, old: source.adding\n }\n // Add subscription to tail of target's sources\n if (target.sources) target.sources.nS = sub;\n target.sources = sub;\n // track that this source has had a subscription added during this calculation\n source.adding = sub;\n // Set up reciprocal subscription if needed\n if (target.subscribers || target.queue) source.subscribe(sub);\n}\n\nfunction delsub(sub: Subscription) {\n sub.src.unsubscribe(sub);\n if (sub.nS) sub.nS.pS = sub.pS;\n if (sub.pS) sub.pS.nS = sub.nS;\n sub.src = sub.tgt = sub.nS = sub.pS = sub.nT = sub.pT = undefined;\n sub.old = freesubs;\n freesubs = sub;\n}\n\nfunction subscribeAll(s: Subscription) {\n if (s) while (s.pS) s = s.pS; else return;\n for(; s; s = s.nS) s.src.subscribe(s);\n}\n\nfunction unsubscribeAll(s: Subscription) {\n if (s) while (s.pS) s = s.pS; else return;\n for(; s; s = s.nS) s.src.unsubscribe(s);\n}\n\nconst sentinel = {} // a unique value for uniqueness checking\n\nexport class Cell {\n value: any = undefined // the value\n validThrough = 0; // timestamp of most recent validation or recalculation\n lastChanged = 0; // timestamp of last value change\n latestSource = timestamp; // max lastChanged of this cell or any ancestor source\n flags = 0;\n ctx: Context = undefined;\n /** The subscription being added during the current calculation - used for uniqueness */\n adding: Subscription = undefined;\n /** Linked list of sources */\n sources: Subscription = undefined;\n /** Linked list of targets */\n subscribers: Subscription = undefined;\n queue: RuleQueue = undefined;\n\n /**\n * The computation to be performed (if {@link Is.Compute}) or the\n * setup/teardown for {@link Is.Stream}.\n */\n compute: (sub?: boolean) => any = returnValue;\n\n stream<T>(sink: Sink<T>, _conn?: Connection, inlet?: Inlet) {\n let lastValue = sentinel;\n Cell.mkRule(() => {\n const val = this.getValue();\n if (val !== lastValue) {\n const old = swapCtx(nullCtx);\n try { sink(lastValue = val); } finally { swapCtx(old); }\n }\n }, inlet ? ruleQueue(backpressure(inlet)) : defaultQ);\n return IsStream;\n }\n\n getValue() {\n if (arguments.length) return apply(this.stream, this, arguments);\n this.catchUp();\n const dep = current.cell;\n // Only create a dependency if our value can change\n if (dep && this.flags & Is.Variable) {\n if (this.flags & Is.Running) throw new CircularDependency(\"Cached function dependency cycle\");\n // See if we've already got a subscription node for the dependent\n let s = this.adding;\n if (!s || s.tgt !== dep) {\n // nope, it's new\n mksub(this, dep);\n } else {\n // Yep, see if it's a hangover from last time\n if (s.ts === -1) {\n // yep, mark it reused\n s.ts = this.lastChanged;\n if (s.nS) { // if not at end, move it\n s.nS.pS = s.pS;\n if (s.pS) s.pS.nS = s.nS;\n s.nS = undefined;\n s.pS = dep.sources;\n dep.sources.nS = s;\n dep.sources = s;\n }\n }\n // else it's already done, no need to do anything.\n }\n }\n if (this.flags & Is.Error) throw this.value;\n return this.value;\n }\n\n shouldWrite(changed: boolean) {\n const cell = current.cell || currentRule;\n if (cell) {\n // When a cell changes within a sweep (i.e. from an active rule or other\n // cell), we need to check if it's not a circular update or disallowed\n // side-effect. In such a case we bail out with an error, even if the\n // change is idempotent. (To avoid hiding value-dependent errors.)\n if (!cell.queue) throw new WriteConflict(\"Side-effects not allowed outside rules\");\n if (this.adding && this.adding.tgt === cell) throw new CircularDependency(\"Can't update direct dependency\");\n if (this.validThrough === timestamp || this.hasBeenRead()) throw new WriteConflict(\"Value already used\");\n } else if (changed) {\n // We are *not* in a sweep, but *did* have a change. So we may need to advance\n // the timestamp, if we might have had readers in the current one.\n if (this.validThrough === timestamp || notCaughtUp.length) { ++timestamp; notCaughtUp.length = 0; }\n } else {\n // Not in a sweep and no change -- no need to actually write anything\n return false;\n }\n // If we changed as of the current timestamp, we're already dirty\n // Otherwise, we should flag our subscribers as such.\n (this.lastChanged === timestamp) || markDependentsDirty(this);\n // If we have sources, reset the subscription timestamp of the first one\n // to force a recalculation on our next catchUp().\n if (this.sources) this.sources.ts = 0;\n return true;\n }\n\n setValue(val: any, isErr: boolean) {\n if (this.shouldWrite(val !== this.value || isErr !== !!(this.flags & Is.Error))) {\n this.value = val;\n this.lastChanged = timestamp;\n this.flags = isErr ? this.flags | Is.Error : this.flags & ~Is.Error;\n }\n // We always reset the compute here because we might have been in the\n // Calc state. But we don't clear the Calc flag because we might need\n // any previous sources to be released or unsubscribed. (Which will\n // happen on our next recalc.)\n this.compute = isErr ? throwValue : returnValue;\n }\n\n setCalc(compute: () => any) {\n if (this.shouldWrite(compute !== this.compute)) {\n this.flags |= Is.Compute;\n this.compute = compute;\n this.ctx ||= makeCtx(null, this);\n }\n }\n\n hasBeenRead() {\n if (notCaughtUp.length) {\n for(const cell of notCaughtUp) cell.catchUp();\n notCaughtUp.length = 0;\n }\n return this.validThrough === timestamp;\n }\n\n catchUp(): void {\n const {validThrough} = this;\n if (validThrough === timestamp) return;\n this.validThrough = timestamp;\n if (!(this.flags & Is.Compute)) return;\n if (this.sources) {\n for(let sub=this.sources; sub; sub = sub.nS) {\n const s = sub.src;\n // changed since our last compute? we're definitely dirty\n if (sub.ts !== s.lastChanged) return this.doRecalc();\n // if source is clean, skip it (most should be)\n // (note: only cells w/subscribers can be trusted as to their\n // latestSource, as cacheds with no subscribers don't get\n // notified by their upstreams)\n if (s.subscribers && s.latestSource <= validThrough) continue;\n // not a simple yes or no -- \"it's complicated\" -- so recurse\n s.catchUp();\n if (s.lastChanged > validThrough) {\n return this.doRecalc();\n }\n }\n // If we got to this point, we didn't need to recalc, but that means\n // none of our sources actually *changed*, despite at least one being\n // dirty. But that means we \"virtually\" read the clean values and\n // therefore depended on them... which means if they get written to,\n // either the timestamp must change or the write must be blocked.\n //\n // So we put them on our notCaughtUp list, in order to prevent rules\n // from changing them (or their sources) in the same timestamp, and\n // so that non-rule writes will know to update the timestamp.\n for(let sub=this.sources; sub; sub = sub.nS) {\n if (sub.src.validThrough !== timestamp) notCaughtUp.push(sub.src);\n }\n } else return this.doRecalc();\n }\n\n doRecalc() {\n const oldCtx = swapCtx(this.ctx);\n for(let sub = this.sources; sub; sub = sub.nS) {\n sub.ts = -1; // mark stale for possible reuse\n // attach sub to its source, so we can look it up\n sub.old = sub.src.adding;\n sub.src.adding = sub;\n this.sources = sub;\n }\n this.flags |= Is.Running;\n try {\n try {\n const future = this.compute();\n if (future !== this.value || !this.lastChanged || this.flags & Is.Error) {\n this.value = future;\n this.lastChanged = timestamp;\n }\n this.flags &= ~Is.Error;\n } catch(e) {\n this.flags |= Is.Error\n this.value = e;\n this.lastChanged = timestamp;\n if (currentRule === this) throw e;\n }\n } finally {\n this.flags &= ~Is.Running;\n swapCtx(oldCtx);\n // reset this.src to the head of the list, dropping stale subscriptions\n let head: Subscription;\n for(let sub = this.sources; sub; ) {\n const pS = sub.pS;\n sub.src.adding = sub.old;\n sub.old = undefined;\n if (sub.ts === -1) delsub(sub); else head = sub;\n sub = pS;\n }\n this.sources = head;\n if (!head) {\n // without sources, we can never change or be invalidated, so\n // revert to settable value() or permanent constant\n this.flags &= ~Is.Compute;\n }\n }\n }\n\n stop() {\n this.setQ(null);\n ruleStops.get(this)?.();\n }\n\n setQ(queue = defaultQ) {\n // Don't unsubscribe if we have subscribers or there's going to be a queue\n queue || this.subscribers || unsubscribeAll(this.sources);\n if (this.queue) {\n // Only add to new queue if queued on old\n if (this.queue.has(this)) queue?.add(this);\n this.queue.delete(this);\n queue || this.ctx.job?.restart();\n } else if (queue) {\n // initial queue or re-enable, schedule it\n queue.add(this);\n // If we already have subscribers, we're already subscribed\n this.subscribers || subscribeAll(this.sources);\n }\n this.queue = queue;\n }\n\n subscribe(sub: Subscription) {\n if (!this.subscribers) {\n this.queue || subscribeAll(this.sources);\n // subscribe to source\n if ((this.flags & Is.Demand) === Is.Stream) this.updateDemand();\n }\n if (this.subscribers !== sub && !sub.pT) { // avoid adding already-added subs\n sub.nT = this.subscribers;\n if (this.subscribers) this.subscribers.pT = sub;\n this.subscribers = sub;\n }\n }\n\n unsubscribe(sub: Subscription) {\n if (sub.nT) sub.nT.pT = sub.pT;\n if (sub.pT) sub.pT.nT = sub.nT;\n if (this.subscribers === sub) this.subscribers = sub.nT;\n sub.nT = sub.pT = undefined;\n if (!this.subscribers) {\n this.queue || unsubscribeAll(this.sources);\n // unsubscribe from source\n if ((this.flags & Is.Demand) === Is.Stream) this.updateDemand();\n }\n }\n\n static mkValue<T>(val: T) {\n const cell = new Cell;\n cell.flags = Is.Mutable;\n cell.value = val;\n cell.lastChanged = timestamp;\n return cell;\n }\n\n updateDemand() {\n this.flags |= Is.Demanded;\n defer(streamtrackers.get(this));\n }\n\n static mkStream<T>(src: Source<T>, val?: T) {\n const cell = this.mkValue(val);\n cell.flags |= Is.Stream;\n const ctx = makeCtx();\n const write = (v: T) => { cell.setValue(v, false); };\n let job: Job<void>;\n streamtrackers.set(cell, () => {\n if (!(cell.flags & Is.Demanded)) return;\n cell.flags &= ~(Is.Demanded);\n if (!cell.subscribers) {\n // Last subscriber is gone, so reset to default value\n write(val);\n job?.end(); // unsubscribe from source\n return\n }\n if (job) return;\n job = ctx.job = makeJob<void>().do(r => {\n if (isError(r)) {\n cell.setValue(markHandled(r), true);\n } else {\n cell.setValue(val, false);\n }\n ctx.job = job = undefined;\n });\n const old = swapCtx(ctx);\n try {\n src(write, job);\n } catch(e) {\n job.end();\n detached.asyncThrow(e);\n } finally {\n swapCtx(old);\n }\n });\n return cell;\n }\n\n recalcWhen(src: RecalcSource): void;\n recalcWhen<T extends WeakKey>(key: T, factory: (key: T) => RecalcSource): void;\n recalcWhen<T extends WeakKey>(fnOrKey: T | RecalcSource, fn?: (key: T) => RecalcSource) {\n let trackers: WeakMap<WeakKey, () => number> = fn ?\n obtrackers.get(fn) || setMap(obtrackers, fn, new WeakMap) :\n fntrackers\n ;\n let signal = trackers.get(fnOrKey);\n if (!signal) {\n const src = fn ? fn(<T>fnOrKey) : <RecalcSource> fnOrKey;\n let ct = 0;\n const c = Cell.mkStream(s => (src(() => s(++ct)), IsStream), ct);\n trackers.set(fnOrKey, signal = c.getValue.bind(c));\n }\n signal(); // Subscribe to the cell\n }\n\n static mkCached<T>(compute: () => T) {\n const cell = new Cell;\n cell.compute = compute;\n cell.ctx = makeCtx(null, cell);\n cell.flags = Is.Compute;\n return cell;\n }\n\n static mkRule(fn: (stop: () => void) => OptionalCleanup, q: RuleQueue) {\n const cell = new Cell, outer = getJob(), job = makeJob(), stop = cell.stop.bind(cell);\n outer === detached || ruleStops.set(cell, outer.release(stop));\n cell.compute = () => {\n try {\n job.restart().must(fn(stop));\n cell.lastChanged = timestamp;\n } catch (e) {\n stop();\n throw e;\n }\n }\n cell.ctx = makeCtx(job, cell);\n cell.flags = Is.Compute;\n cell.setQ(q);\n return stop;\n }\n}\n","import { defer } from \"./defer.ts\";\nimport { RuleQueue, currentRule, defaultQ, ruleQueue } from \"./scheduling.ts\";\nimport { AnyFunction, DisposeFn, OptionalCleanup } from \"./types.ts\";\nimport { Cell } from \"./cells.ts\";\nimport { CallableObject, apply, setMap } from \"./utils.ts\";\nimport { detached } from \"./tracking.ts\";\n\n/**\n * A decorator function that supports both TC39 and \"legacy\" decorator protocols\n *\n * @template F the type of method this decorator can decorate. If the method\n * doesn't conform to this type, compile-time type checks will fail.\n *\n * @category Types and Interfaces\n */\nexport type GenericMethodDecorator<F extends AnyFunction> = {\n /** TC39 Method Decorator @hidden */\n (fn: F, ctx?: {kind: \"method\"}): F;\n\n /** Legacy Method Decorator @hidden */\n (proto: object, name: string|symbol, desc?: {value?: F}): void;\n}\n\n/**\n * The interface provided by {@link rule}, and other {@link rule.factory}()\n * functions.\n*\n* @category Types and Interfaces\n*/\nexport interface RuleFactory {\n /**\n * @inheritdoc rule factory tied to a specific scheduler. See {@link rule} for\n * more details.\n */\n (fn: (stop: DisposeFn) => OptionalCleanup): DisposeFn;\n\n /**\n * A function that will stop the currently-executing rule. (Accessing this\n * attribute will throw an error if no rule is currently running.)\n *\n * Note: this returns the stop for the current rule regardless of its\n * scheduler, so you can access `rule.stop` even if the rule was created\n * with a different scheduler.\n */\n readonly stop: DisposeFn;\n\n /**\n * Observe a condition and apply an action.\n *\n * For a given {@link RuleFactory} `r` (such as `rule`), `r.if(condition,\n * action)` is roughly equivalent to `r(() => { if (condition()) return\n * action(); })`, except that the rule is *only* rerun if the `action`'s\n * dependencies change, *or* the **truthiness** of `condition()` changes. It\n * will *not* be re-run if only the dependencies of `condition()` have\n * changed, without affecting its truthiness.\n *\n * This behavior can be important for rules that nest other rules, have\n * cleanups, fire off tasks, etc., as it may be wasteful to constantly tear\n * them down and set them back up if the enabling condition is a calculation\n * with frequently-changing dependencies.\n *\n * @remarks This is just a shortcut for wrapping `condition` as a signal\n * that converts it to boolean. So if you already *have* a boolean signal,\n * you can get the same effect with just `if (condition()) { ... }`.\n */\n if(condition: () => any, action: () => OptionalCleanup): DisposeFn\n\n /**\n * Decorate a method or function to behave as a rule, e.g.\n *\n * ```ts\n * const animate = rule.factory(requestAnimationFrame);\n *\n * class Draggable {\n * @animate.method\n * trackPosition(handleTop: number, handleLeft: number) {\n * const {clientX, clientY} = lastMouseEvent();\n * this.element.style.top = `${clientY - handleTop}px`;\n * this.element.style.left = `${clientX - handleLeft}px`;\n * }\n * }\n *\n * // Start running the method in an animation frame for every change to\n * // lastMouseEvent, until the current job ends:\n * someDraggable.trackPosition(top, left);\n * ```\n * or:\n * ```ts\n * const logger = rule.method((formatString, signal) => { log(formatString, signal()); });\n * ```\n *\n * Each time it's (explicitly) called, the decorated method will start a new\n * rule, which will repeatedly run the method body (with the original\n * arguments and `this`) whenever its dependencies change, according to the\n * schedule defined by the rule factory. (So e.g. `@rule.method` will\n * update on the microtask after a change, etc.)\n *\n * The decorated method will always return a {@link DisposeFn} to let you\n * explicitly stop the rule before the current job end. But if the original\n * method body doesn't return a dispose function of its own, TypeScript will\n * consider the method to return void, unless you explicitly declare its\n * return type to be `DisposeFn | void`.\n *\n * Also note that since rule methods can accept arbitrary parameters, they\n * do not receive a `stop` parameter, and must therefore use {@link\n * RuleFactory.stop rule.stop}() if they wish to terminate themselves.\n */\n readonly method: GenericMethodDecorator<(...args: any[]) => OptionalCleanup>\n\n /**\n * Return a rule factory for the given scheduling function, that you can\n * then use to make rules that run in a specific time frame.\n *\n * ```ts\n * // `animate` will now create rules that run during animation fames\n * const animate = rule.factory(requestAnimationFrame);\n *\n * animate(() => {\n * // ... do stuff in an animation frame when signals used here change\n * })\n * ```\n *\n * (In addition to being callable, the returned function is also a\n * {@link RuleFactory}, and thus has a `.method` decorator, `.if()` method,\n * and so on.)\n *\n * @param scheduleFn A single-argument scheduling function (such as\n * requestAnimationFrame, setImmediate, or queueMicrotask). The rule\n * scheduler will call it from time to time with a single callback. The\n * scheduling function should then arrange for that callback to be invoked\n * *once* at some future point, when it is the desired time for all pending\n * rules on that scheduler to run.\n *\n * @returns A {@link RuleFactory}, like {@link rule}. If called with the\n * same scheduling function more than once, it returns the same factory.\n *\n */\n factory(scheduleFn: SchedulerFn): RuleFactory\n\n /**\n * Create a \"detached\" or standalone rule, that is not attached to any job.\n *\n * `r.detached(fn)` is shorthand for calling `detached.run(r, fn)`. (Where\n * `r` is a {@link RuleFactory} such as `rule`.)\n *\n * Note that since the created rule isn't attached to a job, it *must* be\n * explicitly stopped, either by calling the returned disposal function or\n * by the rule function arranging to stop itself via {@link rule.stop}() or\n * its stop parameter.\n */\n detached(fn: (stop: DisposeFn) => OptionalCleanup): DisposeFn;\n\n /**\n * Change the scheduler used for the currently-executing rule. Throws an\n * error if no rule is running.\n *\n * @param scheduleFn Optional: The {@link SchedulerFn scheduling function}\n * to use; the default microtask scheduler will be used if none is given or\n * the given value is falsy.\n *\n * @remarks It's best to only use scheduling functions that were created\n * *outside* the current rule, otherwise you'll be creating a new scheduling\n * queue object on every run of the rule. (These will get garbage collected\n * with the scheduling functions, but you'll be creating more memory\n * pressure and using more GC time if the rule runs frequently.)\n */\n setScheduler(scheduleFn?: SchedulerFn): void;\n}\n\ntype RuleFunction = (fn: ActionFunction) => DisposeFn\ntype ActionFunction = (stop: DisposeFn) => OptionalCleanup\n\nclass RF extends CallableObject<RuleFunction> implements RuleFactory {\n\n constructor(q: RuleQueue) {\n super((fn: ActionFunction) => Cell.mkRule(fn, q))\n }\n\n get stop() {\n if (currentRule) return currentRule.stop.bind(currentRule);\n throw new Error(\"No rule active\");\n }\n\n if(condition: () => any, action: () => OptionalCleanup): DisposeFn {\n const cond = Cell.mkCached(() => !!condition());\n return this(() => cond.getValue() ? action() : undefined);\n }\n\n get method(): GenericMethodDecorator<(...args: any[]) => OptionalCleanup> {\n const self = this;\n return (\n fn: object | ((...args: any[]) => OptionalCleanup),\n _ctxOrName?: any,\n desc?: { value?: (...args: any[]) => OptionalCleanup; }\n ) => {\n if (desc) return void (desc.value = this.method(desc.value));\n return function (this: any, ...args: any[]): DisposeFn {\n return self(() => apply(fn as any, this, args));\n };\n }\n }\n\n factory(scheduleFn: SchedulerFn): RuleFactory {\n return factories.get(scheduleFn) || setMap(factories, scheduleFn, new RF(ruleQueue(scheduleFn)));\n }\n\n detached(fn: ActionFunction) {\n return detached.run(this as RuleFunction, fn);\n }\n\n setScheduler(scheduleFn?: SchedulerFn): void {\n if (currentRule) currentRule.setQ(scheduleFn ? ruleQueue(scheduleFn) : defaultQ);\n else throw new Error(\"No rule active\");\n }\n}\n\n\nconst factories = new WeakMap<Function, RuleFactory>();\n\n/**\n * Subscribe a function to run every time certain values change.\n *\n * The function is run asynchronously, first after being created, then again\n * after there are changes in any of the values or cached functions it read\n * during its previous run.\n *\n * The created subscription is tied to the currently-active job (which may be\n * another rule). So when that job is ended or restarted, the rule will be\n * terminated automatically. You can also terminate it early by calling the\n * \"stop\" function that is both passed to the rule function and returned by\n * `rule()`.\n *\n * Note: this function will throw an error if called without an active job. If\n * you need a standalone rule, use {@link RuleFactory.detached rule.detached}().\n *\n * @param fn The function that will be run each time its dependencies change.\n * The function will be run in a restarted job each time, with any resources\n * used by the previous run being cleaned up. The function is passed a single\n * argument: a function that can be called to terminate the rule. The function\n * should return a cleanup function or void.\n *\n * @returns A function that can be called to terminate the rule.\n *\n * @category Signals\n */\nexport const rule: ((action: (stop: DisposeFn) => OptionalCleanup) => DisposeFn) & RuleFactory = (\n RF.prototype.factory(defer)\n)\n\n/**\n * Synchronously run any pending rules tied to a specific schedule.\n *\n * (Note: \"pending\" rules are ones with at least one changed ancestor\n * dependency; this doesn't mean they will actually *do* anything, since\n * intermediate cached() function results might end up unchanged.)\n *\n * You should normally only need to call this when you need to *force*\n * side-effects to occur within a specific *synchronous* timeframe, e.g. if\n * rules need to be able to cancel a synchronous event or continue an IndexedDB\n * transaction. (Otherwise, this is really only useful for testing.)\n *\n * @param scheduleFn The {@link SchedulerFn scheduler} used to create the rule\n * factory you wish to run pending rules for. If not given, the default\n * {@link rule}() factory is targeted.\n *\n * @category Signals\n */\nexport function runRules(scheduleFn?: SchedulerFn) {\n (scheduleFn ? ruleQueue(scheduleFn) : defaultQ).flush();\n}\n\n/**\n * A single-argument scheduling function (such as requestAnimationFrame,\n * setImmediate, or queueMicrotask). The rule scheduler will call it from time\n * to time with a single callback. The scheduling function should then arrange\n * for that callback to be invoked *once* at some future point, when it is the\n * desired time for all pending rules on that scheduler to run.\n *\n * @category Types and Interfaces\n */\nexport type SchedulerFn = (cb: () => unknown) => unknown;\n","/**\n * The Signals API for uneventful.\n *\n * @module uneventful/signals\n */\n\nimport { current, freeCtx, makeCtx, swapCtx } from \"./ambient.ts\";\nimport { PlainFunction, Yielding, AnyFunction, Job } from \"./types.ts\";\nimport { Cell } from \"./cells.ts\";\nimport { rule } from \"./rules.ts\";\nimport { reject, resolve } from \"./results.ts\";\nimport { UntilMethod } from \"./sinks.ts\";\nimport { SignalSource, Source, Stream } from \"./streams.ts\";\nimport { callOrWait } from \"./call-or-wait.ts\";\nimport { CallableObject, apply } from \"./utils.ts\";\nimport { defer } from \"./defer.ts\";\nimport { next } from \"./sinks.ts\"; // needed for documentation link\n\nexport type * from \"./rules.ts\"\nexport { rule, runRules } from \"./rules.ts\"\nexport { WriteConflict, CircularDependency } from \"./cells.ts\";\n\n/**\n * An observable value, as a zero-argument callable with extra methods.\n *\n * In addition to being callable, signals also offer a `.value` getter, and\n * implement the standard JS methods `.toString()`, `.valueOf()`, and\n * `.toJSON()` in such a way that they reflect the signal's contents rather than\n * the signal itself.\n *\n * Signals also implement the {@link Source} interface, and can thus be\n * subscribed to. Subscribers receive the current value first, and then any\n * changes thereafter. They can be waited on by {@link until}(), in which case\n * the calling job resumes when the signal's value is truthy.\n *\n * You can also transform a signal to a {@link Writable} by calling its\n * .{@link Signal.withSet withSet}() method, or create a writable value using\n * {@link value}().\n *\n * @category Types and Interfaces\n */\nexport interface Signal<T> extends SignalSource<T>, UntilMethod<T> {\n /**\n * The current value\n *\n * @category Reading\n */\n readonly value: T\n\n /** Current value @hidden */\n valueOf() : T\n\n /** Current value as a string @hidden */\n toString(): string\n\n /** The current value @hidden */\n toJSON() : T\n\n /**\n * Get the signal's current value, without adding the signal as a dependency\n *\n * (This is exactly equivalent to calling {@link peek}(signal), and exists\n * here mainly for interop with other signal frameworks.)\n *\n * @category Reading */\n peek(): T;\n\n /** Get a read-only version of this signal @category Reading */\n asReadonly(): Signal<T>\n\n /** New writable signal with a custom setter @category Writing */\n withSet(set: (v: T) => unknown): Writable<T>\n\n /** @hidden */\n \"uneventful.until\"(): Yielding<T>;\n}\n\n/** @internal */\nexport class SignalImpl<T> extends CallableObject<SignalSource<T>> implements Signal<T> {\n constructor(protected _c: Cell) { super(_c.getValue.bind(_c)); }\n get value() { return this(); }\n valueOf() { return this(); }\n toString() { return \"\" + this(); }\n toJSON() { return this(); }\n peek() { return peek(this as () => T); };\n asReadonly(): Signal<T> { return this; }\n withSet(set: (v: T) => unknown): Writable<T> {\n return Object.assign(new WritableImpl<T>(this._c), {set});\n }\n\n *\"uneventful.next\"(): Yielding<T> {\n return yield (r => {\n let seen = false, res: T;\n rule(stop => {\n try { res = this(); } catch(e) { stop(); defer(reject.bind(null, r,e)); }\n if (seen) { stop(); defer(resolve.bind(null, r, res)); }\n seen = true;\n })\n });\n }\n\n *\"uneventful.until\"(): Yielding<T> {\n return yield (r => {\n let res: T;\n try { res = this(); } catch(e) { reject(r, e); return; }\n if (res) return resolve(r, res);\n rule(stop => {\n try { res = this(); } catch(e) { stop(); defer(reject.bind(null, r,e)); }\n if (res) { stop(); defer(resolve.bind(null, r, res)); }\n });\n });\n }\n}\n\n/**\n * A {@link Signal} with a {@link Writable.set | .set()} method and writable\n * {@link Writable.value | .value} property.\n *\n * @category Types and Interfaces\n */\nexport interface Writable<T> extends Signal<T> {\n /**\n * Set the current value. (Note: this is a bound method so it can be used\n * as a callback.)\n *\n * @category Writing\n */\n readonly set: (val: T) => void;\n\n get value(): T\n\n /** Set the current value */\n set value(val: T);\n}\n\n/** @internal */\nexport class WritableImpl<T> extends SignalImpl<T> implements Writable<T> {\n get value() { return this(); }\n set value(val: T) { this.set(val); }\n set = (val: T) => { this._c.setValue(val, false); }\n asReadonly(): Signal<T> {\n return new SignalImpl<T>(this._c);\n }\n}\n\n/**\n * A writable signal that can be set to either a value or an expression.\n *\n * Like a spreadsheet cell, a configurable signal can contain either a value or\n * a formula. If you .set() a value or change the .value property of the\n * signal, the formula is cleared. Conversely, if you set a formula with\n * .setf(), then the value is calculated using that formula from then on, until\n * another formula is set, or the value is changed directly again.\n *\n * @category Types and Interfaces\n */\nexport interface Configurable<T> extends Writable<T> {\n /**\n * Set a formula that will be used to calculate the signal's value. If it\n * uses the value of other signals, this signal's value will be recalculated\n * when they change.\n *\n * @category Writing\n */\n setf(expr: () => T): this;\n}\n\n/** @internal */\nexport class ConfigurableImpl<T> extends WritableImpl<T> implements Configurable<T> {\n setf(expr: () => T): this {\n this._c.setCalc(expr);\n return this;\n }\n}\n\n/**\n * Create a {@link Configurable} signal with the given inital value\n *\n * @category Signals\n */\nexport function value<T>(val?: T): Configurable<T> {\n const cell = Cell.mkValue(val);\n return new ConfigurableImpl<T>(cell);\n}\n\n/**\n * Create a cached version of a function. The returned callable is also a\n * {@link Signal}.\n *\n * Note: If the supplied function has a non-zero `.length` (i.e., it explicitly\n * takes arguments), it is assumed to be a {@link Source}, and the second\n * calling signature below will apply, even if TypeScript doesn't see it that\n * way!)\n *\n * @category Signals\n */\nexport function cached<T>(compute: () => T): Signal<T>;\n\n/**\n * If the supplied function has a non-zero `.length` (i.e., it explicitly takes\n * arguments), it is assumed to be a {@link Source}, and the second argument is\n * a default value for the created signal to use as default value until the\n * source produces a value.\n *\n * The source will be subscribed *only* while the signal is subscribed as a\n * stream, or observed (directly or indirectly) by a rule. While subscribed,\n * the signal will update itself with the most recent value produced by the\n * source, triggering rules or events as appropriate if the value changes. When\n * the signal is once again unobserved (or if the source ends without an error),\n * its value will revert to the supplied default.\n *\n * If the source ends *with* an error, however, then the cached function will\n * throw that error whenever called, until/unless it becomes unobserved again.\n * (And thus reverts to the default value once more.)\n *\n * @param source A {@link Source} providing data which will become this signal's\n * value\n * @param defaultVal The value to use when the signal is unobserved or waiting for\n * the first item from the source.\n */\nexport function cached<T>(source: Source<T>, defaultVal?: T): Signal<T>;\nexport function cached<T extends Signal<any>>(signal: T): T\nexport function cached<T>(compute: Source<T> | (() => T), initVal?: T): Signal<T> {\n if (compute instanceof SignalImpl) return compute;\n return new SignalImpl<T>(\n compute.length ? Cell.mkStream(compute as Source<T>, initVal) : Cell.mkCached(compute as () => T)\n );\n}\n\n/**\n * Call a function without creating a dependency on any signals it reads. (Like\n * {@link Signal.peek}, but for any function with any arguments.)\n *\n * You can also pass in any arguments the function takes, and the function's\n * return value is returned.\n *\n * (Note: Typed overloads are not supported: TypeScript will use the function's\n * *last* overload for argument-typing purposes. If you need to call a function\n * with a specific overload, wrap the function with {@link action}() instead, and\n * then TypeScript will be able to detect which overload you're using.)\n *\n * @returns The result of calling `fn(..args)`\n *\n * @category Signals\n */\nexport function peek<F extends PlainFunction>(fn: F, ...args: Parameters<F>): ReturnType<F> {\n if (!current.cell) return fn(...args);\n const old = swapCtx(makeCtx(current.job));\n try { return fn(...args); } finally { freeCtx(swapCtx(old)); }\n}\n\n/**\n * Wrap a function (or decorate a method) so that signals it reads are not added\n * as dependencies to the current rule (if any). (Basically, it's shorthand for\n * wrapping the function or method body in a giant call to {@link peek}().)\n *\n * So, instead of writing an action function like this:\n *\n * ```ts\n * function outer(arg1, arg2) {\n * return peek(() => {\n * // reactive values used here will not be added to the running rule\n * })\n * }\n * ```\n * you can just write this:\n * ```ts\n * const outer = action((arg1, arg2) => {\n * // reactive values used here will not be added to the running rule\n * });\n * ```\n * or this:\n * ```ts\n * class Something {\n * @action // auto-detects TC39 or legacy decorators\n * someMethod(arg1) {\n * // reactive values used here will not be added to the running rule\n * }\n * }\n * ```\n *\n * @param fn The function to wrap. It can take any arguments or return value,\n * and overloads are supported. However, any non-standard properties the\n * function may have had will *not* be present on the wrapped function, even if\n * TypeScript will act as if they are!\n *\n * @returns A wrapped version of the function that passes through its arguments\n * to the original function, while running with dependency tracking suppressed\n * (as with {@link peek}()).\n *\n * @category Signals\n */\nexport function action<F extends AnyFunction>(fn: F): F;\n\n/** @hidden TC39 Decorator protocol */\nexport function action<F extends AnyFunction>(fn: F, ctx: {kind: \"method\"}): F;\n\n/** @hidden Legacy Decorator protocol */\nexport function action<F extends AnyFunction, D extends {value?: F}>(\n clsOrProto: any, name: string|symbol, desc: D\n): D\n\nexport function action<F extends AnyFunction, D extends {value?: F}>(fn: F, _ctx?: any, desc?: D): D | F {\n if (desc) return {...desc, value: action(desc.value)};\n return <F> function (this: ThisParameterType<F>) {\n if (!current.cell) return apply(fn, this, arguments);\n const old = swapCtx(makeCtx(current.job));\n try { return apply(fn, this, arguments); } finally { freeCtx(swapCtx(old)); }\n }\n}\n\n/**\n * Wait for and return the next truthy value (or error) from a data source (when\n * processed with `yield *` within a {@link Job}).\n *\n * This differs from {@link next}() in that it waits for the next \"truthy\" value\n * (i.e., not null, false, zero, empty string, etc.), and when used with signals\n * or a signal-using function, it can resume *immediately* if the result is\n * already truthy. (It also supports zero-argument signal-using functions,\n * automatically wrapping them with {@link cached}(), as the common use case for\n * until() is to wait for an arbitrary condition to be satisfied.)\n *\n * @param source The source to wait on, which can be:\n * - An object with an `\"uneventful.until\"` method returning a {@link Yielding}\n * (in which case the result will be the the result of calling that method)\n * - A {@link Signal}, or a zero-argument function returning a value based on\n * signals (in which case the job resumes as soon as the result is truthy,\n * perhaps immediately)\n * - A {@link Source} (in which case the job resumes on the next truthy value\n * it produces\n *\n * (Note: if the supplied source is a function with a non-zero `.length`, it is\n * assumed to be a {@link Source}.)\n *\n * @returns a Yieldable that when processed with `yield *` in a job, will return\n * the triggered event, or signal value. An error is thrown if event stream\n * throws or closes early, or the signal throws.\n *\n * @category Signals\n * @category Scheduling\n */\n\nexport function until<T>(source: UntilMethod<T> | Stream<T> | (() => T)): Yielding<T> {\n return callOrWait<T>(source, \"uneventful.until\", waitTruthy, recache);\n}\nfunction recache<T>(s: () => T) { return until(cached(s)); }\nfunction waitTruthy<T>(job: Job<T>, v: T) { v && job.return(v); }\n"],"names":[],"mappings":";;;AAQO,MAAM,aAAa,SAAS,KAAK,CAAC;AACzC,CAAC;AACM,MAAM,kBAAkB,SAAS,KAAK,CAAC;AAC9C,CAAC;AACD,IAAI,SAAS,GAAG,CAAC,CAAC;AAClB,MAAM,UAAU,mBAAmB,IAAI,OAAO,EAAE,CAAC;AACjD,MAAM,UAAU,mBAAmB,IAAI,OAAO,EAAE,CAAC;AACjD,MAAM,cAAc,mBAAmB,IAAI,OAAO,EAAE,CAAC;AACrD,MAAM,UAAU,GAAG,EAAE,CAAC;AACtB,SAAS,mBAAmB,CAAC,IAAI,EAAE;AACnC,EAAE,MAAM,YAAY,GAAG,IAAI,CAAC,YAAY,GAAG,SAAS,CAAC;AACrD,EAAE,OAAO,IAAI,EAAE,IAAI,GAAG,UAAU,CAAC,GAAG,EAAE,EAAE;AACxC,IAAI,KAAK,IAAI,GAA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MAAM,OAAO,KAAK,CAAC,EAAE,EAAE,IAAI,EAAE,SAAS,CAAC,CAAC;AACxC,IAAI,MAAM,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;AAC9C,IAAI,IAAI;AACR,MAAM,OAAO,KAAK,CAAC,EAAE,EAAE,IAAI,EAAE,SAAS,CAAC,CAAC;AACxC,KAAK,SAAS;AACd,MAAM,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;AAC5B,KAAK;AACL,GAAG,CAAC;AACJ,CAAC;AACM,SAAS,KAAK,CAAC,MAAM,EAAE;AAC9B,EAAE,OAAO,UAAU,CAAC,MAAM,EAAE,kBAAkB,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;AACrE,CAAC;AACD,SAAS,OAAO,CAAC,CAAC,EAAE;AACpB,EAAE,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;AAC1B,CAAC;AACD,SAAS,UAAU,CAAC,GAAG,EAAE,CAAC,EAAE;AAC5B,EAAE,CAAC,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;AACrB;;;;"}
|
|
1
|
+
{"version":3,"file":"signals.mjs","sources":["../src/cells.ts","../src/rules.ts","../src/signals.ts"],"sourcesContent":["import { Context, current, makeCtx, swapCtx } from \"./ambient.ts\";\nimport { DisposeFn, Job, OptionalCleanup, RecalcSource } from \"./types.ts\"\nimport { detached, getJob, makeJob } from \"./tracking.ts\";\nimport { Connection, Inlet, IsStream, Sink, Source, backpressure } from \"./streams.ts\";\nimport { apply, arrayEq, setMap } from \"./utils.ts\";\nimport { isError, markHandled } from \"./results.ts\";\nimport { nullCtx } from \"./internals.ts\";\nimport { defer } from \"./defer.ts\";\nimport { Batch, batch } from \"./scheduling.ts\";\nimport { action, peek, type Configurable } from \"./signals.ts\";\n\nconst ruleQueues = new WeakMap<Function, RuleQueue>();\nexport function ruleQueue(scheduleFn: (cb: () => unknown) => unknown = defer) {\n ruleQueues.has(scheduleFn) || ruleQueues.set(scheduleFn, batch<Cell>(runRules, scheduleFn));\n return ruleQueues.get(scheduleFn);\n}\n\nexport type RuleQueue = Batch<Cell>;\nexport var currentRule: Cell;\nexport const ruleStops = new WeakMap<Cell, DisposeFn>();\nexport const defaultQ = /* @__PURE__ */ ruleQueue(defer);\n\nvar currentQueue: RuleQueue;\nfunction runRules(this: RuleQueue, q: Set<Cell>) {\n // another queue is running? reschedule for later\n if (currentQueue) return;\n currentQueue = this;\n try {\n // run rules marked dirty by value changes\n for (currentRule of q) {\n currentRule.catchUp();\n q.delete(currentRule);\n }\n } finally {\n currentQueue = currentRule = undefined;\n }\n}\n\n/**\n * Error indicating a rule has attempted to write a value it indirectly\n * depends on, or which has already been read by another rule in the current\n * batch. (Also thrown when a cached function attempts to write a value at all,\n * directly or indirectly.)\n *\n * @category Errors\n */\nexport class WriteConflict extends Error {}\n\n/**\n * Error indicating a rule has attempted to write a value it directly depends\n * on, or a cached function has called itself, directly or indirectly.\n *\n * @category Errors\n */\nexport class CircularDependency extends Error {}\n\nvar timestamp = 1;\n\n/** recalcWhen(fn): map fn -> signal */\nconst fntrackers = new WeakMap<Function, () => number>();\n\n/** recalcWhen(key, factory): map factory -> key -> signal */\nconst obtrackers = new WeakMap<Function, WeakMap<WeakKey, () => number>>();\n\n/** stream controllers for stream+recalcWhen signals */\nconst monitors = new WeakMap<Cell, ()=>void>();\n\n/** Cells whose demand has changed and need to start/stop jobs, etc. */\nexport const demandChanges = batch<Cell>(q => { for(const cell of q) cell.updateDemand(); });\n\nconst dirtyStack: Cell[] = [];\n\nfunction markDependentsDirty(cell: Cell) {\n // We don't set validThrough here because that's how we tell the cell's been read/depended on\n const latestSource = cell.latestSource = timestamp;\n for(; cell; cell = dirtyStack.pop()) {\n for (let sub=cell.subscribers; sub; sub = sub.nT) {\n const tgt = sub.tgt;\n if (tgt.latestSource >= latestSource) continue;\n tgt.latestSource = latestSource;\n tgt.queue?.add(tgt);\n if (tgt.subscribers) dirtyStack.push(tgt);\n }\n }\n}\n\n// The .compute for a cell whose value has been explicitly set\nfunction returnValue(this: Cell) {\n return this.value;\n}\n\n// The compute for a cell whose value is an explicit error\nfunction throwValue(this: Cell) {\n throw this.value;\n}\n\n/**\n * Cells that are known to be clean as of this timestamp, but have not been\n * marked as read yet (and whose sources might also not be marked read). This\n * lets us lazily determine if a cell's value has been depended on (i.e.\n * \"virtually read\") in this timestamp, even if it wasn't *actually* read.\n */\nconst notCaughtUp = [] as Cell[];\n\nconst enum Is {\n Observed = 1 << 0, // Cell has subscribers or a rule queue\n Stopped = 1 << 1, // Stateful cell requested stop\n Compute = 1 << 2,\n Error = 1 << 4,\n Running = 1 << 5,\n Stateful = 1 << 6, // Cell has state (e.g. job, stream) that depends on its observed-ness\n Mutable = 1 << 7,\n Variable = Compute | Mutable,\n}\n\ntype Subscription = {\n /** Source of the subscription */\n src: Cell\n nS: Subscription,\n pS: Subscription,\n\n /** Subscriber */\n tgt: Cell\n nT: Subscription,\n pT: Subscription,\n\n ts: number,\n\n /* stack for active subscriptions on sources */\n old: Subscription\n}\n\nvar freesubs: Subscription;\n\nfunction mksub(source: Cell, target: Cell) {\n let sub: Subscription = freesubs;\n if (sub) {\n freesubs = sub.old;\n sub.src = source; sub.nS = undefined; sub.pS = target.sources;\n sub.tgt = target; sub.nT = sub.pT = undefined;\n sub.ts = source.lastChanged; sub.old = source.adding;\n } else sub = {\n src: source, nS: undefined, pS: target.sources,\n tgt: target, nT: undefined, pT: undefined,\n ts: source.lastChanged, old: source.adding\n }\n // Add subscription to tail of target's sources\n if (target.sources) target.sources.nS = sub;\n target.sources = sub;\n // track that this source has had a subscription added during this calculation\n source.adding = sub;\n // Set up reciprocal subscription if needed\n if (target.flags & Is.Observed) source.subscribe(sub);\n}\n\n/** Delete subscription, with recursive constant folding */\nfunction removeConstListener(sub: Subscription) {\n const{tgt, nS, pS} = sub;\n if (sub.src.adding === sub) sub.src.adding = sub.old;\n delsub(sub);\n // Recurse if its source list becomes empty\n if (tgt.sources === sub) (tgt.sources = nS || pS) || tgt.becomeConstant();\n}\n\n/** Delete subscription as part of recalc cleanup only */\nfunction delsub(sub: Subscription) {\n sub.src.unsubscribe(sub);\n if (sub.nS) sub.nS.pS = sub.pS;\n if (sub.pS) sub.pS.nS = sub.nS;\n sub.src = sub.tgt = sub.nS = sub.pS = sub.nT = sub.pT = undefined;\n sub.old = freesubs;\n freesubs = sub;\n}\n\nfunction subscribeAll(c: Cell) {\n for(let s = firstSource(c); s; s = s.nS) s.src.subscribe(s);\n toggleDemand(c);\n}\n\nfunction unsubscribeAll(c: Cell) {\n for(let s = firstSource(c); s; s = s.nS) s.src.unsubscribe(s);\n toggleDemand(c);\n}\n\nconst sentinel = {} // a unique value for uniqueness checking\n\nfunction firstSource(c: Cell) {\n let s = c.sources;\n if (s) while (s.pS) s = s.pS; // Back up to the start (in case the cell is running)\n return s;\n}\n\nfunction toggleDemand(c: Cell) {\n // We toggle the observed flag to match our current state; if we're also\n // stateful, we need to toggle our \"dirty\" status in the demand queue, too.\n if (((c.flags ^= Is.Observed) & Is.Stateful) === Is.Stateful) {\n // If we were already in the queue, then we were dirty in the old state,\n // which means we're *clean* in the new state, and vice versa. This\n // lets us avoid redundant work in the queue when demand briefly\n // flip-flops (due to e.g. nested rules being restarted).\n demandChanges.has(c) ? demandChanges.delete(c) : demandChanges.add(c);\n }\n}\n\nexport class Cell {\n value: any = undefined // the value\n validThrough = 0; // timestamp of most recent validation or recalculation\n lastChanged = 0; // timestamp of last value change\n latestSource = timestamp; // max lastChanged of this cell or any ancestor source\n flags = 0;\n ctx: Context = undefined;\n /** The subscription being added during the current calculation - used for uniqueness */\n adding: Subscription = undefined;\n /** Linked list of sources */\n sources: Subscription = undefined;\n /** Linked list of targets */\n subscribers: Subscription = undefined;\n queue: RuleQueue = undefined;\n\n /**\n * The computation to be performed (if {@link Is.Compute}) or the\n * setup/teardown for {@link Is.Stateful}.\n */\n compute: (sub?: boolean) => any = returnValue;\n\n stream<T>(sink: Sink<T>, _conn?: Connection, inlet?: Inlet) {\n let lastValue = sentinel;\n Cell.mkRule(() => {\n const val = this.getValue();\n if (val !== lastValue) {\n const old = swapCtx(nullCtx);\n try { sink(lastValue = val); } finally { swapCtx(old); }\n }\n }, inlet ? ruleQueue(backpressure(inlet)) : defaultQ);\n return IsStream;\n }\n\n getValue() {\n if (arguments.length) return apply(this.stream, this, arguments);\n const dep = current.cell;\n // Only create a dependency if our value can change\n if (dep && this.flags & Is.Variable) {\n if (this.flags & Is.Running) throw new CircularDependency(\"Cached function dependency cycle\");\n // See if we've already got a subscription node for the dependent\n let s = this.adding;\n if (!s || s.tgt !== dep) {\n // nope, it's new\n mksub(this, dep);\n s = this.adding;\n } else {\n // Yep, see if it's a hangover from last time\n if (s.ts === -1) {\n // yep, mark it reused\n s.ts = this.lastChanged;\n if (s.nS) { // if not at end, move it\n s.nS.pS = s.pS;\n if (s.pS) s.pS.nS = s.nS;\n s.nS = undefined;\n s.pS = dep.sources;\n dep.sources.nS = s;\n dep.sources = s;\n }\n }\n // else it's already done, no need to do anything.\n }\n this.catchUp();\n if (this.adding === s) s.ts = this.lastChanged;\n } else this.catchUp();\n if (this.flags & Is.Error) throw this.value;\n return this.value;\n }\n\n shouldWrite(changed: boolean) {\n const cell = current.cell || currentRule;\n if (cell) {\n // When a cell changes within a sweep (i.e. from an active rule or other\n // cell), we need to check if it's not a circular update or disallowed\n // side-effect. In such a case we bail out with an error, even if the\n // change is idempotent. (To avoid hiding value-dependent errors.)\n if (!cell.queue) throw new WriteConflict(\"Side-effects not allowed outside rules\");\n if (this.adding && this.adding.tgt === cell) throw new CircularDependency(\"Can't update direct dependency\");\n if (this.validThrough === timestamp || this.hasBeenRead()) throw new WriteConflict(\"Value already used\");\n } else if (changed) {\n // We are *not* in a sweep, but *did* have a change. So we may need to advance\n // the timestamp, if we might have had readers in the current one.\n if (this.validThrough === timestamp || notCaughtUp.length) { ++timestamp; notCaughtUp.length = 0; }\n } else {\n // Not in a sweep and no change -- no need to actually write anything\n return false;\n }\n // If we changed as of the current timestamp, we're already dirty\n // Otherwise, we should flag our subscribers as such.\n (this.lastChanged === timestamp) || markDependentsDirty(this);\n // If we have sources, reset the subscription timestamp of the first one\n // to force a recalculation on our next catchUp(). (It should be safe\n // because if we were running, we'd have thrown \"value already used\" above.)\n if (this.sources) this.sources.ts = 0;\n return true;\n }\n\n setValue(val: any, isErr: boolean) {\n if (this.shouldWrite(val !== this.value || isErr !== !!(this.flags & Is.Error))) {\n this.value = val;\n this.lastChanged = timestamp;\n this.flags = isErr ? this.flags | Is.Error : this.flags & ~Is.Error;\n }\n // We always reset the compute here because we might have been in the\n // Calc state. But we don't clear the Calc flag because we might need\n // any previous sources to be released or unsubscribed. (Which will\n // happen on our next recalc.)\n this.compute = isErr ? throwValue : returnValue;\n }\n\n setCalc(compute: () => any) {\n if (this.shouldWrite(compute !== this.compute)) {\n this.flags |= Is.Compute;\n this.compute = compute;\n this.ctx ||= makeCtx(null, this);\n }\n }\n\n hasBeenRead() {\n if (notCaughtUp.length) {\n for(const cell of notCaughtUp) cell.catchUp();\n notCaughtUp.length = 0;\n }\n return this.validThrough === timestamp;\n }\n\n catchUp(): void {\n const {validThrough} = this;\n if (validThrough === timestamp) return;\n this.validThrough = timestamp;\n if (!(this.flags & Is.Compute)) return;\n if (this.sources) {\n for(let sub=this.sources; sub; sub = sub.nS) {\n const s = sub.src;\n // changed since our last compute? we're definitely dirty\n if (sub.ts !== s.lastChanged) return this.doRecalc();\n // if source is clean, skip it (most should be)\n // (note: only cells w/subscribers can be trusted as to their\n // latestSource, as cacheds with no subscribers don't get\n // notified by their upstreams)\n if (s.subscribers && s.latestSource <= validThrough) continue;\n // not a simple yes or no -- \"it's complicated\" -- so recurse\n s.catchUp();\n if (s.lastChanged > validThrough) {\n return this.doRecalc();\n }\n }\n // If we got to this point, we didn't need to recalc, but that means\n // none of our sources actually *changed*, despite at least one being\n // dirty. But that means we \"virtually\" read the clean values and\n // therefore depended on them... which means if they get written to,\n // either the timestamp must change or the write must be blocked.\n //\n // So we put them on our notCaughtUp list, in order to prevent rules\n // from changing them (or their sources) in the same timestamp, and\n // so that non-rule writes will know to update the timestamp.\n for(let sub=this.sources; sub; sub = sub.nS) {\n if (sub.src.validThrough !== timestamp) notCaughtUp.push(sub.src);\n }\n } else return this.doRecalc();\n }\n\n doRecalc() {\n const {ctx} = this, oldCtx = swapCtx(ctx);\n if (this.flags & Is.Stateful) {\n ctx.job?.restart();\n }\n for(let sub = this.sources; sub; sub = sub.nS) {\n sub.ts = -1; // mark stale for possible reuse\n // attach sub to its source, so we can look it up\n sub.old = sub.src.adding;\n sub.src.adding = sub;\n this.sources = sub;\n }\n this.flags |= Is.Running;\n try {\n try {\n const future = this.compute();\n if (future !== this.value || !this.lastChanged || this.flags & Is.Error) {\n this.value = future;\n this.lastChanged = timestamp;\n }\n this.flags &= ~Is.Error;\n } catch(e) {\n this.flags |= Is.Error\n this.value = e;\n this.lastChanged = timestamp;\n if (currentRule === this) throw e;\n }\n } finally {\n this.flags &= ~Is.Running;\n if (this.flags & Is.Stateful) {\n demandChanges.delete(this);\n if (this.flags & (Is.Error|Is.Stopped)) {\n this.flags &= ~Is.Stopped;\n ctx.job?.restart();\n } else if (this.flags & Is.Observed) {\n } else {\n ctx.job?.restart();\n }\n }\n swapCtx(oldCtx);\n // reset this.src to the head of the list, dropping stale subscriptions\n let head: Subscription;\n for(let sub = this.sources; sub; ) {\n const pS = sub.pS;\n sub.src.adding = sub.old;\n sub.old = undefined;\n if (sub.ts === -1) delsub(sub); else head = sub;\n sub = pS;\n }\n // without sources, we can never change or be invalidated, so flag as uncomputable\n (this.sources = head) || this.becomeConstant()\n }\n }\n\n becomeConstant() {\n // Not safe if running, and running cells will do this on exit anyway.\n // And if we're stateful, we can change by being observed/unobserved, so\n // aren't really constant.\n if (this.flags & (Is.Running | Is.Stateful)) return;\n\n this.flags &= ~Is.Compute;\n\n // If we're mutable, don't delete subscriptions\n if (this.flags & Is.Variable) return;\n\n // It's safe to delete subscriptions in the adding stack, because those\n // cells are already reading the current value (or not) during their\n // active recalc.\n while (this.adding) removeConstListener(this.adding);\n\n // For any other subscriptions, we only delete ones that match our timestamp,\n // as they've already read our latest value. The rest will have to wait\n // until they recalc, at which point they won't renew their subscription and\n // it'll get cleared out then. (And propagate if applicable.)\n for(let sub = this.subscribers; sub; ) {\n const {nT} = sub; (sub.ts !== this.lastChanged) || removeConstListener(sub); sub = nT;\n }\n }\n\n stop() {\n this.setQ(null);\n // force immediate stop unless we're running (in which case doRecalc\n // will handle it for us, since we have no demand any more):\n if (this.flags & Is.Running) { this.flags |= Is.Stopped; } else this.updateDemand();\n ruleStops.get(this)?.();\n }\n\n setQ(queue: RuleQueue|null = defaultQ) {\n if (queue == this.queue) return; // use `==` to ignore null/undefined\n if (!this.subscribers) {\n // Without subscribers, adding/removing a queue will change demand,\n // so we'll need to unsubscribe from sources if (and ONLY if) we're\n // removing a *currently active* queue:\n queue || !this.queue || unsubscribeAll(this);\n }\n if (this.queue) {\n // Only add to new queue if queued on old\n if (this.queue.has(this)) queue?.add(this);\n this.queue.delete(this);\n } else if (queue) {\n // initial queue or re-enable, schedule it\n queue.add(this);\n // If we already have subscribers, we're already subscribed\n this.subscribers || subscribeAll(this);\n }\n this.queue = queue;\n }\n\n subscribe(sub: Subscription) {\n if (!this.subscribers && !this.queue) {\n // 0->1 subs, engage demand (unless we already have it via queue)\n subscribeAll(this);\n }\n if (this.subscribers !== sub && !sub.pT) { // avoid adding already-added subs\n sub.nT = this.subscribers;\n if (this.subscribers) this.subscribers.pT = sub;\n this.subscribers = sub;\n }\n }\n\n unsubscribe(sub: Subscription) {\n if (sub.nT) sub.nT.pT = sub.pT;\n if (sub.pT) sub.pT.nT = sub.nT;\n if (this.subscribers === sub) this.subscribers = sub.nT;\n sub.nT = sub.pT = undefined;\n if (!this.subscribers && !this.queue) {\n // 1->0 subs, remove demand (unless we still have it via queue)\n unsubscribeAll(this);\n }\n }\n\n static mkValue<T>(val: T) {\n const cell = new Cell;\n cell.flags = Is.Mutable;\n cell.value = val;\n cell.lastChanged = timestamp;\n return cell;\n }\n\n isObserved() {\n // intentional side effect: start state tracking\n return !!((this.flags|= Is.Stateful) & Is.Observed);\n }\n\n getJob() {\n this.flags |= Is.Stateful;\n return this.ctx.job ||= makeJob();\n }\n\n updateDemand() {\n demandChanges.delete(this);\n if (monitors.has(this)) {\n monitors.get(this)();\n } else if (this.flags & Is.Observed) {\n // Trigger an async update so we run on the right scheduler\n this.shouldWrite(true);\n } else {\n // no demand: restart job if active\n this.ctx.job?.restart();\n }\n }\n\n static mkStream<T>(src: Source<T>, val?: T) {\n const cell = this.mkValue(val);\n cell.flags |= Is.Stateful;\n const ctx = makeCtx();\n const write = (v: T) => { cell.setValue(v, false); };\n let job: Job<void>;\n monitors.set(cell, () => {\n if (!cell.subscribers) {\n // Last subscriber is gone, so reset to default value\n write(val);\n job?.end(); // unsubscribe from source\n return\n }\n if (job) return;\n job = ctx.job = makeJob<void>().do(r => {\n if (isError(r)) {\n cell.setValue(markHandled(r), true);\n } else {\n cell.setValue(val, false);\n }\n ctx.job = job = undefined;\n });\n const old = swapCtx(ctx);\n try {\n src(write, job);\n } catch(e) {\n job.end();\n detached.asyncThrow(e);\n } finally {\n swapCtx(old);\n }\n });\n return cell;\n }\n\n recalcWhen(src: RecalcSource): void;\n recalcWhen<T extends WeakKey>(key: T, factory: (key: T) => RecalcSource): void;\n recalcWhen<T extends WeakKey>(fnOrKey: T | RecalcSource, fn?: (key: T) => RecalcSource) {\n let trackers: WeakMap<WeakKey, () => number> = fn ?\n obtrackers.get(fn) || setMap(obtrackers, fn, new WeakMap) :\n fntrackers\n ;\n let signal = trackers.get(fnOrKey);\n if (!signal) {\n const src = fn ? fn(<T>fnOrKey) : <RecalcSource> fnOrKey;\n let ct = 0;\n const c = Cell.mkStream(s => (src(() => s(++ct)), IsStream), ct);\n trackers.set(fnOrKey, signal = c.getValue.bind(c));\n }\n signal(); // Subscribe to the cell\n }\n\n static mkCached<T>(compute: () => T) {\n const cell = new Cell;\n cell.compute = compute;\n cell.ctx = makeCtx(null, cell);\n cell.flags = Is.Compute;\n return cell;\n }\n\n static mkRule(fn: () => OptionalCleanup, q: RuleQueue) {\n const outer = getJob(), cell = Cell.mkCached(() => {\n try {\n const cleanup = fn();\n if (cleanup) (cell.ctx.job || cell.getJob()).must(cleanup);\n cell.lastChanged = timestamp;\n } catch (e) {\n cell.stop();\n throw e;\n }\n }), stop = cell.stop.bind(cell);\n outer === detached || ruleStops.set(cell, outer.release(stop));\n cell.setQ(q);\n return stop;\n }\n}\n\n/**\n * Keep an expression's old value unless there's a semantic change\n *\n * By default, reactive values (i.e. {@link cached}(), or {@link value}() with a\n * {@link Configurable.setf setf}()) are considered to have \"changed\" (and thus\n * trigger recalculation of their dependents) when they are different according\n * to `===` comparison.\n *\n * This works well for primitive values, but for arrays and objects it's not\n * always ideal, because two arrays can have the exact same elements and still\n * be different according to `===`. So this function lets you substitute a\n * different comparison function (like a deep-equal or shallow-equal) instead.\n * (The default is {@link arrayEq}() if no compare function is supplied.)\n *\n * Specifically, if your reactive expression returns `unchangedIf(newVal,\n * compare)`, then the expression's previous value will be kept if the compare\n * function returns true when called with the old and new values. Otherwise, the\n * new value will be used.\n *\n * @remarks\n * - If the reactive expression's last \"value\" was an error, the new value is\n * returned\n * - An error will be thrown if this function is called outside a reactive\n * expression or from within a {@link peek}() call or {@link action} wrapper.\n *\n * @category Reactive Values\n */\n\nexport function unchangedIf<T>(newVal: T, equals: (v1: T, v2: T) => boolean = arrayEq): T {\n const {cell} = current;\n if (cell) {\n return (cell.flags & Is.Error || !equals(cell.value, newVal)) ? newVal : cell.value;\n } else {\n throw new Error(\"unchangedIf() must be called from a reactive expression\");\n }\n}\n","import { defer } from \"./defer.ts\";\nimport { Cell, RuleQueue, currentRule, defaultQ, ruleQueue } from \"./cells.ts\";\nimport { AnyFunction, DisposeFn, OptionalCleanup } from \"./types.ts\";\nimport { CallableObject, apply, setMap } from \"./utils.ts\";\nimport { detached } from \"./tracking.ts\";\n\n/**\n * A decorator function that supports both TC39 and \"legacy\" decorator protocols\n *\n * @template F the type of method this decorator can decorate. If the method\n * doesn't conform to this type, compile-time type checks will fail.\n *\n * @category Types and Interfaces\n */\nexport type GenericMethodDecorator<F extends AnyFunction> = {\n /** TC39 Method Decorator @hidden */\n (fn: F, ctx?: {kind: \"method\"}): F;\n\n /** Legacy Method Decorator @hidden */\n (proto: object, name: string|symbol, desc?: {value?: F}): void;\n}\n\n/**\n * The interface provided by {@link rule}, and other {@link rule.factory}()\n * functions.\n*\n* @category Types and Interfaces\n*/\nexport interface RuleFactory {\n /**\n * @inheritdoc rule factory tied to a specific scheduler. See {@link rule} for\n * more details.\n */\n (fn: () => OptionalCleanup): DisposeFn;\n\n /**\n * A function that will stop the currently-executing rule. (Accessing this\n * attribute will throw an error if no rule is currently running.)\n *\n * Note: this returns the stop for the current rule regardless of its\n * scheduler, so you can access `rule.stop` even if the rule was created\n * with a different scheduler.\n */\n readonly stop: DisposeFn;\n\n /**\n * Observe a condition and apply an action.\n *\n * For a given {@link RuleFactory} `r` (such as `rule`), `r.if(condition,\n * action)` is roughly equivalent to `r(() => { if (condition()) return\n * action(); })`, except that the rule is *only* rerun if the `action`'s\n * dependencies change, *or* the **truthiness** of `condition()` changes. It\n * will *not* be re-run if only the dependencies of `condition()` have\n * changed, without affecting its truthiness.\n *\n * This behavior can be important for rules that nest other rules, have\n * cleanups, fire off tasks, etc., as it may be wasteful to constantly tear\n * them down and set them back up if the enabling condition is a calculation\n * with frequently-changing dependencies.\n *\n * @remarks This is just a shortcut for wrapping `condition` as a signal\n * that converts it to boolean. So if you already *have* a boolean signal,\n * you can get the same effect with just `if (condition()) { ... }`.\n */\n if(condition: () => any, action: () => OptionalCleanup): DisposeFn\n\n /**\n * Decorate a method or function to behave as a rule, e.g.\n *\n * ```ts\n * const animate = rule.factory(requestAnimationFrame);\n *\n * class Draggable {\n * @animate.method\n * trackPosition(handleTop: number, handleLeft: number) {\n * const {clientX, clientY} = lastMouseEvent();\n * this.element.style.top = `${clientY - handleTop}px`;\n * this.element.style.left = `${clientX - handleLeft}px`;\n * }\n * }\n *\n * // Start running the method in an animation frame for every change to\n * // lastMouseEvent, until the current job ends:\n * someDraggable.trackPosition(top, left);\n * ```\n * or:\n * ```ts\n * const logger = rule.method((formatString, signal) => { log(formatString, signal()); });\n * ```\n *\n * Each time it's (explicitly) called, the decorated method will start a new\n * rule, which will repeatedly run the method body (with the original\n * arguments and `this`) whenever its dependencies change, according to the\n * schedule defined by the rule factory. (So e.g. `@rule.method` will\n * update on the microtask after a change, etc.)\n *\n * The decorated method will always return a {@link DisposeFn} to let you\n * explicitly stop the rule before the current job end. But if the original\n * method body doesn't return a dispose function of its own, TypeScript will\n * consider the method to return void, unless you explicitly declare its\n * return type to be `DisposeFn | void`.\n *\n * Also note that since rule methods can accept arbitrary parameters, they\n * do not receive a `stop` parameter, and must therefore use {@link\n * RuleFactory.stop rule.stop}() if they wish to terminate themselves.\n */\n readonly method: GenericMethodDecorator<(...args: any[]) => OptionalCleanup>\n\n /**\n * Return a rule factory for the given scheduling function, that you can\n * then use to make rules that run in a specific time frame.\n *\n * ```ts\n * // `animate` will now create rules that run during animation fames\n * const animate = rule.factory(requestAnimationFrame);\n *\n * animate(() => {\n * // ... do stuff in an animation frame when signals used here change\n * })\n * ```\n *\n * (In addition to being callable, the returned function is also a\n * {@link RuleFactory}, and thus has a `.method` decorator, `.if()` method,\n * and so on.)\n *\n * @param scheduleFn A single-argument scheduling function (such as\n * requestAnimationFrame, setImmediate, or queueMicrotask). The rule\n * scheduler will call it from time to time with a single callback. The\n * scheduling function should then arrange for that callback to be invoked\n * *once* at some future point, when it is the desired time for all pending\n * rules on that scheduler to run.\n *\n * @returns A {@link RuleFactory}, like {@link rule}. If called with the\n * same scheduling function more than once, it returns the same factory.\n *\n */\n factory(scheduleFn: SchedulerFn): RuleFactory\n\n /**\n * Create a \"detached\" or standalone rule, that is not attached to any job.\n *\n * `r.detached(fn)` is shorthand for calling `detached.run(r, fn)`. (Where\n * `r` is a {@link RuleFactory} such as `rule`.)\n *\n * Note that since the created rule isn't attached to a job, it *must* be\n * explicitly stopped, either by calling the returned disposal function or\n * by the rule function arranging to stop itself via {@link rule.stop}().\n */\n detached(fn: () => OptionalCleanup): DisposeFn;\n\n /**\n * Change the scheduler used for the currently-executing rule. Throws an\n * error if no rule is running.\n *\n * @param scheduleFn Optional: The {@link SchedulerFn scheduling function}\n * to use; the default microtask scheduler will be used if none is given or\n * the given value is falsy.\n *\n * @remarks It's best to only use scheduling functions that were created\n * *outside* the current rule, otherwise you'll be creating a new scheduling\n * queue object on every run of the rule. (These will get garbage collected\n * with the scheduling functions, but you'll be creating more memory\n * pressure and using more GC time if the rule runs frequently.)\n */\n setScheduler(scheduleFn?: SchedulerFn): void;\n}\n\ntype RuleFunction = (fn: ActionFunction) => DisposeFn\ntype ActionFunction = () => OptionalCleanup\n\nclass RF extends CallableObject<RuleFunction> implements RuleFactory {\n\n constructor(q: RuleQueue) {\n super((fn: ActionFunction) => Cell.mkRule(fn, q))\n }\n\n get stop() {\n if (currentRule) return currentRule.stop.bind(currentRule);\n throw new Error(\"No rule active\");\n }\n\n if(condition: () => any, action: () => OptionalCleanup): DisposeFn {\n const cond = Cell.mkCached(() => !!condition());\n return this(() => cond.getValue() ? action() : undefined);\n }\n\n get method(): GenericMethodDecorator<(...args: any[]) => OptionalCleanup> {\n const self = this;\n return (\n fn: object | ((...args: any[]) => OptionalCleanup),\n _ctxOrName?: any,\n desc?: { value?: (...args: any[]) => OptionalCleanup; }\n ) => {\n if (desc) return void (desc.value = this.method(desc.value));\n return function (this: any, ...args: any[]): DisposeFn {\n return self(() => apply(fn as any, this, args));\n };\n }\n }\n\n factory(scheduleFn: SchedulerFn): RuleFactory {\n return factories.get(scheduleFn) || setMap(factories, scheduleFn, new RF(ruleQueue(scheduleFn)));\n }\n\n detached(fn: ActionFunction) {\n return detached.run(this as RuleFunction, fn);\n }\n\n setScheduler(scheduleFn?: SchedulerFn): void {\n if (currentRule) currentRule.setQ(scheduleFn ? ruleQueue(scheduleFn) : defaultQ);\n else throw new Error(\"No rule active\");\n }\n}\n\n\nconst factories = new WeakMap<Function, RuleFactory>();\n\n/**\n * Subscribe a function to run every time certain values change.\n *\n * The function is run asynchronously, first after being created, then again\n * after there are changes in any of the {@link value}()s or {@link cached}()\n * functions it read during its previous run.\n *\n * The created subscription is tied to the currently-active job (which may be\n * another rule). So when that job is ended or restarted, the rule will be\n * terminated automatically. You can also terminate it early by calling the\n * \"stop\" function that is returned by `rule()`, or by calling\n * {@link rule.stop}() from within the rule function.\n *\n * Note: this function will throw an error if called without an active job. If\n * you need a standalone rule, use {@link RuleFactory.detached rule.detached}().\n *\n * @param fn The function that will be run each time its dependencies change.\n * The function will be run in a restarted job each time, with any resources\n * used by the previous run being cleaned up. The function is called with no\n * arguments, and should return a cleanup function or void.\n *\n * @returns A function that can be called to terminate the rule.\n *\n * @category Reactive Behaviors\n */\nexport const rule: ((fn: () => OptionalCleanup) => DisposeFn) & RuleFactory = (\n RF.prototype.factory(defer)\n)\n\n/**\n * Synchronously run any pending rules tied to a specific schedule.\n *\n * (Note: \"pending\" rules are ones with at least one changed ancestor\n * dependency; this doesn't mean they will actually *do* anything, since\n * intermediate cached() function results might end up unchanged.)\n *\n * You should normally only need to call this when you need to *force*\n * side-effects to occur within a specific *synchronous* timeframe, e.g. if\n * rules need to be able to cancel a synchronous event or continue an IndexedDB\n * transaction. (Otherwise, this is really only useful for testing.)\n *\n * @param scheduleFn The {@link SchedulerFn scheduler} used to create the rule\n * factory you wish to run pending rules for. If not given, the default\n * {@link rule}() factory is targeted.\n *\n * @category Reactive Behaviors\n */\nexport function runRules(scheduleFn?: SchedulerFn) {\n (scheduleFn ? ruleQueue(scheduleFn) : defaultQ).flush();\n}\n\n/**\n * A single-argument scheduling function (such as requestAnimationFrame,\n * setImmediate, or queueMicrotask). The rule scheduler will call it from time\n * to time with a single callback. The scheduling function should then arrange\n * for that callback to be invoked *once* at some future point, when it is the\n * desired time for all pending rules on that scheduler to run.\n *\n * @category Types and Interfaces\n */\nexport type SchedulerFn = (cb: () => unknown) => unknown;\n","/**\n * The Signals API for uneventful.\n *\n * @module uneventful/signals\n */\n\nimport { current, freeCtx, makeCtx, swapCtx } from \"./ambient.ts\";\nimport { PlainFunction, Yielding, AnyFunction, Job } from \"./types.ts\";\nimport { Cell } from \"./cells.ts\";\nimport { rule } from \"./rules.ts\";\nimport { reject, resolve } from \"./results.ts\";\nimport { UntilMethod } from \"./sinks.ts\";\nimport { SignalSource, Source, Stream } from \"./streams.ts\";\nimport { callOrWait } from \"./call-or-wait.ts\";\nimport { CallableObject, apply } from \"./utils.ts\";\nimport { defer } from \"./defer.ts\";\nimport { next } from \"./sinks.ts\"; // needed for documentation link\n\nexport type * from \"./rules.ts\"\nexport { rule, runRules } from \"./rules.ts\"\nexport { WriteConflict, CircularDependency, unchangedIf } from \"./cells.ts\";\n\n/**\n * An observable value, as a zero-argument callable with extra methods.\n *\n * In addition to being callable, signals also offer a `.value` getter, and\n * implement the standard JS methods `.toString()`, `.valueOf()`, and\n * `.toJSON()` in such a way that they reflect the signal's contents rather than\n * the signal itself.\n *\n * Signals also implement the {@link Source} interface, and can thus be\n * subscribed to. Subscribers receive the current value first, and then any\n * changes thereafter. They can be waited on by {@link until}(), in which case\n * the calling job resumes when the signal's value is truthy.\n *\n * You can also transform a signal to a {@link Writable} by calling its\n * .{@link Signal.withSet withSet}() method, or create a writable value using\n * {@link value}().\n *\n * @category Types and Interfaces\n */\nexport interface Signal<T> extends SignalSource<T>, UntilMethod<T> {\n /**\n * The current value\n *\n * @category Reading\n */\n readonly value: T\n\n /** Current value @hidden */\n valueOf() : T\n\n /** Current value as a string @hidden */\n toString(): string\n\n /** The current value @hidden */\n toJSON() : T\n\n /**\n * Get the signal's current value, without adding the signal as a dependency\n *\n * (This is exactly equivalent to calling {@link peek}(signal), and exists\n * here mainly for interop with other signal frameworks.)\n *\n * @category Reading */\n peek(): T;\n\n /** Get a read-only version of this signal @category Reading */\n asReadonly(): Signal<T>\n\n /** New writable signal with a custom setter @category Writing */\n withSet(set: (v: T) => unknown): Writable<T>\n\n /** @hidden */\n \"uneventful.until\"(): Yielding<T>;\n}\n\n/** @internal */\nexport class SignalImpl<T> extends CallableObject<SignalSource<T>> implements Signal<T> {\n constructor(protected _c: Cell) { super(_c.getValue.bind(_c)); }\n get value() { return this(); }\n valueOf() { return this(); }\n toString() { return \"\" + this(); }\n toJSON() { return this(); }\n peek() { return peek(this as () => T); };\n asReadonly(): Signal<T> { return this; }\n withSet(set: (v: T) => unknown): Writable<T> {\n return Object.assign(new WritableImpl<T>(this._c), {set});\n }\n\n *\"uneventful.next\"(): Yielding<T> {\n return yield (r => {\n let seen = false, res: T;\n rule(() => {\n try { res = this(); } catch(e) { rule.stop(); defer(reject.bind(null, r,e)); }\n if (seen) { rule.stop(); defer(resolve.bind(null, r, res)); }\n seen = true;\n })\n });\n }\n\n *\"uneventful.until\"(): Yielding<T> {\n return yield (r => {\n let res: T;\n try { res = this(); } catch(e) { reject(r, e); return; }\n if (res) return resolve(r, res);\n rule(() => {\n try { res = this(); } catch(e) { rule.stop(); defer(reject.bind(null, r,e)); }\n if (res) { rule.stop(); defer(resolve.bind(null, r, res)); }\n });\n });\n }\n}\n\n/**\n * A {@link Signal} with a {@link Writable.set | .set()} method and writable\n * {@link Writable.value | .value} property.\n *\n * @category Types and Interfaces\n */\nexport interface Writable<T> extends Signal<T> {\n /**\n * Set the current value. (Note: this is a bound method so it can be used\n * as a callback.)\n *\n * @category Writing\n */\n readonly set: (val: T) => void;\n\n get value(): T\n\n /** Set the current value */\n set value(val: T);\n}\n\n/** @internal */\nexport class WritableImpl<T> extends SignalImpl<T> implements Writable<T> {\n get value() { return this(); }\n set value(val: T) { this.set(val); }\n set = (val: T) => { this._c.setValue(val, false); }\n asReadonly(): Signal<T> {\n return new SignalImpl<T>(this._c);\n }\n}\n\n/**\n * A writable signal that can be set to either a value or an expression.\n *\n * Like a spreadsheet cell, a configurable signal can contain either a value or\n * a formula. If you .set() a value or change the .value property of the\n * signal, the formula is cleared. Conversely, if you set a formula with\n * .setf(), then the value is calculated using that formula from then on, until\n * another formula is set, or the value is changed directly again.\n *\n * @category Types and Interfaces\n */\nexport interface Configurable<T> extends Writable<T> {\n /**\n * Set a formula that will be used to calculate the signal's value. If it\n * uses the value of other signals, this signal's value will be recalculated\n * when they change.\n *\n * @category Writing\n */\n setf(expr: () => T): this;\n}\n\n/** @internal */\nexport class ConfigurableImpl<T> extends WritableImpl<T> implements Configurable<T> {\n setf(expr: () => T): this {\n this._c.setCalc(expr);\n return this;\n }\n}\n\n/**\n * Create a {@link Configurable} signal with the given inital value\n *\n * @category Reactive Values\n */\nexport function value<T>(val?: T): Configurable<T> {\n const cell = Cell.mkValue(val);\n return new ConfigurableImpl<T>(cell);\n}\n\n/**\n * Create a cached version of a function. The returned callable is also a\n * {@link Signal}.\n *\n * Note: If the supplied function has a non-zero `.length` (i.e., it explicitly\n * takes arguments), it is assumed to be a {@link Source}, and the second\n * calling signature below will apply, even if TypeScript doesn't see it that\n * way!)\n *\n * @category Reactive Values\n */\nexport function cached<T>(compute: () => T): Signal<T>;\n\n/**\n * If the supplied function has a non-zero `.length` (i.e., it explicitly takes\n * arguments), it is assumed to be a {@link Source}, and the second argument is\n * a default value for the created signal to use as default value until the\n * source produces a value.\n *\n * The source will be subscribed *only* while the signal is subscribed as a\n * stream, or observed (directly or indirectly) by a rule. While subscribed,\n * the signal will update itself with the most recent value produced by the\n * source, triggering rules or events as appropriate if the value changes. When\n * the signal is once again unobserved (or if the source ends without an error),\n * its value will revert to the supplied default.\n *\n * If the source ends *with* an error, however, then the cached function will\n * throw that error whenever called, until/unless it becomes unobserved again.\n * (And thus reverts to the default value once more.)\n *\n * @param source A {@link Source} providing data which will become this signal's\n * value\n * @param defaultVal The value to use when the signal is unobserved or waiting for\n * the first item from the source.\n */\nexport function cached<T>(source: Source<T>, defaultVal?: T): Signal<T>;\nexport function cached<T extends Signal<any>>(signal: T): T\nexport function cached<T>(compute: Source<T> | (() => T), initVal?: T): Signal<T> {\n if (compute instanceof SignalImpl) return compute;\n return new SignalImpl<T>(\n compute.length ? Cell.mkStream(compute as Source<T>, initVal) : Cell.mkCached(compute as () => T)\n );\n}\n\n/**\n * Call a function without creating a dependency on any signals it reads. (Like\n * {@link Signal.peek}, but for any function with any arguments.)\n *\n * You can also pass in any arguments the function takes, and the function's\n * return value is returned.\n *\n * (Note: Typed overloads are not supported: TypeScript will use the function's\n * *last* overload for argument-typing purposes. If you need to call a function\n * with a specific overload, wrap the function with {@link action}() instead, and\n * then TypeScript will be able to detect which overload you're using.)\n *\n * @returns The result of calling `fn(..args)`\n *\n * @category Reactive Values\n */\nexport function peek<F extends PlainFunction>(fn: F, ...args: Parameters<F>): ReturnType<F> {\n if (!current.cell) return fn(...args);\n const old = swapCtx(makeCtx(current.job));\n try { return fn(...args); } finally { freeCtx(swapCtx(old)); }\n}\n\n/**\n * Wrap a function (or decorate a method) so that signals it reads are not added\n * as dependencies to the current rule (if any). (Basically, it's shorthand for\n * wrapping the function or method body in a giant call to {@link peek}().)\n *\n * So, instead of writing an action function like this:\n *\n * ```ts\n * function outer(arg1, arg2) {\n * return peek(() => {\n * // reactive values used here will not be added to the running rule\n * })\n * }\n * ```\n * you can just write this:\n * ```ts\n * const outer = action((arg1, arg2) => {\n * // reactive values used here will not be added to the running rule\n * });\n * ```\n * or this:\n * ```ts\n * class Something {\n * @action // auto-detects TC39 or legacy decorators\n * someMethod(arg1) {\n * // reactive values used here will not be added to the running rule\n * }\n * }\n * ```\n *\n * @param fn The function to wrap. It can take any arguments or return value,\n * and overloads are supported. However, any non-standard properties the\n * function may have had will *not* be present on the wrapped function, even if\n * TypeScript will act as if they are!\n *\n * @returns A wrapped version of the function that passes through its arguments\n * to the original function, while running with dependency tracking suppressed\n * (as with {@link peek}()).\n *\n * @category Reactive Behaviors\n */\nexport function action<F extends AnyFunction>(fn: F): F;\n\n/** @hidden TC39 Decorator protocol */\nexport function action<F extends AnyFunction>(fn: F, ctx: {kind: \"method\"}): F;\n\n/** @hidden Legacy Decorator protocol */\nexport function action<F extends AnyFunction, D extends {value?: F}>(\n clsOrProto: any, name: string|symbol, desc: D\n): D\n\nexport function action<F extends AnyFunction, D extends {value?: F}>(fn: F, _ctx?: any, desc?: D): D | F {\n if (desc) return {...desc, value: action(desc.value)};\n return <F> function (this: ThisParameterType<F>) {\n if (!current.cell) return apply(fn, this, arguments);\n const old = swapCtx(makeCtx(current.job));\n try { return apply(fn, this, arguments); } finally { freeCtx(swapCtx(old)); }\n }\n}\n\n/**\n * Wait for and return the next truthy value (or error) from a data source (when\n * processed with `yield *` within a {@link Job}).\n *\n * This differs from {@link next}() in that it waits for the next \"truthy\" value\n * (i.e., not null, false, zero, empty string, etc.), and when used with signals\n * or a signal-using function, it can resume *immediately* if the result is\n * already truthy. (It also supports zero-argument signal-using functions,\n * automatically wrapping them with {@link cached}(), as the common use case for\n * until() is to wait for an arbitrary condition to be satisfied.)\n *\n * @param source The source to wait on, which can be:\n * - An object with an `\"uneventful.until\"` method returning a {@link Yielding}\n * (in which case the result will be the the result of calling that method)\n * - A {@link Signal}, or a zero-argument function returning a value based on\n * signals (in which case the job resumes as soon as the result is truthy,\n * perhaps immediately)\n * - A {@link Source} (in which case the job resumes on the next truthy value\n * it produces\n *\n * (Note: if the supplied source is a function with a non-zero `.length`, it is\n * assumed to be a {@link Source}.)\n *\n * @returns a Yieldable that when processed with `yield *` in a job, will return\n * the triggered event, or signal value. An error is thrown if event stream\n * throws or closes early, or the signal throws.\n *\n * @category Scheduling\n */\n\nexport function until<T>(source: UntilMethod<T> | Stream<T> | (() => T)): Yielding<T> {\n return callOrWait<T>(source, \"uneventful.until\", waitTruthy, recache);\n}\nfunction recache<T>(s: () => T) { return until(cached(s)); }\nfunction waitTruthy<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MAAM,EAAE;AAC9B,EAAE,OAAO,UAAU,CAAC,MAAM,EAAE,kBAAkB,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;AACrE,CAAC;AACD,SAAS,OAAO,CAAC,CAAC,EAAE;AACpB,EAAE,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;AAC1B,CAAC;AACD,SAAS,UAAU,CAAC,GAAG,EAAE,CAAC,EAAE;AAC5B,EAAE,CAAC,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;AACrB;;;;"}
|
|
@@ -178,5 +178,30 @@ declare function recalcWhen(src: RecalcSource): void;
|
|
|
178
178
|
* function, not a closure, or the same memory thrash issue will occur!)
|
|
179
179
|
*/
|
|
180
180
|
declare function recalcWhen<T extends WeakKey>(key: T, factory: (key: T) => RecalcSource): void;
|
|
181
|
+
/**
|
|
182
|
+
* Find out whether the active signal is being observed, or just queried.
|
|
183
|
+
*
|
|
184
|
+
* If the return value is true, the caller is running within a signal
|
|
185
|
+
* calculation that is being observed by subscribers (such as a rule or stream
|
|
186
|
+
* listener). If the return value is false, the caller is running within a
|
|
187
|
+
* signal calculation that is *not* observed by any subscribers, and the signal
|
|
188
|
+
* will be recalculated whenever it transitions from unobserved to observed.
|
|
189
|
+
*
|
|
190
|
+
* Returns `undefined` if the caller isn't running in a signal calculation.
|
|
191
|
+
*
|
|
192
|
+
* @remarks Note that calling this function within a signal calculation even
|
|
193
|
+
* once adds a *permanent*, implicit dependency to that signal, on whether the
|
|
194
|
+
* signal is being observed. (As does using any job APIs directly.)
|
|
195
|
+
*
|
|
196
|
+
* The assumption here is that if you're checking whether it's observed, it's
|
|
197
|
+
* because you only want to do certain things *while* it's being observed, so
|
|
198
|
+
* the signal needs to be recalculated when it *starts* being observed, so you
|
|
199
|
+
* can do those things. (If you need to undo or clean up those things when the
|
|
200
|
+
* signal is no-longer observed, you can register a cleanup callback via e.g.
|
|
201
|
+
* {@link must}(), or wrap them in a sub-job with start, connect, etc.)
|
|
202
|
+
*
|
|
203
|
+
* @category Signals
|
|
204
|
+
*/
|
|
205
|
+
declare function isObserved(): boolean | undefined;
|
|
181
206
|
|
|
182
|
-
export { type EachResult as E, type NextMethod as N, type UntilMethod as U, type Each as a, each as e, forEach as f, next as n, recalcWhen as r };
|
|
207
|
+
export { type EachResult as E, type NextMethod as N, type UntilMethod as U, type Each as a, each as e, forEach as f, isObserved as i, next as n, recalcWhen as r };
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
let defer = typeof queueMicrotask === "function" ? queueMicrotask : /* @__PURE__ */ ((p) => (cb) => p.then(cb))(Promise.resolve());
|
|
2
|
+
|
|
3
|
+
function batch(process, sched) {
|
|
4
|
+
return new _Batch(process, sched);
|
|
5
|
+
}
|
|
6
|
+
class _Batch {
|
|
7
|
+
constructor(reap, sched) {
|
|
8
|
+
this.reap = reap;
|
|
9
|
+
this.sched = sched;
|
|
10
|
+
this._flags = 0 /* Unset */;
|
|
11
|
+
this.q = /* @__PURE__ */ new Set();
|
|
12
|
+
this._run = () => {
|
|
13
|
+
this._flags &= ~2 /* Scheduled */;
|
|
14
|
+
this.flush();
|
|
15
|
+
};
|
|
16
|
+
/** Run all pending items */
|
|
17
|
+
this.flush = () => {
|
|
18
|
+
if (this._flags & 1 /* Running */)
|
|
19
|
+
return;
|
|
20
|
+
const { q: queue } = this;
|
|
21
|
+
if (!queue.size)
|
|
22
|
+
return;
|
|
23
|
+
this._flags |= 1 /* Running */;
|
|
24
|
+
try {
|
|
25
|
+
this.reap(queue);
|
|
26
|
+
} finally {
|
|
27
|
+
this._flags &= ~1 /* Running */;
|
|
28
|
+
!queue.size || this._flags & 2 /* Scheduled */ || this._sched();
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/** Is this queue currently running? */
|
|
33
|
+
isRunning() {
|
|
34
|
+
return !!(this._flags & 1 /* Running */);
|
|
35
|
+
}
|
|
36
|
+
/** Is this queue currently empty? */
|
|
37
|
+
isEmpty() {
|
|
38
|
+
return !this.q.size;
|
|
39
|
+
}
|
|
40
|
+
add(subject) {
|
|
41
|
+
this.q.size || this._flags & (1 /* Running */ | 2 /* Scheduled */) || this._sched();
|
|
42
|
+
this.q.add(subject);
|
|
43
|
+
}
|
|
44
|
+
delete(subject) {
|
|
45
|
+
this.q.delete(subject);
|
|
46
|
+
}
|
|
47
|
+
has(subject) {
|
|
48
|
+
return this.q.has(subject);
|
|
49
|
+
}
|
|
50
|
+
_sched() {
|
|
51
|
+
this._flags |= 2 /* Scheduled */;
|
|
52
|
+
(this.sched || defer)(this._run);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const isArray = Array.isArray;
|
|
57
|
+
function arrayEq(a, b) {
|
|
58
|
+
return a === b || isArray(a) && isArray(b) && a.length === b.length && a.every(same, b);
|
|
59
|
+
}
|
|
60
|
+
function same(item, idx) {
|
|
61
|
+
return item === this[idx];
|
|
62
|
+
}
|
|
63
|
+
function setMap(map, key, val) {
|
|
64
|
+
map.set(key, val);
|
|
65
|
+
return val;
|
|
66
|
+
}
|
|
67
|
+
function isFunction(f) {
|
|
68
|
+
return typeof f === "function";
|
|
69
|
+
}
|
|
70
|
+
const CallableObject = /* @__PURE__ */ (() => Object.assign(
|
|
71
|
+
function CallableObject2(fn) {
|
|
72
|
+
return Object.setPrototypeOf(fn, new.target.prototype);
|
|
73
|
+
},
|
|
74
|
+
{ prototype: Function.prototype }
|
|
75
|
+
// No need to have extra prototypes in the chain
|
|
76
|
+
))();
|
|
77
|
+
const apply = Reflect.apply;
|
|
78
|
+
const GeneratorBase = /* @__PURE__ */ (() => {
|
|
79
|
+
function G() {
|
|
80
|
+
}
|
|
81
|
+
G.prototype = function* () {
|
|
82
|
+
}.constructor.prototype.prototype;
|
|
83
|
+
return G;
|
|
84
|
+
})();
|
|
85
|
+
|
|
86
|
+
export { CallableObject as C, GeneratorBase as G, arrayEq as a, batch as b, apply as c, defer as d, isArray as e, isFunction as i, setMap as s };
|
|
87
|
+
//# sourceMappingURL=utils-P0JEpWXG.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils-P0JEpWXG.mjs","sources":["../src/defer.ts","../src/scheduling.ts","../src/utils.ts"],"sourcesContent":["/**\n * Invoke a no-argument function as a microtask, using queueMicrotask or Promise.resolve().then()\n *\n * @category Scheduling\n */\nexport let defer: (cb: () => any) => void =\n typeof queueMicrotask === \"function\" ?\n queueMicrotask :\n (p => (cb: () => any) => p.then(cb))(Promise.resolve());\n\n/**\n * @internal For testing use only!\n *\n */\nexport function setDefer(fn: typeof defer) {\n defer = fn;\n}","import { defer } from \"./defer.ts\";\n\n/** Scheduler state flags */\nconst enum Is {\n Unset = 0,\n _ = 1,\n Running = _ << 0,\n Scheduled = _ << 1,\n}\n\n/**\n * A generic batch processing queue, implemented as a set. (So items are\n * processed at most once per batch run.)\n *\n * @template T The type of items that will be in the batch\n *\n * @category Scheduling\n */\nexport interface Batch<T> {\n /** Is the batch processing function currently running? */\n isRunning(): boolean;\n\n /** Is the batch currently empty? */\n isEmpty(): boolean;\n\n /**\n * Add an item to the batch. Schedules the batch for processing if the\n * batch was empty and is not already scheduled. (Does nothing if the\n * item is already in the batch.)\n */\n add(item: T): void;\n\n /** Remove an item from the batch. (Does not affect the schedule.) */\n delete(item: T): void;\n\n /** Is the item in the batch? */\n has(item: any): boolean;\n\n /**\n * Process the batch now by calling the processing function, unless the\n * batch is empty or already running. If the processing function exits\n * without fully emptying the batch (due to errors, time limits, etc.),\n * another flush will be scheduled via the batch's scheduler (unless one is\n * already scheduled).\n */\n readonly flush: () => void;\n}\n\n\n/**\n * Create a batch processing queue from the given processing loop and scheduling\n * function.\n *\n * @template T The type of items that will be in the batch\n *\n * @param process A function taking a set of items. It should remove items from\n * the set, usually *before* processing them. (So that the batch won't\n * perpetually block on that item in case of a persistent error.) If the\n * processing function doesn't remove all items from the set, another processing\n * pass will be done later. (This allows you to rate-limit processing, so as\n * not to hog the current thread.)\n *\n * @param sched A single-argument scheduling function (like\n * requestAnimationFrame, setImmediate, or queueMicrotask). The batch will call\n * it from time to time with a single callback. The scheduling function should\n * then arrange for that callback to be invoked *once* at some future point,\n * when it is the desired time for pending items to be processed. If no\n * function is given (or it's undefined/null), {@link defer} is used.\n *\n * @returns a {@link Batch} that items can be added to for later processing.\n *\n * @category Scheduling\n */\nexport function batch<T>(process: (items: Set<T>) => void, sched?: (cb: () => unknown) => unknown): Batch<T> {\n return new _Batch(process, sched);\n}\n\n/**\n * A generic queue for things that need to be run at-most-once per item\n * per timeframe.\n *\n * @category Scheduling\n */\nclass _Batch<T> implements Batch<T> {\n protected _flags: Is = Is.Unset;\n protected readonly q = new Set<T>();\n\n constructor(\n protected readonly reap: (queue: Set<T>) => void,\n protected readonly sched: ((cb: () => unknown) => unknown) | undefined | null,\n ) {}\n\n /** Is this queue currently running? */\n isRunning() { return !!(this._flags & Is.Running); }\n\n /** Is this queue currently empty? */\n isEmpty() { return !this.q.size; }\n\n add(subject: T) {\n this.q.size || this._flags & (Is.Running|Is.Scheduled) || this._sched();\n this.q.add(subject);\n }\n\n delete(subject: any) {\n this.q.delete(subject);\n }\n\n has(subject: any) {\n return this.q.has(subject);\n }\n\n protected _sched() {\n this._flags |= Is.Scheduled;\n (this.sched || defer)(this._run);\n }\n\n protected _run = () => {\n this._flags &= ~Is.Scheduled;\n this.flush();\n }\n\n /** Run all pending items */\n flush = () => {\n // already running? skip it\n if (this._flags & Is.Running) return;\n const {q: queue} = this;\n // nothing to do? skip it\n if (!queue.size) return;\n this._flags |= Is.Running;\n try {\n this.reap(queue);\n } finally {\n this._flags &= ~Is.Running;\n // schedule again if we're stopping early due to error\n !queue.size || (this._flags & Is.Scheduled) || this._sched();\n }\n }\n}\n","/**\n * Utilities that aren't part of Uneventful's core feature set, but are exposed\n * anyway, because they're boilerplate that can save duplication elsewhere if\n * you happen to need them.\n *\n * @module uneventful/utils\n */\nimport { AnyFunction } from \"./types.ts\";\n\n/**\n * Shorthand for Array.isArray()\n *\n * @category Data Structures\n */\nexport const isArray = Array.isArray;\n\n/**\n * Return true if the supplied parameters are the same object/vaue, or are\n * arrays with identical contents.\n *\n * @category Data Structures\n */\nexport function arrayEq<T>(a: readonly T[] | null | undefined, b: readonly T[] | null | undefined): boolean;\nexport function arrayEq<T>(a: any, b: any): boolean;\nexport function arrayEq<T>(a: readonly T[] | null | undefined, b: readonly T[] | null | undefined) {\n return (a===b) || (isArray(a) && isArray(b) && a.length === b.length && a.every(same, b))\n}\n\nfunction same(this: any[], item: any, idx: number) { return item === this[idx]; }\n\n/**\n * Set a value in a Map or WeakMap, and return the value.\n *\n * Commonly used with constructions like `return map.get(key) ?? setMap(map,\n * key, calculateDefault())`.\n *\n * @template K The type of key accepted by the map\n * @template V The type of value accepted by the map\n *\n * @category Data Structures\n */\nexport function setMap<K, V>(map: { set(key: K, val: V): void; }, key: K, val: V) {\n map.set(key, val);\n return val;\n}\n\n/**\n * Is the given value a function? (Shorthand for `typeof f === \"function\"`)\n *\n * @category Functional Programming\n */\nexport function isFunction(f: any): f is Function {\n return typeof f === \"function\";\n}\n\n/**\n * This class hides the implementation details of inheriting from Function in\n * the documentation. (By default, typedoc exposes all the inherited properties\n * and members, which we don't want. By inheriting from it instead of from\n * Function, we keep the documentation free of unimportant details.)\n *\n * The way this works is that you subclass CallableObject and define a\n * constructor that calls `super(someClosure)` where `someClosure` is a unique\n * function object, which will then pick up any properties or methods defined by\n * the subclass.\n *\n * @template T The call/return signature that instances of the class will\n * implement.\n *\n * @category Functional Programming\n */\n//@ts-ignore not really a duplicate\nexport declare class CallableObject<T extends AnyFunction> extends Function {\n /**\n * @param fn A unique function or closure, to be passed to super() in a\n * subclass. The function object will gain a prototype from `new.target`,\n * thereby picking up any properties or methods defined by the class,\n * and becoming `this` for the calling constructor.\n *\n * (Note that calling the constructor by any means other than super() from\n * a constructor will result in an error or some other unhelpful result.)\n */\n constructor(fn: T);\n /** @internal */ declare length: number;\n /** @internal */ declare arguments: any;\n /** @internal */ declare caller: Function;\n /** @internal */ declare prototype: any;\n /** @internal */ declare name: string;\n}\n//@ts-ignore CallableObject<T> adheres to the constraint of T in its *implementation*\nexport interface CallableObject<T extends AnyFunction> extends T {\n /** @internal */ [Symbol.hasInstance](value: any): boolean;\n /** @internal */ apply(this: Function, thisArg: any, argArray?: any): any;\n /** @internal */ bind(this: Function, thisArg: any, ...argArray: any[]): any;\n /** @internal */ call(this: Function, thisArg: any, ...argArray: any[]): any;\n /** @internal */ toString(): string;\n}\n//@ts-ignore This is the real implementation of the above declarations\nexport const CallableObject = /* @__PURE__ */ ( () => <typeof CallableObject> Object.assign(\n function CallableObject<T>(fn: T) { return Object.setPrototypeOf(fn, new.target.prototype); },\n {prototype: Function.prototype } // No need to have extra prototypes in the chain\n))();\n\nexport { batch, type Batch } from \"./scheduling.ts\";\n\n/**\n * Calls the `target` function with the given object as the `this` value and the\n * elements of given array as the arguments.\n *\n * @category Functional Programming\n */\nexport const apply = Reflect.apply;\n\n/**\n * A pseudo-constructor for the abstract ancestor type of all generators,\n * useful for testing whether something is `instanceof Generator`.\n *\n * @category Data Structures\n */\nexport const GeneratorBase = /* @__PURE__ */ (() => {\n function G() {}; G.prototype = (function *(){}).constructor.prototype.prototype;\n return G as any as abstract new () => Generator;\n})()\n"],"names":[],"mappings":"AAAU,IAAC,KAAK,GAAG,OAAO,cAAc,KAAK,UAAU,GAAG,cAAc,mBAAmB,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,OAAO,CAAC,OAAO,EAAE;;ACQjI,SAAS,KAAK,CAAC,OAAO,EAAE,KAAK,EAAE;AACtC,EAAE,OAAO,IAAI,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;AACpC,CAAC;AACD,MAAM,MAAM,CAAC;AACb,EAAE,WAAW,CAAC,IAAI,EAAE,KAAK,EAAE;AAC3B,IAAI,IAAI,CAA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AK,UAAU,CAAC;AACjC,CAAC;AACW,MAAC,cAAc,mBAAmB,CAAC,MAAM,MAAM,CAAC,MAAM;AAClE,EAAE,SAAS,eAAe,CAAC,EAAE,EAAE;AAC/B,IAAI,OAAO,MAAM,CAAC,cAAc,CAAC,EAAE,EAAE,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;AAC3D,GAAG;AACH,EAAE,EAAE,SAAS,EAAE,QAAQ,CAAC,SAAS,EAAE;AACnC;AACA,CAAC,IAAI;AAEO,MAAC,KAAK,GAAG,OAAO,CAAC,MAAM;AACvB,MAAC,aAAa,mBAAmB,CAAC,MAAM;AACpD,EAAE,SAAS,CAAC,GAAG;AACf,GAAG;AAEH,EAAE,CAAC,CAAC,SAAS,GAAG,aAAa;AAC7B,GAAG,CAAC,WAAW,CAAC,SAAS,CAAC,SAAS,CAAC;AACpC,EAAE,OAAO,CAAC,CAAC;AACX,CAAC;;;;"}
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,5 +1,63 @@
|
|
|
1
1
|
import { A as AnyFunction } from './types-N2ua11te.js';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* A generic batch processing queue, implemented as a set. (So items are
|
|
5
|
+
* processed at most once per batch run.)
|
|
6
|
+
*
|
|
7
|
+
* @template T The type of items that will be in the batch
|
|
8
|
+
*
|
|
9
|
+
* @category Scheduling
|
|
10
|
+
*/
|
|
11
|
+
interface Batch<T> {
|
|
12
|
+
/** Is the batch processing function currently running? */
|
|
13
|
+
isRunning(): boolean;
|
|
14
|
+
/** Is the batch currently empty? */
|
|
15
|
+
isEmpty(): boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Add an item to the batch. Schedules the batch for processing if the
|
|
18
|
+
* batch was empty and is not already scheduled. (Does nothing if the
|
|
19
|
+
* item is already in the batch.)
|
|
20
|
+
*/
|
|
21
|
+
add(item: T): void;
|
|
22
|
+
/** Remove an item from the batch. (Does not affect the schedule.) */
|
|
23
|
+
delete(item: T): void;
|
|
24
|
+
/** Is the item in the batch? */
|
|
25
|
+
has(item: any): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Process the batch now by calling the processing function, unless the
|
|
28
|
+
* batch is empty or already running. If the processing function exits
|
|
29
|
+
* without fully emptying the batch (due to errors, time limits, etc.),
|
|
30
|
+
* another flush will be scheduled via the batch's scheduler (unless one is
|
|
31
|
+
* already scheduled).
|
|
32
|
+
*/
|
|
33
|
+
readonly flush: () => void;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Create a batch processing queue from the given processing loop and scheduling
|
|
37
|
+
* function.
|
|
38
|
+
*
|
|
39
|
+
* @template T The type of items that will be in the batch
|
|
40
|
+
*
|
|
41
|
+
* @param process A function taking a set of items. It should remove items from
|
|
42
|
+
* the set, usually *before* processing them. (So that the batch won't
|
|
43
|
+
* perpetually block on that item in case of a persistent error.) If the
|
|
44
|
+
* processing function doesn't remove all items from the set, another processing
|
|
45
|
+
* pass will be done later. (This allows you to rate-limit processing, so as
|
|
46
|
+
* not to hog the current thread.)
|
|
47
|
+
*
|
|
48
|
+
* @param sched A single-argument scheduling function (like
|
|
49
|
+
* requestAnimationFrame, setImmediate, or queueMicrotask). The batch will call
|
|
50
|
+
* it from time to time with a single callback. The scheduling function should
|
|
51
|
+
* then arrange for that callback to be invoked *once* at some future point,
|
|
52
|
+
* when it is the desired time for pending items to be processed. If no
|
|
53
|
+
* function is given (or it's undefined/null), {@link defer} is used.
|
|
54
|
+
*
|
|
55
|
+
* @returns a {@link Batch} that items can be added to for later processing.
|
|
56
|
+
*
|
|
57
|
+
* @category Scheduling
|
|
58
|
+
*/
|
|
59
|
+
declare function batch<T>(process: (items: Set<T>) => void, sched?: (cb: () => unknown) => unknown): Batch<T>;
|
|
60
|
+
|
|
3
61
|
/**
|
|
4
62
|
* Utilities that aren't part of Uneventful's core feature set, but are exposed
|
|
5
63
|
* anyway, because they're boilerplate that can save duplication elsewhere if
|
|
@@ -8,6 +66,20 @@ import { A as AnyFunction } from './types-N2ua11te.js';
|
|
|
8
66
|
* @module uneventful/utils
|
|
9
67
|
*/
|
|
10
68
|
|
|
69
|
+
/**
|
|
70
|
+
* Shorthand for Array.isArray()
|
|
71
|
+
*
|
|
72
|
+
* @category Data Structures
|
|
73
|
+
*/
|
|
74
|
+
declare const isArray: (arg: any) => arg is any[];
|
|
75
|
+
/**
|
|
76
|
+
* Return true if the supplied parameters are the same object/vaue, or are
|
|
77
|
+
* arrays with identical contents.
|
|
78
|
+
*
|
|
79
|
+
* @category Data Structures
|
|
80
|
+
*/
|
|
81
|
+
declare function arrayEq<T>(a: readonly T[] | null | undefined, b: readonly T[] | null | undefined): boolean;
|
|
82
|
+
declare function arrayEq<T>(a: any, b: any): boolean;
|
|
11
83
|
/**
|
|
12
84
|
* Set a value in a Map or WeakMap, and return the value.
|
|
13
85
|
*
|
|
@@ -16,12 +88,16 @@ import { A as AnyFunction } from './types-N2ua11te.js';
|
|
|
16
88
|
*
|
|
17
89
|
* @template K The type of key accepted by the map
|
|
18
90
|
* @template V The type of value accepted by the map
|
|
91
|
+
*
|
|
92
|
+
* @category Data Structures
|
|
19
93
|
*/
|
|
20
94
|
declare function setMap<K, V>(map: {
|
|
21
95
|
set(key: K, val: V): void;
|
|
22
96
|
}, key: K, val: V): V;
|
|
23
97
|
/**
|
|
24
98
|
* Is the given value a function? (Shorthand for `typeof f === "function"`)
|
|
99
|
+
*
|
|
100
|
+
* @category Functional Programming
|
|
25
101
|
*/
|
|
26
102
|
declare function isFunction(f: any): f is Function;
|
|
27
103
|
/**
|
|
@@ -37,6 +113,8 @@ declare function isFunction(f: any): f is Function;
|
|
|
37
113
|
*
|
|
38
114
|
* @template T The call/return signature that instances of the class will
|
|
39
115
|
* implement.
|
|
116
|
+
*
|
|
117
|
+
* @category Functional Programming
|
|
40
118
|
*/
|
|
41
119
|
declare class CallableObject<T extends AnyFunction> extends Function {
|
|
42
120
|
/**
|
|
@@ -53,6 +131,20 @@ declare class CallableObject<T extends AnyFunction> extends Function {
|
|
|
53
131
|
interface CallableObject<T extends AnyFunction> extends T {
|
|
54
132
|
}
|
|
55
133
|
declare const CallableObject: any;
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Calls the `target` function with the given object as the `this` value and the
|
|
137
|
+
* elements of given array as the arguments.
|
|
138
|
+
*
|
|
139
|
+
* @category Functional Programming
|
|
140
|
+
*/
|
|
56
141
|
declare const apply: typeof Reflect.apply;
|
|
142
|
+
/**
|
|
143
|
+
* A pseudo-constructor for the abstract ancestor type of all generators,
|
|
144
|
+
* useful for testing whether something is `instanceof Generator`.
|
|
145
|
+
*
|
|
146
|
+
* @category Data Structures
|
|
147
|
+
*/
|
|
148
|
+
declare const GeneratorBase: abstract new () => Generator;
|
|
57
149
|
|
|
58
|
-
export { CallableObject, apply, isFunction, setMap };
|
|
150
|
+
export { type Batch, CallableObject, GeneratorBase, apply, arrayEq, batch, isArray, isFunction, setMap };
|