Class DynArrayReducer<T>
Type Parameters
- T = unknown
unknown- Type of data. Defaults tounknownto enforce type safety when no type is specified. 
                 
                    
                  Hierarchy
              
              - DynArrayReducer (View Summary)
 
Index
Constructors
Accessors
Methods
Constructors
constructor
- new DynArrayReducer<T = unknown>(
data?: Iterable<T, any, any> | ListReducer<T>,
): DynArrayReducer<T>Initializes DynArrayReducer. 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
- T = unknown
unknown- Type of data. 
Parameters
Optionaldata: Iterable<T, any, any> | ListReducer<T>Data iterable to store if array or copy otherwise.
Returns DynArrayReducer<T>
 - T = unknown
 
Accessors
data
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
updatevia DynArrayReducer.index withtrueto recalculate the index and notify all subscribers.Returns T[]
The internal data.
derived
Returns DynReducer.API.DerivedList<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
Returns Index<number>
Returns the Indexer public API; is also iterable.
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 DynArrayReducer.
Returns IterableIterator<T>
Iterator for data stored in DynArrayReducer.
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 DynArrayReducer 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 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
datain the constructor it will be used as the host array and not copied. All non-array iterables otherwise create a new array / copy.Note:
unknownensures stricter type checking, preventing unintended operations on the data.Example
Example
Example