uneventful 0.0.4 → 0.0.6
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 +773 -0
- package/dist/call-or-wait-DHkBd_bM.mjs.map +1 -0
- package/dist/mod.d.ts +22 -1575
- package/dist/mod.mjs +8 -1341
- package/dist/mod.mjs.map +1 -1
- package/dist/signals.d.ts +470 -0
- package/dist/signals.mjs +590 -0
- package/dist/signals.mjs.map +1 -0
- package/dist/sinks-kEzJo6Hc.d.ts +182 -0
- package/dist/types-N2ua11te.d.ts +966 -0
- package/dist/utils.d.ts +58 -0
- package/dist/utils.mjs +18 -0
- package/dist/utils.mjs.map +1 -0
- package/package.json +25 -8
|
@@ -0,0 +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,GAAG,GAAG,IAAI,CAAC,WAAW,EAAE,GAAG,EAAE,GAAG,GAAG,GAAG,CAAC,EAAE,EAAE;AACxD,MAAM,MAAM,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC;AAC1B,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C,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;;;;"}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { h as Suspend, a as Stream, Y as Yielding, b as Sink, I as Inlet, K as Connection, i as RecalcSource } from './types-N2ua11te.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The result type returned from calls to {@link Each}.next()
|
|
5
|
+
*
|
|
6
|
+
* @category Types and Interfaces
|
|
7
|
+
*/
|
|
8
|
+
type EachResult<T> = {
|
|
9
|
+
/** The value provided by the source being iterated */
|
|
10
|
+
item: T;
|
|
11
|
+
/**
|
|
12
|
+
* A suspend callback that must be `yield`-ed before the next call to the
|
|
13
|
+
* iterator's .next() method. (That is, you must `yield next` it exactly once
|
|
14
|
+
* per loop pass. See {@link each}() for more details.)
|
|
15
|
+
*/
|
|
16
|
+
next: Suspend<void>;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* The iterable returned by `yield *` {@link each}()
|
|
20
|
+
*
|
|
21
|
+
* @category Types and Interfaces
|
|
22
|
+
*/
|
|
23
|
+
type Each<T> = IterableIterator<EachResult<T>>;
|
|
24
|
+
/**
|
|
25
|
+
* Asynchronously iterate over an event source
|
|
26
|
+
*
|
|
27
|
+
* Usage:
|
|
28
|
+
*
|
|
29
|
+
* ```ts
|
|
30
|
+
* for (const {item: event, next} of yield *each(mouseMove)) {
|
|
31
|
+
* console.log(event.clientX, event.clientY);
|
|
32
|
+
* yield next; // required exactly once per iteration, even/w continue!
|
|
33
|
+
* }
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* each(eventSource) yield-returns an iterator of `{item, next}` pairs. The
|
|
37
|
+
* item is the data supplied by the event source, and `next` is a
|
|
38
|
+
* {@link Suspend}\<void\> that advances the iterator to the next item. It
|
|
39
|
+
* *must* be yielded exactly once per loop iteration. If you use `continue` to
|
|
40
|
+
* shortcut the loop body, you must `yield next` *before* doing so.
|
|
41
|
+
*
|
|
42
|
+
* The for-loop will end if the source ends, errors, or is canceled. The source
|
|
43
|
+
* is paused while the loop body is running, and resumed when the `yield next`
|
|
44
|
+
* happens. If events arrive anyway (e.g. because the source doesn't support
|
|
45
|
+
* pausing), they will be ignored unless you pipe the source through the
|
|
46
|
+
* {@link slack}() operator to provide a buffer. If the for-loop is exited
|
|
47
|
+
* early for any reason (or the iterator's `.return()` is called), the source is
|
|
48
|
+
* unsubscribed and the iteration ended.
|
|
49
|
+
*
|
|
50
|
+
* @category Stream Consumers
|
|
51
|
+
*/
|
|
52
|
+
declare function each<T>(src: Stream<T>): Yielding<Each<T>>;
|
|
53
|
+
/**
|
|
54
|
+
* An object that can be waited on with `yield *until()`, by calling its
|
|
55
|
+
* "uneventful.until" method. (This mostly exists to allow Signals to optimize
|
|
56
|
+
* their until() implementation, but is also open for extensions.)
|
|
57
|
+
*
|
|
58
|
+
* @category Types and Interfaces
|
|
59
|
+
*/
|
|
60
|
+
interface UntilMethod<T> {
|
|
61
|
+
/** Return an async op to resume once a truthy value is available */
|
|
62
|
+
"uneventful.until"(): Yielding<T>;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* An object that can be waited on with `yield *next()`, by calling its
|
|
66
|
+
* "uneventful.next" method. (This mostly exists to allow Signals to optimize
|
|
67
|
+
* their next() implementation, but is also open for extensions.)
|
|
68
|
+
*
|
|
69
|
+
* @category Types and Interfaces
|
|
70
|
+
*/
|
|
71
|
+
interface NextMethod<T> {
|
|
72
|
+
/** Return an async op to resume with the "next" (i.e. not current) value produced */
|
|
73
|
+
"uneventful.next"(): Yielding<T>;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Wait for and return the next value (or error) from a data source (when
|
|
77
|
+
* processed with `yield *` within a {@link Job}).
|
|
78
|
+
*
|
|
79
|
+
* This differs from {@link until}() in that it waits for the *next* value
|
|
80
|
+
* (truthy or not!), and it never resumes immediately for signals, but instead
|
|
81
|
+
* waits for the signal to *change*. (Also, it does not support zero-argument
|
|
82
|
+
* functions, unless you wrap them with {@link cached}() first.)
|
|
83
|
+
*
|
|
84
|
+
* @param source The source to wait on, which can be:
|
|
85
|
+
* - An object with an `"uneventful.next"` method returning a {@link Yielding}
|
|
86
|
+
* (in which case the result will be the the result of calling that method)
|
|
87
|
+
* - A {@link Signal} or {@link Source} (in which case the job resumes on the
|
|
88
|
+
* next value it produces)
|
|
89
|
+
*
|
|
90
|
+
* (Note: if the supplied source is a function with a non-zero `.length`, it is
|
|
91
|
+
* assumed to be a {@link Source}.)
|
|
92
|
+
*
|
|
93
|
+
* @returns a Yieldable that when processed with `yield *` in a job, will return
|
|
94
|
+
* the triggered event, or signal value. An error is thrown if event stream
|
|
95
|
+
* throws or closes early, or the signal throws.
|
|
96
|
+
*
|
|
97
|
+
* @category Stream Consumers
|
|
98
|
+
* @category Scheduling
|
|
99
|
+
*/
|
|
100
|
+
declare function next<T>(source: NextMethod<T> | Stream<T>): Yielding<T>;
|
|
101
|
+
/**
|
|
102
|
+
* Run a {@link restarting}() callback for each value produced by a source.
|
|
103
|
+
*
|
|
104
|
+
* With each event that occurs, any previous callback run is cleaned up before
|
|
105
|
+
* the new one begins. (And the last run is cleaned up when the connection or
|
|
106
|
+
* job ends.)
|
|
107
|
+
*
|
|
108
|
+
* This function is almost the exact opposite of {@link each}(), in that the
|
|
109
|
+
* stream is never paused (unless you do so manually via a throttle or inlet),
|
|
110
|
+
* and if the "loop body" (callback job) is still running when a new value
|
|
111
|
+
* arrives, forEach() restarts the job instead of dropping the value.
|
|
112
|
+
*
|
|
113
|
+
* @param src An event source (i.e. a {@link Source} or {@link Signal})
|
|
114
|
+
* @param sink A callback that receives values from the source
|
|
115
|
+
* @param inlet An optional throttle or inlet that will be used to pause the
|
|
116
|
+
* source (if it's a signal or supports backpressure)
|
|
117
|
+
* @returns a {@link Connection} that can be used to detect the stream
|
|
118
|
+
* end/error, or ended to close it early.
|
|
119
|
+
*
|
|
120
|
+
* @category Stream Consumers
|
|
121
|
+
*/
|
|
122
|
+
declare function forEach<T>(src: Stream<T>, sink: Sink<T>, inlet?: Inlet): Connection;
|
|
123
|
+
/**
|
|
124
|
+
* When called without a source, return a callback suitable for use w/{@link pipe}().
|
|
125
|
+
* e.g.:
|
|
126
|
+
*
|
|
127
|
+
* ```ts
|
|
128
|
+
* pipe(someSource, ..., forEach(v => { doSomething(v); }), optionalInlet));
|
|
129
|
+
* ```
|
|
130
|
+
*
|
|
131
|
+
*/
|
|
132
|
+
declare function forEach<T>(sink: Sink<T>, inlet?: Inlet): (src: Stream<T>) => Connection;
|
|
133
|
+
/**
|
|
134
|
+
* Arrange for the current signal or rule to recalculate on demand
|
|
135
|
+
*
|
|
136
|
+
* This lets you interop with systems that have a way to query a value and
|
|
137
|
+
* subscribe to changes to it, but not directly produce a signal. (Such as
|
|
138
|
+
* querying the DOM state and using a MutationObserver.)
|
|
139
|
+
*
|
|
140
|
+
* By calling this with a {@link Source} or {@link RecalcSource}, you arrange
|
|
141
|
+
* for it to be subscribed, if and when the call occurs in a rule or a cached
|
|
142
|
+
* function that's in use by a rule (directly or indirectly). When the source
|
|
143
|
+
* emits a value, the signal machinery will invalidate the caching of the
|
|
144
|
+
* function or rule, forcing a recalculation and subsequent rule reruns, if
|
|
145
|
+
* applicable.
|
|
146
|
+
*
|
|
147
|
+
* Note: you should generally only call the 1-argument version of this function
|
|
148
|
+
* with "static" sources - i.e. ones that won't change on every call. Otherwise,
|
|
149
|
+
* you will end up creating new signals each time, subscribing and unsubscribing
|
|
150
|
+
* on every call to recalcWhen().
|
|
151
|
+
*
|
|
152
|
+
* If the source needs to reference some object, it's best to use the 2-argument
|
|
153
|
+
* version (i.e. `recalcWhen(someObj, factory)`, where `factory` is a function
|
|
154
|
+
* that takes `someObj` and returns a suitable {@link RecalcSource}.)
|
|
155
|
+
*
|
|
156
|
+
* @remarks
|
|
157
|
+
* recalcWhen is specifically designed so that using it does not pull in any
|
|
158
|
+
* part of Uneventful's signals framework, in the event a program doesn't
|
|
159
|
+
* already use it. This means you can use it in library code to provide signal
|
|
160
|
+
* compatibility, without adding bundle bloat to code that doesn't use signals.
|
|
161
|
+
*
|
|
162
|
+
* @category Signals
|
|
163
|
+
*/
|
|
164
|
+
declare function recalcWhen(src: RecalcSource): void;
|
|
165
|
+
/**
|
|
166
|
+
* Two-argument variant of recalcWhen
|
|
167
|
+
*
|
|
168
|
+
* In certain circumstances, you may wish to use recalcWhen with a source
|
|
169
|
+
* related to some object. You could call recalcWhen with a closure, but that
|
|
170
|
+
* would create and discard signals on every call. So this 2-argument version
|
|
171
|
+
* lets you avoid that by allowing the use of an arbitrary object as a key,
|
|
172
|
+
* along with a factory function to turn the key into a {@link RecalcSource}.
|
|
173
|
+
*
|
|
174
|
+
* @param key an object to be used as a key
|
|
175
|
+
*
|
|
176
|
+
* @param factory a function that will be called with the key to obtain a
|
|
177
|
+
* {@link RecalcSource}. (Note that this factory function must also be a static
|
|
178
|
+
* function, not a closure, or the same memory thrash issue will occur!)
|
|
179
|
+
*/
|
|
180
|
+
declare function recalcWhen<T extends WeakKey>(key: T, factory: (key: T) => RecalcSource): void;
|
|
181
|
+
|
|
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 };
|