import { UmbDeepState } from './deep-state.js'; /** * @class UmbArrayState * @augments {UmbDeepState} * @description - A RxJS BehaviorSubject which deepFreezes the object-data to ensure its not manipulated from any implementations. * Additionally the Subject ensures the data is unique, not updating any Observes unless there is an actual change of the content. * * The ArrayState provides methods to append data when the data is an Object. */ export declare class UmbArrayState extends UmbDeepState { #private; readonly getUniqueMethod: (entry: T) => U; constructor(initialData: T[], getUniqueOfEntryMethod: (entry: T) => U); /** * @function sortBy * @param {(a: T, b: T) => number} sortMethod - A method to be used for sorting every time data is set. * @returns {UmbArrayState} Reference to it self. * @description - A sort method to this Subject. * @example Example add sort method * const data = [ * { key: 1, value: 'foo'}, * { key: 2, value: 'bar'} * ]; * const myState = new UmbArrayState(data, (x) => x.key); * myState.sortBy((a, b) => (a.sortOrder || 0) - (b.sortOrder || 0)); */ sortBy(sortMethod?: (a: T, b: T) => number): this; /** * @function setValue * @param value * @param {T} data - The next data for this state to hold. * @description - Set the data of this state, if sortBy has been defined for this state the data will be sorted before set. If data is different than current this will trigger observations to update. * @example Example change the data of a state * const myState = new UmbArrayState(['Good morning']); * // myState.value is equal ['Good morning']. * myState.setValue(['Goodnight']) * // myState.value is equal ['Goodnight']. */ setValue(value: T[]): void; /** * @function clear * @description - Set the data of this state to an empty array. * @example Example clearing the data of a state * const myState = new UmbArrayState(['Good morning']); * // myState.value is equal ['Good morning']. * myState.clear() * // myState.value is equal []. */ clear(): void; /** * @function getHasOne * @param {U} unique - the unique value to compare with. * @returns {boolean} Wether it existed * @description - Check if a unique value exists in the current data of this Subject. * @example Example check for key to exist. * const data = [ * { key: 1, value: 'foo'}, * { key: 2, value: 'bar'} * ]; * const myState = new UmbArrayState(data, (x) => x.key); * myState.hasOne(1); */ getHasOne(unique: U): boolean; /** * @function remove * @param {U[]} uniques - The unique values to remove. * @returns {UmbArrayState} Reference to it self. * @description - Remove some new data of this Subject. * @example Example remove entry with id '1' and '2' * const data = [ * { id: 1, value: 'foo'}, * { id: 2, value: 'bar'} * ]; * const myState = new UmbArrayState(data, (x) => x.id); * myState.remove([1, 2]); */ remove(uniques: U[]): this; /** * @function removeOne * @param {U} unique - The unique value to remove. * @returns {UmbArrayState} Reference to it self. * @description - Remove some new data of this Subject. * @example Example remove entry with id '1' * const data = [ * { id: 1, value: 'foo'}, * { id: 2, value: 'bar'} * ]; * const myState = new UmbArrayState(data, (x) => x.id); * myState.removeOne(1); */ removeOne(unique: U): this; /** * @function filter * @param predicate * @param {unknown} filterMethod - The unique value to remove. * @returns {UmbArrayState} Reference to it self. * @description - Remove some new data of this Subject. * @example Example remove entry with key '1' * const data = [ * { key: 1, value: 'foo'}, * { key: 2, value: 'bar'}, * { key: 3, value: 'poo'} * ]; * const myState = new UmbArrayState(data, (x) => x.key); * myState.filter((entry) => entry.key !== 1); * * Result: * [ * { key: 2, value: 'bar'}, * { key: 3, value: 'poo'} * ] */ filter(predicate: (value: T, index: number, array: T[]) => boolean): this; /** * @function appendOne * @param {T} entry - new data to be added in this Subject. * @returns {UmbArrayState} Reference to it self. * @description - Append some new data to this Subject. * @example Example append some data. * const data = [ * { key: 1, value: 'foo'}, * { key: 2, value: 'bar'} * ]; * const myState = new UmbArrayState(data); * myState.append({ key: 1, value: 'replaced-foo'}); */ appendOne(entry: T): this; /** * @function appendOneAt * @param {T} entry - new data to be added in this Subject. * @param {T} index - index of where to append this data into the Subject. * @returns {UmbArrayState} Reference to it self. * @description - Append some new data to this Subject. * @example Example append some data. * const data = [ * { key: 1, value: 'foo'}, * { key: 3, value: 'bar'} * ]; * const myState = new UmbArrayState(data); * myState.appendOneAt({ key: 2, value: 'in-between'}, 1); */ appendOneAt(entry: T, index: number): this; /** * @function append * @param {T[]} entries - A array of new data to be added in this Subject. * @returns {UmbArrayState} Reference to it self. * @description - Append some new data to this Subject, if it compares to existing data it will replace it. * @example Example append some data. * const data = [ * { key: 1, value: 'foo'}, * { key: 2, value: 'bar'} * ]; * const myState = new UmbArrayState(data); * myState.append([ * { key: 1, value: 'replaced-foo'}, * { key: 3, value: 'another-bla'} * ]); */ append(entries: T[]): this; /** * @function replace * @param {Partial} entires - data of entries to be replaced. * @param entries * @returns {UmbArrayState} Reference to it self. * @description - Replaces one or more entries, requires the ArrayState to be constructed with a getUnique method. * @example Example append some data. * const data = [ * { key: 1, value: 'foo'}, * { key: 2, value: 'bar'} * ]; * const myState = new UmbArrayState(data, (x) => x.key); * const updates = [ * { key: 1, value: 'foo2'}, * { key: 3, value: 'bar2'} * ]; * myState.replace(updates); * // Only the existing item gets replaced: * myState.getValue(); // -> [{ key: 1, value: 'foo2'}, { key: 2, value: 'bar'}] */ replace(entries: Array): UmbArrayState; /** * @function updateOne * @param {U} unique - Unique value to find entry to update. * @param {Partial} entry - new data to be added in this Subject. * @returns {UmbArrayState} Reference to it self. * @description - Update a item with some new data, requires the ArrayState to be constructed with a getUnique method. * @example Example append some data. * const data = [ * { key: 1, value: 'foo'}, * { key: 2, value: 'bar'} * ]; * const myState = new UmbArrayState(data, (x) => x.key); * myState.updateOne(2, {value: 'updated-bar'}); */ updateOne(unique: U, entry: Partial): this; /** * @function prepend * @param {T[]} entries - A array of new data to be added in this Subject. * @returns {UmbArrayState} Reference to it self. * @description - Prepend some new data to this Subject, if it compares to existing data it will replace it. * @example Example prepend some data. * const data = [ * { key: 1, value: 'foo'}, * { key: 2, value: 'bar'} * ]; * const myState = new UmbArrayState(data); * myState.prepend([ * { key: 0, value: 'another-bla'}, * { key: 1, value: 'replaced-foo'}, * ]); */ prepend(entries: T[]): this; destroy(): void; }