@mmstack/primitives 21.8.3 → 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
|
@@ -1350,7 +1350,9 @@ type DuplicateKeyPolicy = {
|
|
|
1350
1350
|
* when the list is reordered.
|
|
1351
1351
|
*
|
|
1352
1352
|
* @param source A `Signal<T[]>` or a function returning `T[]`.
|
|
1353
|
-
* @param mapFn The mapping function. Receives the item
|
|
1353
|
+
* @param mapFn The mapping function. Receives the item, its index as a Signal, and the
|
|
1354
|
+
* entry's key (the effective ordinal key when `duplicateKeys` is enabled, otherwise
|
|
1355
|
+
* the raw key) — stable for the lifetime of the mapped entry.
|
|
1354
1356
|
* @param options Optional configuration:
|
|
1355
1357
|
* - `onDestroy`: A callback invoked when a mapped item is removed from the array.
|
|
1356
1358
|
* - `key`: A custom key extractor for identity matching (e.g. `(item) => item.id`)
|
|
@@ -1380,7 +1382,7 @@ type DuplicateKeyPolicy = {
|
|
|
1380
1382
|
* users.set([users()[1], users()[0]]);
|
|
1381
1383
|
* ```
|
|
1382
1384
|
*/
|
|
1383
|
-
declare function keyArray<T, U, K>(source: Signal<T[]> | (() => T[]), mapFn: (v: T, i: Signal<number
|
|
1385
|
+
declare function keyArray<T, U, K>(source: Signal<T[]> | (() => T[]), mapFn: (v: T, i: Signal<number>, key: K | string) => U, options?: {
|
|
1384
1386
|
onDestroy?: (value: U) => void;
|
|
1385
1387
|
/**
|
|
1386
1388
|
* Optional function to use a custom key for item comparison.
|
|
@@ -4178,6 +4180,7 @@ type StoredSignal<T> = WritableSignal<T> & {
|
|
|
4178
4180
|
* ```
|
|
4179
4181
|
*/
|
|
4180
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>;
|
|
4181
4184
|
|
|
4182
4185
|
/**
|
|
4183
4186
|
* The cross-tab transport `tabSync` rides. The default is {@link MessageBus} (a `BroadcastChannel`);
|
|
@@ -4365,6 +4368,85 @@ declare function toWritable<T>(source: Signal<T>, set: (value: T) => void, updat
|
|
|
4365
4368
|
pure?: boolean;
|
|
4366
4369
|
}): WritableSignal<T>;
|
|
4367
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
|
+
|
|
4368
4450
|
type UntilOptions = {
|
|
4369
4451
|
/**
|
|
4370
4452
|
* Optional timeout in milliseconds. If the condition is not met
|
|
@@ -4515,5 +4597,5 @@ type CreateHistoryOptions<T> = Omit<CreateSignalOptions<T[]>, 'equal'> & {
|
|
|
4515
4597
|
*/
|
|
4516
4598
|
declare function withHistory<T>(sourceOrValue: WritableSignal<T> | T, opt?: CreateHistoryOptions<T>): SignalWithHistory<T>;
|
|
4517
4599
|
|
|
4518
|
-
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 };
|
|
4519
|
-
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 };
|