@mmstack/primitives 21.1.2 → 21.2.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/README.md
CHANGED
|
@@ -418,6 +418,8 @@ export class UserProfile {
|
|
|
418
418
|
|
|
419
419
|
This is also the pattern for coordinating resources registered _above_ a boundary (e.g. an app-builder page whose connectors register at a higher injector): the outer `provideTransitionScope()` is the shared scope, and any number of `<mm-unscoped-suspense>` boundaries observe it.
|
|
420
420
|
|
|
421
|
+
**Forwarding scope (advanced).** `provideForwardingTransitionScope()` provides a scope that can be **re-pointed at a different target at runtime** via `setTarget(scope | null)` — reads follow the current target, while `add`/`remove` pin to the target a resource was registered under (so re-pointing never strands a registration). It's the building block for a coordinator that hosts several independent sub-scopes and switches which one it observes — e.g. a router outlet that, per navigation, points at the incoming route's own scope (read it from any injector with `getTransitionScope(injector)`). Most apps reach for `provideTransitionScope()`; this is for that one extra level of control.
|
|
422
|
+
|
|
421
423
|
### `injectStartTransition`
|
|
422
424
|
|
|
423
425
|
The analog of React's `useTransition`. `startTransition(fn)` runs your state mutations (which commit immediately); any resource that reloads as a result **holds its value and reveals together once everything settles** — so a multi-resource update lands as one consistent frame instead of a torn mix of new and stale. The returned handle gives you a unified `pending` signal and a `done` promise for imperative coordination (disable a button, await completion).
|
|
@@ -80,7 +80,7 @@ function popFrame() {
|
|
|
80
80
|
* ]);
|
|
81
81
|
*
|
|
82
82
|
* // The fine-grained mapped list
|
|
83
|
-
* const mappedUsers =
|
|
83
|
+
* const mappedUsers = indexArray(
|
|
84
84
|
* users,
|
|
85
85
|
* (userSignal, index) => {
|
|
86
86
|
* // 1. Create a fine-grained SIDE EFFECT for *this item*
|
|
@@ -101,7 +101,7 @@ function popFrame() {
|
|
|
101
101
|
* };
|
|
102
102
|
* },
|
|
103
103
|
* {
|
|
104
|
-
* // 3. Tell
|
|
104
|
+
* // 3. Tell indexArray HOW to clean up when an item is removed, this needs to be manual as it's not a nestedEffect itself
|
|
105
105
|
* onDestroy: (mappedItem) => {
|
|
106
106
|
* mappedItem.destroyEffect();
|
|
107
107
|
* }
|
|
@@ -561,6 +561,47 @@ function injectTransitionScope() {
|
|
|
561
561
|
}
|
|
562
562
|
return scope;
|
|
563
563
|
}
|
|
564
|
+
function createForwardingScope() {
|
|
565
|
+
const own = createTransitionScope();
|
|
566
|
+
const target = signal(null, ...(ngDevMode ? [{ debugName: "target" }] : /* istanbul ignore next */ []));
|
|
567
|
+
const eff = () => target() ?? own;
|
|
568
|
+
const owners = new Map();
|
|
569
|
+
return {
|
|
570
|
+
setTarget: (t) => target.set(t),
|
|
571
|
+
resources: computed(() => eff().resources()),
|
|
572
|
+
pending: computed(() => eff().pending()),
|
|
573
|
+
suspended: (type) => eff().suspended(type),
|
|
574
|
+
add: (ref, opt) => {
|
|
575
|
+
const t = untracked(target) ?? own;
|
|
576
|
+
owners.set(ref, t);
|
|
577
|
+
t.add(ref, opt);
|
|
578
|
+
},
|
|
579
|
+
remove: (ref) => {
|
|
580
|
+
const t = owners.get(ref) ?? untracked(target) ?? own;
|
|
581
|
+
t.remove(ref);
|
|
582
|
+
owners.delete(ref);
|
|
583
|
+
},
|
|
584
|
+
commit: (value) => linkedSignal({
|
|
585
|
+
source: () => ({ v: value(), settled: !eff().pending() }),
|
|
586
|
+
computation: (curr, prev) => curr.settled || prev === undefined ? curr.v : prev.value,
|
|
587
|
+
}),
|
|
588
|
+
holding: computed(() => eff().holding()),
|
|
589
|
+
beginHold: () => (untracked(target) ?? own).beginHold(),
|
|
590
|
+
endHold: () => (untracked(target) ?? own).endHold(),
|
|
591
|
+
hold: (value) => linkedSignal({
|
|
592
|
+
source: () => ({ v: value(), held: eff().holding() }),
|
|
593
|
+
computation: (curr, prev) => prev !== undefined && curr.held ? prev.value : curr.v,
|
|
594
|
+
}),
|
|
595
|
+
};
|
|
596
|
+
}
|
|
597
|
+
/** Provide a forwarding transition scope at a boundary (used by the transition outlet). */
|
|
598
|
+
function provideForwardingTransitionScope() {
|
|
599
|
+
return { provide: TRANSITION_SCOPE, useFactory: createForwardingScope };
|
|
600
|
+
}
|
|
601
|
+
/** Read the transition scope reachable from `injector`, or null if none is provided there. */
|
|
602
|
+
function getTransitionScope(injector) {
|
|
603
|
+
return injector.get(TRANSITION_SCOPE, null);
|
|
604
|
+
}
|
|
564
605
|
/**
|
|
565
606
|
* Returns a register function bound to the nearest transition scope: it adds a resource
|
|
566
607
|
* to the scope and removes it when the caller's injection context is destroyed. Pass any
|
|
@@ -4247,5 +4288,5 @@ function withHistory(sourceOrValue, opt) {
|
|
|
4247
4288
|
* Generated bundle index. Do not edit.
|
|
4248
4289
|
*/
|
|
4249
4290
|
|
|
4250
|
-
export { MmActivity, SuspenseBoundary, SuspenseBoundaryBase, UnscopedSuspenseBoundary, activeTransaction, batteryStatus, chunked, clipboard, combineWith, createTransaction, createTransitionScope, debounce, debounced, derived, distinct, elementSize, elementVisibility, filter, filterWith, focusWithin, forkStore, geolocation, holdUntilReady, idle, indexArray, injectPaused, injectRegisterResource, injectStartTransaction, injectStartTransition, injectTransitionScope, isDerivation, isLeaf, isMutable, isOpaque, isStore, keepPrevious, keyArray, map, mapArray, mapObject, mediaQuery, merge3, mousePosition, mutable, mutableStore, nestedEffect, networkStatus, opaque, orientation, pageVisibility, pairwise, pausableComputed, pausableEffect, pausableSignal, pipeable, piped, pooled, pooledArray, pooledMap, pooledSet, prefersDarkMode, prefersReducedMotion, providePaused, provideTransitionScope, registerResource, resolvePause, scan, scrollPosition, select, sensor, sensors, signalFromEvent, startWith, store, stored, tabSync, tap, throttle, throttled, toFakeDerivation, toFakeSignalDerivation, toStore, toWritable, until, windowSize, withHistory };
|
|
4291
|
+
export { MmActivity, SuspenseBoundary, SuspenseBoundaryBase, UnscopedSuspenseBoundary, activeTransaction, batteryStatus, chunked, clipboard, combineWith, createForwardingScope, createTransaction, createTransitionScope, debounce, debounced, derived, distinct, elementSize, elementVisibility, filter, filterWith, focusWithin, forkStore, geolocation, getTransitionScope, holdUntilReady, idle, indexArray, injectPaused, injectRegisterResource, injectStartTransaction, injectStartTransition, injectTransitionScope, isDerivation, isLeaf, isMutable, isOpaque, isStore, keepPrevious, keyArray, map, mapArray, mapObject, mediaQuery, merge3, mousePosition, mutable, mutableStore, nestedEffect, networkStatus, opaque, orientation, pageVisibility, pairwise, pausableComputed, pausableEffect, pausableSignal, pipeable, piped, pooled, pooledArray, pooledMap, pooledSet, prefersDarkMode, prefersReducedMotion, provideForwardingTransitionScope, providePaused, provideTransitionScope, registerResource, resolvePause, scan, scrollPosition, select, sensor, sensors, signalFromEvent, startWith, store, stored, tabSync, tap, throttle, throttled, toFakeDerivation, toFakeSignalDerivation, toStore, toWritable, until, windowSize, withHistory };
|
|
4251
4292
|
//# sourceMappingURL=mmstack-primitives.mjs.map
|