Class DynArrayReducer<T>
Type Parameters
Hierarchy
- DynArrayReducer (View Summary)
Index
Constructors
Accessors
Methods
Constructors
constructor
- new DynArrayReducer<T = unknown>(
data?: Iterable<T> | ListReducer<T>,
): DynArrayReducer<T> Initializes DynArrayReducer. Any iterable is supported for initial data. Take note that if
data
is 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
Parameters
Optional
data: Iterable<T> | ListReducer<T>Data iterable to store if array or copy otherwise.
Returns DynArrayReducer<T>
Accessors
data
- get data(): T[]
Returns the internal data of this instance. Be careful!
Note: if an array is set as initial data then that array is used as the internal data. If any changes are performed to the data externally do invoke
update
via DynArrayReducer.index withtrue
to recalculate the index and notify all subscribers.Returns T[]
The internal data.
derived
- get derived(): DynReducer.API.DerivedList<T>
Returns DynReducer.API.DerivedList<T>
Derived public API.
destroyed
- get destroyed(): boolean
Returns boolean
Returns whether this instance is destroyed.
filters
- get filters(): DynReducer.API.Filters<T>
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
- get sort(): DynReducer.API.Sort<T>
Returns DynReducer.API.Sort<T>
The sort adapter.
Methods
[iterator]
- "[iterator]"(): IterableIterator<T>
Provides an iterator for data stored in DynArrayReducer.
Returns IterableIterator<T>
Iterator for data stored in DynArrayReducer.
destroy
Protected
initialize
- initialize(optionsRest?: { [key: string]: any }): void
Protected
Provides a callback for custom reducers to initialize any data / custom configuration. Depending on the consumer of
dynamic-reducer
this may be utilized allowing child classes to avoid implementing the constructor.Parameters
Optional
optionsRest: { [key: string]: any }Any additional custom options passed beyond DynReducer.Options.Common.
Returns void
Provides a managed array with non-destructive reducing / filtering / sorting capabilities with subscription / Svelte store support.
Note: In constructing a DynArrayReducer instance that arrays are treated as a special case. When an array is passed in as
data
in the constructor it will be used as the host array and not copied. All non-array iterables otherwise create a new array / copy.Note:
unknown
ensures stricter type checking, preventing unintended operations on the data.Example
Example
Example