ngx-base-state
Version:
Base classes for creation state service via Rxjs observable
102 lines (101 loc) • 3.27 kB
TypeScript
import { BaseState } from './base.state';
/**
* @class
* @abstract
* @classdes Array state class. Implementing base array functionality.
*/
export declare abstract class ArrayState<T> extends BaseState<T[]> {
/**
* Return item by quired index.
* @public
* @param {Number} index - Quired index
* @deprecated use `this.data[index]` instead
* @return {Generic} quired item.
*/
getByIndex(index: number): T | undefined;
/**
* Unshift item to array in state.
* @public
* @param {Generic} item - Item needs to unshift.
*/
unshiftItem(item: T): void;
/**
* Shift array in state.
* @public
*/
shift(): void;
/**
* Pop array in state.
* @public
*/
pop(): void;
/**
* Concat current state with another array.
* @param {T[]} array - Another array to concat with the current state.
* @public
*/
concatWith(array: T[]): void;
/**
* Push item to array in state.
* @public
* @param {Generic} item - Item needs to push
*/
pushItem(item: T): void;
/**
* Insert item in array by index.
* @public
* @param {number} index - Index where to insert new item.
* @param {Generic} item - Item need to insert.
*/
insertItemByIndex(index: number, item: T): void;
/**
* Remove item in array by item identify param (using `compareItems` method).
* @public
* @param {Generic} itemId - Id of item you want to remove.
*/
removeItem(item: T): T | undefined;
/**
* Remove item in array by item id (using `getItemId` method).
* @public
* @param {Generic} itemId - Id of item you want to remove.
*/
removeItemById(itemId: unknown): T | undefined;
/**
* Remove item in array by index.
* @public
* @param {number} index - Index of item you want to remove.
*/
removeItemByIndex(index: number): T | undefined;
/**
* Update item in array by item identify param (using `compareItems` method).
* @public
* @param {Generic} itemToUpdate - item that will be update.
*/
updateItem(itemToUpdate: T): void;
/**
* Update item in array by index.
* @public
* @param {Generic} itemToUpdate - item that will be update.
* @param {Generic} index - index of item that need to update.
*/
updateItemByIndex(itemToUpdate: T, index: number): void;
protected setNewValue(value: T[] | null): void;
protected catchError(error: Error | TypeError, actionName: string): void;
/**
* Must return identify param of item.
* Method must be filled in child classes.
* Used for compare two any items.
* @protected
* @param {Generic} item - item of your state.
* @return {any} identify param of item.
*/
protected getItemId(item: T): any;
protected validateDataType(data: unknown): void;
/**
* Compare two items via `getItemId`
* @private
* @param {Generic} itemToUpdate - item that will be update.
* @return {boolean} result of comparing two items via `getItemId`.
*/
private compareItems;
}