/** * Push-based subscribable primitives for the query system. * * Two primitives: * - Subscribable — any value + "changed" notifications * - SubscribableArray — array + incremental delta events (added/removed) * * Key property: **lazy subscribe** — upstream subscriptions only activate * when the first subscriber attaches, and deactivate when the last leaves. * This means one-off reads (.value / .items) have zero subscription overhead. */ export type Unsubscribe = () => void; export interface Subscribable { /** Current value — plain read, no side effects */ readonly value: T; /** * Subscribe to change notifications. * - First call activates upstream subscriptions (lazy). * - Callback does NOT fire immediately — read .value for current state. * - Callback fires whenever .value changes. * - Last unsubscribe deactivates upstream. */ subscribe(cb: () => void, type?: 'derived' | 'reaction'): Unsubscribe; /** Tear down all internal subscriptions */ dispose(): void; } /** * Implementation of Subscribable with lazy upstream activation. */ export declare class SubscribableImpl implements Subscribable { private _value; private _derivedSubscribers; private _subscribers; private _upstreamActive; private _activateUpstream; private _deactivateUpstream; private _equals; constructor(initialValue: T, activateUpstream?: () => Unsubscribe, opts?: { equals?: false | ((a: T, b: T) => boolean); }); get value(): T; subscribe(cb: () => void, type?: 'derived' | 'reaction'): Unsubscribe; /** Update value and notify subscribers (skips if equals check passes) */ _set(value: T): void; private _notify; dispose(): void; } /** Delta events — mirrors ThreadEvent shape */ export type ArrayEvent = { init: readonly T[]; } | { added: readonly T[]; removed: readonly T[] | null; }; /** Type guard for init events. Same logic as thread's isInitEvent. */ export declare function isArrayInitEvent(event: ArrayEvent): event is { init: readonly T[]; }; export interface SubscribableArray { /** * Current snapshot — plain readonly array. * * NOTE: only stays current while at least one subscriber is active * (upstream is lazily activated on first `.subscribe()`). With no * subscribers this returns the initial snapshot from construction * and does NOT reflect later mutations. Tests/consumers that want * to observe updates must hold a subscription (`subscribe(() => {})` * is enough). */ readonly items: readonly T[]; /** Length shortcut */ readonly length: number; /** * Subscribe to delta events. * - First call activates upstream subscriptions (lazy). * - No init event on subscribe — read .items for current state. * - Receives `{ init }` only on genuine resets (triggerRemap). * - Last unsubscribe deactivates upstream. */ subscribe(cb: (event: ArrayEvent) => void, type?: 'derived' | 'reaction'): Unsubscribe; /** Tear down all internal subscriptions */ dispose(): void; } /** * Implementation of SubscribableArray with lazy upstream activation. * * Constructor takes initial items (computed synchronously at query time) * and an optional activation function that sets up upstream subscriptions. * The activation function is only called on first `.subscribe()`. */ export declare class SubscribableArrayImpl implements SubscribableArray { private _items; private _derivedSubscribers; private _subscribers; private _upstreamActive; private _activateUpstream; private _deactivateUpstream; constructor(initialItems: T[], activateUpstream?: () => Unsubscribe); get items(): readonly T[]; get length(): number; subscribe(cb: (event: ArrayEvent) => void, type?: 'derived' | 'reaction'): Unsubscribe; /** Push items and notify subscribers */ _push(...items: T[]): void; /** Remove items and notify subscribers */ _remove(items: readonly T[]): void; /** Full reset — replace all items */ _reset(items: T[]): void; private _notify; dispose(): void; } //# sourceMappingURL=subscribable.d.ts.map