@mmstack/primitives 20.4.3 → 20.4.4
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 +18 -28
- package/fesm2022/mmstack-primitives.mjs +86 -1
- package/fesm2022/mmstack-primitives.mjs.map +1 -1
- package/index.d.ts +98 -2
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -468,6 +468,102 @@ declare function mapArray<T, U>(source: Signal<T[]> | (() => T[]), map: (value:
|
|
|
468
468
|
onDestroy?: (value: U) => void;
|
|
469
469
|
}): Signal<U[]>;
|
|
470
470
|
|
|
471
|
+
/**
|
|
472
|
+
* A pure, synchronous transform from I -> O.
|
|
473
|
+
* Prefer transforms without side effects to keep derivations predictable.
|
|
474
|
+
*/
|
|
475
|
+
type UnaryFunction<I, O> = (a: I) => O;
|
|
476
|
+
/** An Operator transforms a source Signal<I> into a derived Signal<O>. */
|
|
477
|
+
type Operator<I, O> = (src: Signal<I>) => Signal<O>;
|
|
478
|
+
type SignalMap<In> = {
|
|
479
|
+
(): PipeableSignal<In>;
|
|
480
|
+
<A>(fn1: UnaryFunction<In, A>, opt?: CreateSignalOptions<A>): PipeableSignal<A>;
|
|
481
|
+
<A, B>(fn1: UnaryFunction<In, A>, fn2: UnaryFunction<A, B>, opt?: CreateSignalOptions<B>): PipeableSignal<B>;
|
|
482
|
+
<A, B, C>(fn1: UnaryFunction<In, A>, fn2: UnaryFunction<A, B>, fn3: UnaryFunction<B, C>, opt?: CreateSignalOptions<C>): PipeableSignal<C>;
|
|
483
|
+
<A, B, C, D>(fn1: UnaryFunction<In, A>, fn2: UnaryFunction<A, B>, fn3: UnaryFunction<B, C>, fn4: UnaryFunction<C, D>, opt?: CreateSignalOptions<D>): PipeableSignal<D>;
|
|
484
|
+
<A, B, C, D, E>(fn1: UnaryFunction<In, A>, fn2: UnaryFunction<A, B>, fn3: UnaryFunction<B, C>, fn4: UnaryFunction<C, D>, fn5: UnaryFunction<D, E>, opt?: CreateSignalOptions<E>): PipeableSignal<E>;
|
|
485
|
+
<A, B, C, D, E, F>(fn1: UnaryFunction<In, A>, fn2: UnaryFunction<A, B>, fn3: UnaryFunction<B, C>, fn4: UnaryFunction<C, D>, fn5: UnaryFunction<D, E>, fn6: UnaryFunction<E, F>, opt?: CreateSignalOptions<F>): PipeableSignal<F>;
|
|
486
|
+
<A, B, C, D, E, F, G>(fn1: UnaryFunction<In, A>, fn2: UnaryFunction<A, B>, fn3: UnaryFunction<B, C>, fn4: UnaryFunction<C, D>, fn5: UnaryFunction<D, E>, fn6: UnaryFunction<E, F>, fn7: UnaryFunction<F, G>, opt?: CreateSignalOptions<G>): PipeableSignal<G>;
|
|
487
|
+
<A, B, C, D, E, F, G, H>(fn1: UnaryFunction<In, A>, fn2: UnaryFunction<A, B>, fn3: UnaryFunction<B, C>, fn4: UnaryFunction<C, D>, fn5: UnaryFunction<D, E>, fn6: UnaryFunction<E, F>, fn7: UnaryFunction<F, G>, fn8: UnaryFunction<G, H>, opt?: CreateSignalOptions<H>): PipeableSignal<H>;
|
|
488
|
+
<A, B, C, D, E, F, G, H, I>(fn1: UnaryFunction<In, A>, fn2: UnaryFunction<A, B>, fn3: UnaryFunction<B, C>, fn4: UnaryFunction<C, D>, fn5: UnaryFunction<D, E>, fn6: UnaryFunction<E, F>, fn7: UnaryFunction<F, G>, fn8: UnaryFunction<G, H>, fn9: UnaryFunction<H, I>, ...rest: UnaryFunction<any, any>[]): PipeableSignal<unknown>;
|
|
489
|
+
};
|
|
490
|
+
/** `.pipe(...)` — compose operators (Signal -> Signal). */
|
|
491
|
+
type SignalPipe<In> = {
|
|
492
|
+
(): PipeableSignal<In>;
|
|
493
|
+
<A>(op1: Operator<In, A>): PipeableSignal<A>;
|
|
494
|
+
<A, B>(op1: Operator<In, A>, op2: Operator<A, B>): PipeableSignal<B>;
|
|
495
|
+
<A, B, C>(op1: Operator<In, A>, op2: Operator<A, B>, op3: Operator<B, C>): PipeableSignal<C>;
|
|
496
|
+
<A, B, C, D>(op1: Operator<In, A>, op2: Operator<A, B>, op3: Operator<B, C>, op4: Operator<C, D>): PipeableSignal<D>;
|
|
497
|
+
<A, B, C, D, E>(op1: Operator<In, A>, op2: Operator<A, B>, op3: Operator<B, C>, op4: Operator<C, D>, op5: Operator<D, E>): PipeableSignal<E>;
|
|
498
|
+
<A, B, C, D, E, F>(op1: Operator<In, A>, op2: Operator<A, B>, op3: Operator<B, C>, op4: Operator<C, D>, op5: Operator<D, E>, op6: Operator<E, F>): PipeableSignal<F>;
|
|
499
|
+
<A, B, C, D, E, F, G>(op1: Operator<In, A>, op2: Operator<A, B>, op3: Operator<B, C>, op4: Operator<C, D>, op5: Operator<D, E>, op6: Operator<E, F>, op7: Operator<F, G>): PipeableSignal<G>;
|
|
500
|
+
<A, B, C, D, E, F, G, H>(op1: Operator<In, A>, op2: Operator<A, B>, op3: Operator<B, C>, op4: Operator<C, D>, op5: Operator<D, E>, op6: Operator<E, F>, op7: Operator<F, G>, op8: Operator<G, H>): PipeableSignal<H>;
|
|
501
|
+
<A, B, C, D, E, F, G, H, I>(op1: Operator<In, A>, op2: Operator<A, B>, op3: Operator<B, C>, op4: Operator<C, D>, op5: Operator<D, E>, op6: Operator<E, F>, op7: Operator<F, G>, op8: Operator<G, H>, op9: Operator<H, I>, ...rest: Operator<any, any>[]): PipeableSignal<unknown>;
|
|
502
|
+
};
|
|
503
|
+
/**
|
|
504
|
+
* A `Signal<T>` augmented with a chainable `.pipe(...)` method.
|
|
505
|
+
*
|
|
506
|
+
* The `.pipe(...)` returns **computed** signals wrapped with the same method,
|
|
507
|
+
* allowing fluent, strongly-typed pipelines.
|
|
508
|
+
* @see {@link SignalPipe}
|
|
509
|
+
* @example
|
|
510
|
+
* ```ts
|
|
511
|
+
* import { piped } from '@ngrx/signals';
|
|
512
|
+
*
|
|
513
|
+
* const count = piped(1);
|
|
514
|
+
*
|
|
515
|
+
* const doubled = count.pipe(x => x * 2); // PipeableSignal<number>
|
|
516
|
+
* // doubled() === 2
|
|
517
|
+
* const toString = doubled.pipe(String); // PipeableSignal<string>
|
|
518
|
+
* // toString() === '2'
|
|
519
|
+
* ```
|
|
520
|
+
*/
|
|
521
|
+
type PipeableSignal<T, TSig extends Signal<T> = Signal<T>> = TSig & {
|
|
522
|
+
pipe: SignalPipe<T>;
|
|
523
|
+
/** Chain pure transforms to derive new signals. See {@link SignalMap}. */
|
|
524
|
+
map: SignalMap<T>;
|
|
525
|
+
};
|
|
526
|
+
/**
|
|
527
|
+
* Helper type to infer the value type of a signal.
|
|
528
|
+
* @internal
|
|
529
|
+
*/
|
|
530
|
+
type SignalValue<TSig extends Signal<any>> = TSig extends Signal<infer V> ? V : never;
|
|
531
|
+
|
|
532
|
+
/** Project with optional equality. Pure & sync. */
|
|
533
|
+
declare const select: <I, O>(projector: (v: I) => O, opt?: CreateSignalOptions<O>) => Operator<I, O>;
|
|
534
|
+
/** Combine with another signal using a projector. */
|
|
535
|
+
declare const combineWith: <A, B, R>(other: Signal<B>, project: (a: A, b: B) => R, opt?: CreateSignalOptions<R>) => Operator<A, R>;
|
|
536
|
+
/** Only re-emit when equal(prev, next) is false. */
|
|
537
|
+
declare const distinct: <T>(equal?: (a: T, b: T) => boolean) => Operator<T, T>;
|
|
538
|
+
/** map to new value */
|
|
539
|
+
declare const map: <I, O>(fn: (v: I) => O) => Operator<I, O>;
|
|
540
|
+
/** filter values, keeping the last value if it was ever available, if first value is filtered will return undefined */
|
|
541
|
+
declare const filter: <T>(predicate: (v: T) => boolean) => Operator<T, T | undefined>;
|
|
542
|
+
/** tap into the value */
|
|
543
|
+
declare const tap: <T>(fn: (v: T) => void) => Operator<T, T>;
|
|
544
|
+
|
|
545
|
+
/**
|
|
546
|
+
* Decorate any `Signal<T>` with a chainable `.pipe(...)` method.
|
|
547
|
+
*
|
|
548
|
+
* @example
|
|
549
|
+
* const s = pipeable(signal(1)); // WritableSignal<number> (+ pipe)
|
|
550
|
+
* const label = s.pipe(n => n * 2, n => `#${n}`); // Signal<string> (+ pipe)
|
|
551
|
+
* label(); // "#2"
|
|
552
|
+
*/
|
|
553
|
+
declare function pipeable<TSig extends Signal<any>>(signal: TSig): PipeableSignal<SignalValue<TSig>, TSig>;
|
|
554
|
+
/**
|
|
555
|
+
* Create a new **writable** signal and return it as a `PipableSignal`.
|
|
556
|
+
*
|
|
557
|
+
* The returned value is a `WritableSignal<T>` with `.set`, `.update`, `.asReadonly`
|
|
558
|
+
* still available (via intersection type), plus a chainable `.pipe(...)`.
|
|
559
|
+
*
|
|
560
|
+
* @example
|
|
561
|
+
* const count = piped(1); // WritableSignal<number> (+ pipe)
|
|
562
|
+
* const even = count.pipe(n => n % 2 === 0); // Signal<boolean> (+ pipe)
|
|
563
|
+
* count.update(n => n + 1);
|
|
564
|
+
*/
|
|
565
|
+
declare function piped<T>(initial: T, opt?: CreateSignalOptions<T>): PipeableSignal<T, WritableSignal<T>>;
|
|
566
|
+
|
|
471
567
|
/**
|
|
472
568
|
* Creates a read-only signal that reactively tracks whether a CSS media query
|
|
473
569
|
* string currently matches.
|
|
@@ -1318,5 +1414,5 @@ type CreateHistoryOptions<T> = Omit<CreateSignalOptions<T[]>, 'equal'> & {
|
|
|
1318
1414
|
*/
|
|
1319
1415
|
declare function withHistory<T>(source: WritableSignal<T>, opt?: CreateHistoryOptions<T>): SignalWithHistory<T>;
|
|
1320
1416
|
|
|
1321
|
-
export { debounce, debounced, derived, elementVisibility, isDerivation, isMutable, mapArray, mediaQuery, mousePosition, mutable, networkStatus, pageVisibility, prefersDarkMode, prefersReducedMotion, scrollPosition, sensor, stored, throttle, throttled, toFakeDerivation, toFakeSignalDerivation, toWritable, until, windowSize, withHistory };
|
|
1322
|
-
export type { CreateDebouncedOptions, CreateHistoryOptions, CreateStoredOptions, CreateThrottledOptions, DebouncedSignal, DerivedSignal, ElementVisibilityOptions, ElementVisibilitySignal, MousePositionOptions, MousePositionSignal, MutableSignal, NetworkStatusSignal, ScrollPosition, ScrollPositionOptions, ScrollPositionSignal, SignalWithHistory, StoredSignal, ThrottledSignal, UntilOptions, WindowSize, WindowSizeOptions, WindowSizeSignal };
|
|
1417
|
+
export { combineWith, debounce, debounced, derived, distinct, elementVisibility, filter, isDerivation, isMutable, map, mapArray, mediaQuery, mousePosition, mutable, networkStatus, pageVisibility, pipeable, piped, prefersDarkMode, prefersReducedMotion, scrollPosition, select, sensor, stored, tap, throttle, throttled, toFakeDerivation, toFakeSignalDerivation, toWritable, until, windowSize, withHistory };
|
|
1418
|
+
export type { CreateDebouncedOptions, CreateHistoryOptions, CreateStoredOptions, CreateThrottledOptions, DebouncedSignal, DerivedSignal, ElementVisibilityOptions, ElementVisibilitySignal, MousePositionOptions, MousePositionSignal, MutableSignal, NetworkStatusSignal, PipeableSignal, ScrollPosition, ScrollPositionOptions, ScrollPositionSignal, SignalWithHistory, StoredSignal, ThrottledSignal, UntilOptions, WindowSize, WindowSizeOptions, WindowSizeSignal };
|