Class DynMapReducer<K, T>
Type Parameters
- K = unknown
unknown- Key type. Defaults tounknownto enforce type safety when no type is specified. - T = unknown
unknown- Type of data. Defaults tounknownto enforce type safety when no type is specified.
Index
Constructors
Accessors
Methods
Constructors
constructor
- new DynMapReducer<K = unknown, T = unknown>(
data?: Map<K, T> | MapReducer<K, T>,
): DynMapReducer<K, T>Initializes DynMapReducer. Any iterable is supported for initial data. Take note that if
datais an array it will be used as the host array and not copied. All non-array iterables otherwise create a new array / copy.Type Parameters
- K = unknown
unknown- Key type. - T = unknown
unknown- Type of data.
Parameters
Returns DynMapReducer<K, T>
- K = unknown
Accessors
data
Returns the internal data of this instance. Be careful!
Note: When a map is set as data then that map is used as the internal data. If any changes are performed to the data externally do invoke
updatevia DynMapReducer.index withtrueto recalculate the index and notify all subscribers.Returns Map<K, T>
The internal data.
derived
Returns DynReducer.API.DerivedMap<K, T>
Derived public API.
destroyed
- get destroyed(): boolean
Returns boolean
Returns whether this instance is destroyed.
filters
Returns DynReducer.API.Filters<T>
The filters adapter.
index
length
- get length(): number
Returns number
Returns the main data items or indexed items length.
reversed
- get reversed(): boolean
Returns boolean
Returns current reversed state.
- set reversed(reversed: boolean): void
Sets reversed state and notifies subscribers.
Parameters
- reversed: boolean
New reversed state.
Returns void
- reversed: boolean
sort
Returns DynReducer.API.Sort<T>
The sort adapter.
Methods
[iterator]
Provides an iterator for data stored in DynMapReducer.
Returns IterableIterator<T>
Iterator for data stored in DynMapReducer.
destroy
Removes all derived reducers, subscriptions, and cleans up all resources.
Returns void
Protectedinitialize
ProtectedProvides a callback for custom reducers to initialize any data / custom configuration. Depending on the consumer of
dynamic-reducerthis may be utilized allowing child classes to avoid implementing the constructor.Parameters
OptionaloptionsRest: { [key: string]: any }Any additional custom options passed beyond DynReducer.Options.Common.
Returns void
setData
subscribe
Add a subscriber to this DynMapReducer instance.
Parameters
- handler: (value: this) => void
Callback function that is invoked on update / changes. Receives
thisreference.
Returns () => void
Unsubscribe function.
- handler: (value: this) => void
Provides a managed Map with non-destructive reducing / filtering / sorting capabilities with subscription / Svelte store support allowing for a Map to be treated like an iterable list.
Note:
unknownensures stricter type checking, preventing unintended operations on the data.Example