@mmstack/primitives 20.6.2 → 20.7.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 = mapArray(
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 mapArray HOW to clean up when an item is removed, this needs to be manual as it's not a nestedEffect itself
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
  * }
@@ -573,6 +573,47 @@ function injectTransitionScope() {
573
573
  }
574
574
  return scope;
575
575
  }
576
+ function createForwardingScope() {
577
+ const own = createTransitionScope();
578
+ const target = signal(null, ...(ngDevMode ? [{ debugName: "target" }] : []));
579
+ const eff = () => target() ?? own;
580
+ const owners = new Map();
581
+ return {
582
+ setTarget: (t) => target.set(t),
583
+ resources: computed(() => eff().resources()),
584
+ pending: computed(() => eff().pending()),
585
+ suspended: (type) => eff().suspended(type),
586
+ add: (ref, opt) => {
587
+ const t = untracked(target) ?? own;
588
+ owners.set(ref, t);
589
+ t.add(ref, opt);
590
+ },
591
+ remove: (ref) => {
592
+ const t = owners.get(ref) ?? untracked(target) ?? own;
593
+ t.remove(ref);
594
+ owners.delete(ref);
595
+ },
596
+ commit: (value) => linkedSignal({
597
+ source: () => ({ v: value(), settled: !eff().pending() }),
598
+ computation: (curr, prev) => curr.settled || prev === undefined ? curr.v : prev.value,
599
+ }),
600
+ holding: computed(() => eff().holding()),
601
+ beginHold: () => (untracked(target) ?? own).beginHold(),
602
+ endHold: () => (untracked(target) ?? own).endHold(),
603
+ hold: (value) => linkedSignal({
604
+ source: () => ({ v: value(), held: eff().holding() }),
605
+ computation: (curr, prev) => prev !== undefined && curr.held ? prev.value : curr.v,
606
+ }),
607
+ };
608
+ }
609
+ /** Provide a forwarding transition scope at a boundary (used by the transition outlet). */
610
+ function provideForwardingTransitionScope() {
611
+ return { provide: TRANSITION_SCOPE, useFactory: createForwardingScope };
612
+ }
613
+ /** Read the transition scope reachable from `injector`, or null if none is provided there. */
614
+ function getTransitionScope(injector) {
615
+ return injector.get(TRANSITION_SCOPE, null);
616
+ }
576
617
  /**
577
618
  * Returns a register function bound to the nearest transition scope: it adds a resource
578
619
  * to the scope and removes it when the caller's injection context is destroyed. Pass any
@@ -4278,5 +4319,5 @@ function withHistory(sourceOrValue, opt) {
4278
4319
  * Generated bundle index. Do not edit.
4279
4320
  */
4280
4321
 
4281
- 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 };
4322
+ 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 };
4282
4323
  //# sourceMappingURL=mmstack-primitives.mjs.map