@mmstack/primitives 22.8.3 → 22.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
|
@@ -1357,7 +1357,9 @@ type DuplicateKeyPolicy = {
|
|
|
1357
1357
|
* when the list is reordered.
|
|
1358
1358
|
*
|
|
1359
1359
|
* @param source A `Signal<T[]>` or a function returning `T[]`.
|
|
1360
|
-
* @param mapFn The mapping function. Receives the item
|
|
1360
|
+
* @param mapFn The mapping function. Receives the item, its index as a Signal, and the
|
|
1361
|
+
* entry's key (the effective ordinal key when `duplicateKeys` is enabled, otherwise
|
|
1362
|
+
* the raw key) — stable for the lifetime of the mapped entry.
|
|
1361
1363
|
* @param options Optional configuration:
|
|
1362
1364
|
* - `onDestroy`: A callback invoked when a mapped item is removed from the array.
|
|
1363
1365
|
* - `key`: A custom key extractor for identity matching (e.g. `(item) => item.id`)
|
|
@@ -1387,7 +1389,7 @@ type DuplicateKeyPolicy = {
|
|
|
1387
1389
|
* users.set([users()[1], users()[0]]);
|
|
1388
1390
|
* ```
|
|
1389
1391
|
*/
|
|
1390
|
-
declare function keyArray<T, U, K>(source: Signal<T[]> | (() => T[]), mapFn: (v: T, i: Signal<number
|
|
1392
|
+
declare function keyArray<T, U, K>(source: Signal<T[]> | (() => T[]), mapFn: (v: T, i: Signal<number>, key: K | string) => U, options?: {
|
|
1391
1393
|
onDestroy?: (value: U) => void;
|
|
1392
1394
|
/**
|
|
1393
1395
|
* Optional function to use a custom key for item comparison.
|
|
@@ -4185,6 +4187,7 @@ type StoredSignal<T> = WritableSignal<T> & {
|
|
|
4185
4187
|
* ```
|
|
4186
4188
|
*/
|
|
4187
4189
|
declare function stored<T>(fallback: T, { key, store: providedStore, serialize, deserialize, syncTabs, equal, onKeyChange, cleanupOldKey, validate, pause, injector: providedInjector, ...rest }: CreateStoredOptions<T>): StoredSignal<T>;
|
|
4190
|
+
declare function isStored<T = unknown>(value: WritableSignal<T>): value is StoredSignal<T>;
|
|
4188
4191
|
|
|
4189
4192
|
/**
|
|
4190
4193
|
* The cross-tab transport `tabSync` rides. The default is {@link MessageBus} (a `BroadcastChannel`);
|
|
@@ -4372,6 +4375,85 @@ declare function toWritable<T>(source: Signal<T>, set: (value: T) => void, updat
|
|
|
4372
4375
|
pure?: boolean;
|
|
4373
4376
|
}): WritableSignal<T>;
|
|
4374
4377
|
|
|
4378
|
+
/**
|
|
4379
|
+
* A member of the writable-signal family that has been wrapped by {@link traced}.
|
|
4380
|
+
* It carries the full surface of the wrapped signal `S` plus a {@link Traced.causedBy}
|
|
4381
|
+
* read that reports the cause recorded at the most recent write.
|
|
4382
|
+
*
|
|
4383
|
+
* @typeParam S - The wrapped writable-signal type (e.g. `WritableSignal`, `MutableSignal`, `DerivedSignal`).
|
|
4384
|
+
* @typeParam C - The type of the captured cause.
|
|
4385
|
+
*/
|
|
4386
|
+
type Traced<S extends WritableSignal<unknown>, C> = S & {
|
|
4387
|
+
/**
|
|
4388
|
+
* The cause captured during the most recent synchronous write, or `undefined`
|
|
4389
|
+
* if the last write happened with no ambient cause. This is a plain read, not
|
|
4390
|
+
* a signal — it never creates a reactive dependency and adds zero recomputations.
|
|
4391
|
+
*/
|
|
4392
|
+
causedBy(): C | undefined;
|
|
4393
|
+
};
|
|
4394
|
+
/**
|
|
4395
|
+
* Wraps any member of the writable-signal family so that every synchronous write
|
|
4396
|
+
* first records an ambient "cause" (via the caller-provided `capture` function)
|
|
4397
|
+
* and then delegates to the original write, preserving the wrapped signal's exact
|
|
4398
|
+
* write semantics. The recorded cause is exposed through a plain {@link Traced.causedBy}
|
|
4399
|
+
* read, letting a downstream consumer attribute a change to whatever caused it —
|
|
4400
|
+
* without any dependency on a particular telemetry system.
|
|
4401
|
+
*
|
|
4402
|
+
* Capture is **synchronous-only** and last-writer-wins: the cause is whatever
|
|
4403
|
+
* `capture()` returns during the `set`/`update`/`mutate`/`inline` call. A write
|
|
4404
|
+
* performed after an `await` (once the ambient cause has been cleared) records
|
|
4405
|
+
* `undefined`; a write while `capture()` returns `undefined` clears the cause.
|
|
4406
|
+
* `causedBy()` is a plain read, not a signal — reading it never subscribes, and
|
|
4407
|
+
* a cause-only change (a write with a different cause but no dependent-visible
|
|
4408
|
+
* value change) never invalidates a consumer.
|
|
4409
|
+
*
|
|
4410
|
+
* The traced twin behaves like the original except for `causedBy`: it carries the
|
|
4411
|
+
* wrapped signal's surface — `asReadonly`, the `mutate`/`inline` methods of a
|
|
4412
|
+
* mutable, and the `from` of a derived — and the underlying write semantics survive
|
|
4413
|
+
* (a traced `derived` still writes through to its source; a traced `toWritable` still
|
|
4414
|
+
* runs its custom `set`). Reads through the twin stay tracked — consumers subscribe
|
|
4415
|
+
* exactly as they would to the source.
|
|
4416
|
+
*
|
|
4417
|
+
* @typeParam S - The wrapped writable-signal type.
|
|
4418
|
+
* @typeParam C - The type of the captured cause.
|
|
4419
|
+
*
|
|
4420
|
+
* @param sig - The writable signal to trace. Any family member is accepted
|
|
4421
|
+
* (`signal`, `mutable`, `derived`, `toWritable`, `stored`, ...).
|
|
4422
|
+
* @param capture - A function invoked synchronously at the start of every write.
|
|
4423
|
+
* Its return value becomes the current cause; returning `undefined`
|
|
4424
|
+
* clears it.
|
|
4425
|
+
* @param opt - Optional configuration.
|
|
4426
|
+
* @param opt.pure - If `true` (the default), the returned twin is a **new** signal
|
|
4427
|
+
* that reads through to `sig`; `sig` itself is left untouched, so
|
|
4428
|
+
* tracing a shared signal never makes the original writable or
|
|
4429
|
+
* alters its behaviour.
|
|
4430
|
+
*
|
|
4431
|
+
* CAUTION: with `pure: false` the write methods are patched
|
|
4432
|
+
* directly onto the `sig` object you passed in — every other
|
|
4433
|
+
* holder of that signal now records causes on write. Only use it
|
|
4434
|
+
* with a signal you created and own exclusively.
|
|
4435
|
+
*
|
|
4436
|
+
* @returns A {@link Traced} twin of `sig` exposing `causedBy()`.
|
|
4437
|
+
*
|
|
4438
|
+
* @example
|
|
4439
|
+
* // A refetch attributing itself to whatever wrote the query.
|
|
4440
|
+
* let activeCause: string | undefined;
|
|
4441
|
+
* const query = traced(signal(''), () => activeCause);
|
|
4442
|
+
*
|
|
4443
|
+
* activeCause = 'user-typed';
|
|
4444
|
+
* query.set('hello');
|
|
4445
|
+
* query.causedBy(); // 'user-typed'
|
|
4446
|
+
*
|
|
4447
|
+
* @example
|
|
4448
|
+
* // Tracing a shared, read-only-exposed signal without making it writable.
|
|
4449
|
+
* const shared = signal(0);
|
|
4450
|
+
* const twin = traced(shared, () => currentInteraction());
|
|
4451
|
+
* twin === shared; // false — the original is untouched
|
|
4452
|
+
*/
|
|
4453
|
+
declare function traced<S extends WritableSignal<unknown>, C>(sig: S, capture: () => C | undefined, opt?: {
|
|
4454
|
+
pure?: boolean;
|
|
4455
|
+
}): Traced<S, C>;
|
|
4456
|
+
|
|
4375
4457
|
type UntilOptions = {
|
|
4376
4458
|
/**
|
|
4377
4459
|
* Optional timeout in milliseconds. If the condition is not met
|
|
@@ -4522,5 +4604,5 @@ type CreateHistoryOptions<T> = Omit<CreateSignalOptions<T[]>, 'equal'> & {
|
|
|
4522
4604
|
*/
|
|
4523
4605
|
declare function withHistory<T>(sourceOrValue: WritableSignal<T> | T, opt?: CreateHistoryOptions<T>): SignalWithHistory<T>;
|
|
4524
4606
|
|
|
4525
|
-
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 };
|
|
4526
|
-
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 };
|
|
4607
|
+
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 };
|
|
4608
|
+
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 };
|