@mmstack/primitives 21.8.4 → 21.9.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mmstack/primitives",
3
- "version": "21.8.4",
3
+ "version": "21.9.0",
4
4
  "keywords": [
5
5
  "angular",
6
6
  "signals",
@@ -4180,6 +4180,7 @@ type StoredSignal<T> = WritableSignal<T> & {
4180
4180
  * ```
4181
4181
  */
4182
4182
  declare function stored<T>(fallback: T, { key, store: providedStore, serialize, deserialize, syncTabs, equal, onKeyChange, cleanupOldKey, validate, pause, injector: providedInjector, ...rest }: CreateStoredOptions<T>): StoredSignal<T>;
4183
+ declare function isStored<T = unknown>(value: WritableSignal<T>): value is StoredSignal<T>;
4183
4184
 
4184
4185
  /**
4185
4186
  * The cross-tab transport `tabSync` rides. The default is {@link MessageBus} (a `BroadcastChannel`);
@@ -4367,6 +4368,85 @@ declare function toWritable<T>(source: Signal<T>, set: (value: T) => void, updat
4367
4368
  pure?: boolean;
4368
4369
  }): WritableSignal<T>;
4369
4370
 
4371
+ /**
4372
+ * A member of the writable-signal family that has been wrapped by {@link traced}.
4373
+ * It carries the full surface of the wrapped signal `S` plus a {@link Traced.causedBy}
4374
+ * read that reports the cause recorded at the most recent write.
4375
+ *
4376
+ * @typeParam S - The wrapped writable-signal type (e.g. `WritableSignal`, `MutableSignal`, `DerivedSignal`).
4377
+ * @typeParam C - The type of the captured cause.
4378
+ */
4379
+ type Traced<S extends WritableSignal<unknown>, C> = S & {
4380
+ /**
4381
+ * The cause captured during the most recent synchronous write, or `undefined`
4382
+ * if the last write happened with no ambient cause. This is a plain read, not
4383
+ * a signal — it never creates a reactive dependency and adds zero recomputations.
4384
+ */
4385
+ causedBy(): C | undefined;
4386
+ };
4387
+ /**
4388
+ * Wraps any member of the writable-signal family so that every synchronous write
4389
+ * first records an ambient "cause" (via the caller-provided `capture` function)
4390
+ * and then delegates to the original write, preserving the wrapped signal's exact
4391
+ * write semantics. The recorded cause is exposed through a plain {@link Traced.causedBy}
4392
+ * read, letting a downstream consumer attribute a change to whatever caused it —
4393
+ * without any dependency on a particular telemetry system.
4394
+ *
4395
+ * Capture is **synchronous-only** and last-writer-wins: the cause is whatever
4396
+ * `capture()` returns during the `set`/`update`/`mutate`/`inline` call. A write
4397
+ * performed after an `await` (once the ambient cause has been cleared) records
4398
+ * `undefined`; a write while `capture()` returns `undefined` clears the cause.
4399
+ * `causedBy()` is a plain read, not a signal — reading it never subscribes, and
4400
+ * a cause-only change (a write with a different cause but no dependent-visible
4401
+ * value change) never invalidates a consumer.
4402
+ *
4403
+ * The traced twin behaves like the original except for `causedBy`: it carries the
4404
+ * wrapped signal's surface — `asReadonly`, the `mutate`/`inline` methods of a
4405
+ * mutable, and the `from` of a derived — and the underlying write semantics survive
4406
+ * (a traced `derived` still writes through to its source; a traced `toWritable` still
4407
+ * runs its custom `set`). Reads through the twin stay tracked — consumers subscribe
4408
+ * exactly as they would to the source.
4409
+ *
4410
+ * @typeParam S - The wrapped writable-signal type.
4411
+ * @typeParam C - The type of the captured cause.
4412
+ *
4413
+ * @param sig - The writable signal to trace. Any family member is accepted
4414
+ * (`signal`, `mutable`, `derived`, `toWritable`, `stored`, ...).
4415
+ * @param capture - A function invoked synchronously at the start of every write.
4416
+ * Its return value becomes the current cause; returning `undefined`
4417
+ * clears it.
4418
+ * @param opt - Optional configuration.
4419
+ * @param opt.pure - If `true` (the default), the returned twin is a **new** signal
4420
+ * that reads through to `sig`; `sig` itself is left untouched, so
4421
+ * tracing a shared signal never makes the original writable or
4422
+ * alters its behaviour.
4423
+ *
4424
+ * CAUTION: with `pure: false` the write methods are patched
4425
+ * directly onto the `sig` object you passed in — every other
4426
+ * holder of that signal now records causes on write. Only use it
4427
+ * with a signal you created and own exclusively.
4428
+ *
4429
+ * @returns A {@link Traced} twin of `sig` exposing `causedBy()`.
4430
+ *
4431
+ * @example
4432
+ * // A refetch attributing itself to whatever wrote the query.
4433
+ * let activeCause: string | undefined;
4434
+ * const query = traced(signal(''), () => activeCause);
4435
+ *
4436
+ * activeCause = 'user-typed';
4437
+ * query.set('hello');
4438
+ * query.causedBy(); // 'user-typed'
4439
+ *
4440
+ * @example
4441
+ * // Tracing a shared, read-only-exposed signal without making it writable.
4442
+ * const shared = signal(0);
4443
+ * const twin = traced(shared, () => currentInteraction());
4444
+ * twin === shared; // false — the original is untouched
4445
+ */
4446
+ declare function traced<S extends WritableSignal<unknown>, C>(sig: S, capture: () => C | undefined, opt?: {
4447
+ pure?: boolean;
4448
+ }): Traced<S, C>;
4449
+
4370
4450
  type UntilOptions = {
4371
4451
  /**
4372
4452
  * Optional timeout in milliseconds. If the condition is not met
@@ -4517,5 +4597,5 @@ type CreateHistoryOptions<T> = Omit<CreateSignalOptions<T[]>, 'equal'> & {
4517
4597
  */
4518
4598
  declare function withHistory<T>(sourceOrValue: WritableSignal<T> | T, opt?: CreateHistoryOptions<T>): SignalWithHistory<T>;
4519
4599
 
4520
- export { CONCURRENCY_INSTRUMENTATION, MmActivity, MmTransition, MmViewTransitionName, OP_PROTO_VERSION, PAUSABLE_OPTIONS, PERSISTED_STORE_OPTIONS, POS_SEGMENT, SuspenseBoundary, SuspenseBoundaryBase, UnscopedSuspenseBoundary, activeTransaction, applyOps, batteryStatus, bridgeScopeToPendingTasks, chunked, clipboard, combineWith, compareHlc, compareSiblings, compareTotal, createAttributedPending, createConvergingApply, createForwardingScope, createHlcClock, createStoreContext, createTransaction, createTransitionScope, debounce, debounced, defaultFold, deferredValue, derived, diffOps, distinct, elementSize, elementVisibility, extendStore, filter, filterWith, focusWithin, forkStore, geolocation, getTransitionScope, holdUntilReady, idle, indexArray, injectPaused, injectRegisterResource, injectStartTransaction, injectStartTransition, injectTransitionScope, insertElement, invertBatch, isConflicted, isDerivation, isLeaf, isMutable, isOpaque, isStore, keepPrevious, keyArray, keyedArray, latest, lww, map, mapArray, mapObject, mediaQuery, merge3, mergeThree, mousePosition, moveElement, mutable, mutableStore, nestedEffect, networkStatus, opLog, opSync, opaque, orderedEntries, orientation, pageVisibility, pairwise, pausableComputed, pausableEffect, pausableSignal, perfCustomTracks, persist, persistedStore, pipeable, piped, pointerDrag, policyStrategy, pooled, pooledArray, pooledMap, pooledSet, posBetween, prefersDarkMode, prefersReducedMotion, preserve, projection, provideConcurrencyInstrumentation, provideForwardingTransitionScope, providePausableOptions, providePaused, providePersistedStoreOptions, provideTransitionScope, rebalanceContainer, rebaseOps, reconcile, registerResource, removeElement, resolvePause, scan, scrollPosition, select, sensor, sensors, signalFromEvent, startWith, store, storeHistory, stored, syncedFork, tabSync, tap, throttle, throttled, toFakeDerivation, toFakeSignalDerivation, toStore, toWritable, until, use, validateEnvelope, windowSize, withHistory };
4521
- export type { AsyncStore, BatteryStatus, ClipboardSignal, Computation, ConcurrencyInstrumentation, Conflicted, ContainerNode, ConvergingApply, CreateChunkedOptions, CreateDebouncedOptions, CreateHistoryOptions, CreateLatestOptions, CreateOpLogOptions, CreatePooledOptions, CreateProvidedPooledOptions, CreateStoredOptions, CreateThrottledOptions, CreateTransitionScopeOptions, DebouncedSignal, DeferStrategy, DeferredSignal, DeferredValueOptions, DerivedSignal, Dot, DotFrontier, DuplicateKeyPolicy, ElementSize, ElementSizeOptions, ElementSizeSignal, ElementVisibilityOptions, ElementVisibilitySignal, ExtendStoreOptions, FoldFn, FoldPolicyEntry, FoldResult, Fork, ForkStoreOptions, ForkStrategy, ForwardingTransitionScope, Frame, GeolocationOptions, GeolocationSignal, Hlc, HlcClock, IdleOptions, IdleSignal, LatestSignal, MergeContext, MergeFn, MergePolicyEntry, MmTransitionContext, MousePositionOptions, MousePositionSignal, MutableSignal, MutableSignalStore, NetworkStatusSignal, OpBatch, OpEnvelope, OpLog, OpLogDriver, OpSync, OpSyncCheckpoint, OpSyncOptions, Opaque, OrderedEntry, PausableOptions, PauseOption, PersistHandle, PersistOptions, PersistedStore, PersistedStoreDefaults, PersistedStoreOptions, PipeableSignal, PointerDragOptions, PointerDragSignal, PointerDragState, PointerModifiers, PointerPoint, ProjectionOptions, RebaseResult, ReconcileFn, ReconcileKey, RegisterCheckpoint, RegisterOptions, ResourceLike, ScreenOrientation, ScreenOrientationState, ScrollPosition, ScrollPositionOptions, ScrollPositionSignal, SensorRunOptions, SignalFromEventOptions, SignalStore, SignalWithHistory, StoreHistory, StoreHistoryOptions, StoreOp, StoreOptions, StoreTabSyncOptions, StoredSignal, SuspendType, SyncOp, SyncSibling, SyncSignalOptions, SyncedFork, TabSyncBus, ThrottledSignal, Transaction, TransactionRef, TransitionRef, TransitionScope, UntilOptions, UseSource, Vivify, WindowSize, WindowSizeOptions, WindowSizeSignal, WithVivify, WritableSignalStore, toStoreOptions };
4600
+ export { CONCURRENCY_INSTRUMENTATION, MmActivity, MmTransition, MmViewTransitionName, OP_PROTO_VERSION, PAUSABLE_OPTIONS, PERSISTED_STORE_OPTIONS, POS_SEGMENT, SuspenseBoundary, SuspenseBoundaryBase, UnscopedSuspenseBoundary, activeTransaction, applyOps, batteryStatus, bridgeScopeToPendingTasks, chunked, clipboard, combineWith, compareHlc, compareSiblings, compareTotal, createAttributedPending, createConvergingApply, createForwardingScope, createHlcClock, createStoreContext, createTransaction, createTransitionScope, debounce, debounced, defaultFold, deferredValue, derived, diffOps, distinct, elementSize, elementVisibility, extendStore, filter, filterWith, focusWithin, forkStore, geolocation, getTransitionScope, holdUntilReady, idle, indexArray, injectPaused, injectRegisterResource, injectStartTransaction, injectStartTransition, injectTransitionScope, insertElement, invertBatch, isConflicted, isDerivation, isLeaf, isMutable, isOpaque, isStore, isStored, keepPrevious, keyArray, keyedArray, latest, lww, map, mapArray, mapObject, mediaQuery, merge3, mergeThree, mousePosition, moveElement, mutable, mutableStore, nestedEffect, networkStatus, opLog, opSync, opaque, orderedEntries, orientation, pageVisibility, pairwise, pausableComputed, pausableEffect, pausableSignal, perfCustomTracks, persist, persistedStore, pipeable, piped, pointerDrag, policyStrategy, pooled, pooledArray, pooledMap, pooledSet, posBetween, prefersDarkMode, prefersReducedMotion, preserve, projection, provideConcurrencyInstrumentation, provideForwardingTransitionScope, providePausableOptions, providePaused, providePersistedStoreOptions, provideTransitionScope, rebalanceContainer, rebaseOps, reconcile, registerResource, removeElement, resolvePause, scan, scrollPosition, select, sensor, sensors, signalFromEvent, startWith, store, storeHistory, stored, syncedFork, tabSync, tap, throttle, throttled, toFakeDerivation, toFakeSignalDerivation, toStore, toWritable, traced, until, use, validateEnvelope, windowSize, withHistory };
4601
+ export type { AsyncStore, BatteryStatus, ClipboardSignal, Computation, ConcurrencyInstrumentation, Conflicted, ContainerNode, ConvergingApply, CreateChunkedOptions, CreateDebouncedOptions, CreateHistoryOptions, CreateLatestOptions, CreateOpLogOptions, CreatePooledOptions, CreateProvidedPooledOptions, CreateStoredOptions, CreateThrottledOptions, CreateTransitionScopeOptions, DebouncedSignal, DeferStrategy, DeferredSignal, DeferredValueOptions, DerivedSignal, Dot, DotFrontier, DuplicateKeyPolicy, ElementSize, ElementSizeOptions, ElementSizeSignal, ElementVisibilityOptions, ElementVisibilitySignal, ExtendStoreOptions, FoldFn, FoldPolicyEntry, FoldResult, Fork, ForkStoreOptions, ForkStrategy, ForwardingTransitionScope, Frame, GeolocationOptions, GeolocationSignal, Hlc, HlcClock, IdleOptions, IdleSignal, LatestSignal, MergeContext, MergeFn, MergePolicyEntry, MmTransitionContext, MousePositionOptions, MousePositionSignal, MutableSignal, MutableSignalStore, NetworkStatusSignal, OpBatch, OpEnvelope, OpLog, OpLogDriver, OpSync, OpSyncCheckpoint, OpSyncOptions, Opaque, OrderedEntry, PausableOptions, PauseOption, PersistHandle, PersistOptions, PersistedStore, PersistedStoreDefaults, PersistedStoreOptions, PipeableSignal, PointerDragOptions, PointerDragSignal, PointerDragState, PointerModifiers, PointerPoint, ProjectionOptions, RebaseResult, ReconcileFn, ReconcileKey, RegisterCheckpoint, RegisterOptions, ResourceLike, ScreenOrientation, ScreenOrientationState, ScrollPosition, ScrollPositionOptions, ScrollPositionSignal, SensorRunOptions, SignalFromEventOptions, SignalStore, SignalWithHistory, StoreHistory, StoreHistoryOptions, StoreOp, StoreOptions, StoreTabSyncOptions, StoredSignal, SuspendType, SyncOp, SyncSibling, SyncSignalOptions, SyncedFork, TabSyncBus, ThrottledSignal, Traced, Transaction, TransactionRef, TransitionRef, TransitionScope, UntilOptions, UseSource, Vivify, WindowSize, WindowSizeOptions, WindowSizeSignal, WithVivify, WritableSignalStore, toStoreOptions };