@mmstack/primitives 21.0.13 → 21.0.14

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mmstack/primitives",
3
- "version": "21.0.13",
3
+ "version": "21.0.14",
4
4
  "keywords": [
5
5
  "angular",
6
6
  "signals",
@@ -1,4 +1,40 @@
1
- import { CreateSignalOptions, DestroyRef, WritableSignal, Signal, Injector, EffectRef, EffectCleanupRegisterFn, CreateEffectOptions, ElementRef, ValueEqualityFn } from '@angular/core';
1
+ import { ValueEqualityFn, Injector, Signal, CreateSignalOptions, DestroyRef, WritableSignal, EffectRef, EffectCleanupRegisterFn, CreateEffectOptions, ElementRef } from '@angular/core';
2
+
3
+ type CreateChunkedOptions<T> = {
4
+ /**
5
+ * The number of items to process in each chunk.
6
+ * @default 50
7
+ */
8
+ chunkSize?: number;
9
+ /**
10
+ * The delay between processing each chunk. Can be a number (milliseconds) or 'frame' to use `requestAnimationFrame`.
11
+ * @default 'frame'
12
+ */
13
+ delay?: number | 'frame' | 'microtask';
14
+ /**
15
+ * A custom equality function to determine if the processed chunk has changed. This can help prevent unnecessary updates if the chunk content is the same as the previous one.
16
+ */
17
+ equal?: ValueEqualityFn<T[]>;
18
+ /**
19
+ * An optional `Injector` to use for the internal effect. This allows the effect to have access to dependency injection if needed.
20
+ */
21
+ injector?: Injector;
22
+ };
23
+ /**
24
+ * Creates a new `Signal` that processes an array of items in time-sliced chunks. This is useful for handling large lists without blocking the main thread.
25
+ *
26
+ * The returned signal will initially contain the first `chunkSize` items from the source array. It will then schedule updates to include additional chunks of items based on the specified `duration`.
27
+ *
28
+ * @template T The type of items in the array.
29
+ * @param source A `Signal` or a function that returns an array of items to be processed in chunks.
30
+ * @param options Configuration options for chunk size, delay duration, equality function, and injector.
31
+ * @returns A `Signal` that emits the current chunk of items being processed.
32
+ *
33
+ * @example
34
+ * const largeList = signal(Array.from({ length: 1000 }, (_, i) => i));
35
+ * const chunkedList = chunked(largeList, { chunkSize: 100, duration: 100 });
36
+ */
37
+ declare function chunked<T>(source: Signal<T[]> | (() => T[]), options?: CreateChunkedOptions<T>): Signal<T[]>;
2
38
 
3
39
  /**
4
40
  * Options for creating a debounced writable signal.
@@ -1606,6 +1642,11 @@ declare function throttle<T>(source: WritableSignal<T>, opt?: CreateThrottledOpt
1606
1642
  * writableSignal.set(5); // sets value of originalValue.a to 5 & triggers all signals
1607
1643
  */
1608
1644
  declare function toWritable<T>(source: Signal<T>, set: (value: T) => void, update?: (updater: (value: T) => T) => void, opt?: CreateSignalOptions<T> & {
1645
+ /**
1646
+ * If `true` (the default), the returned signal will be a computed signal that depends on the source signal.
1647
+ * If `false`, the returned signal will be a direct wrapper around the source signal without creating a new computed signal.
1648
+ * @default true
1649
+ */
1609
1650
  pure?: boolean;
1610
1651
  }): WritableSignal<T>;
1611
1652
 
@@ -1759,5 +1800,5 @@ type CreateHistoryOptions<T> = Omit<CreateSignalOptions<T[]>, 'equal'> & {
1759
1800
  */
1760
1801
  declare function withHistory<T>(source: WritableSignal<T>, opt?: CreateHistoryOptions<T>): SignalWithHistory<T>;
1761
1802
 
1762
- export { combineWith, debounce, debounced, derived, distinct, elementSize, elementVisibility, filter, indexArray, isDerivation, isMutable, isStore, keyArray, map, mapArray, mapObject, mediaQuery, mousePosition, mutable, mutableStore, nestedEffect, networkStatus, pageVisibility, pipeable, piped, prefersDarkMode, prefersReducedMotion, scrollPosition, select, sensor, sensors, store, stored, tabSync, tap, throttle, throttled, toFakeDerivation, toFakeSignalDerivation, toStore, toWritable, until, windowSize, withHistory };
1763
- export type { CreateDebouncedOptions, CreateHistoryOptions, CreateStoredOptions, CreateThrottledOptions, DebouncedSignal, DerivedSignal, ElementSize, ElementSizeOptions, ElementSizeSignal, ElementVisibilityOptions, ElementVisibilitySignal, MousePositionOptions, MousePositionSignal, MutableSignal, MutableSignalStore, NetworkStatusSignal, PipeableSignal, ScrollPosition, ScrollPositionOptions, ScrollPositionSignal, SignalStore, SignalWithHistory, StoredSignal, ThrottledSignal, UntilOptions, WindowSize, WindowSizeOptions, WindowSizeSignal, WritableSignalStore };
1803
+ export { chunked, combineWith, debounce, debounced, derived, distinct, elementSize, elementVisibility, filter, indexArray, isDerivation, isMutable, isStore, keyArray, map, mapArray, mapObject, mediaQuery, mousePosition, mutable, mutableStore, nestedEffect, networkStatus, pageVisibility, pipeable, piped, prefersDarkMode, prefersReducedMotion, scrollPosition, select, sensor, sensors, store, stored, tabSync, tap, throttle, throttled, toFakeDerivation, toFakeSignalDerivation, toStore, toWritable, until, windowSize, withHistory };
1804
+ export type { CreateChunkedOptions, CreateDebouncedOptions, CreateHistoryOptions, CreateStoredOptions, CreateThrottledOptions, DebouncedSignal, DerivedSignal, ElementSize, ElementSizeOptions, ElementSizeSignal, ElementVisibilityOptions, ElementVisibilitySignal, MousePositionOptions, MousePositionSignal, MutableSignal, MutableSignalStore, NetworkStatusSignal, PipeableSignal, ScrollPosition, ScrollPositionOptions, ScrollPositionSignal, SignalStore, SignalWithHistory, StoredSignal, ThrottledSignal, UntilOptions, WindowSize, WindowSizeOptions, WindowSizeSignal, WritableSignalStore };