import { IIterator, IterableOrArrayLike } from '@phosphor/algorithm'; import { IDisposable } from '@phosphor/disposable'; import { ISignal } from '@phosphor/signaling'; import { Vector } from './vector'; /** * A vector which can be observed for changes. */ export interface IObservableVector extends IDisposable { /** * A signal emitted when the vector has changed. */ readonly changed: ISignal>; /** * Test whether the vector is empty. * * @returns `true` if the vector is empty, `false` otherwise. * * #### Complexity * Constant. * * #### Iterator Validity * No changes. */ readonly isEmpty: boolean; /** * The length of the sequence. * * #### Notes * This is a read-only property. */ length: number; /** * Create an iterator over the values in the vector. * * @returns A new iterator starting at the front of the vector. * * #### Complexity * Constant. * * #### Iterator Validity * No changes. */ iter(): IIterator; /** * Get the value at the front of the vector. * * @returns The value at the front of the vector, or `undefined` if * the vector is empty. * * #### Complexity * Constant. * * #### Iterator Validity * No changes. */ readonly front: T; /** * Get the value at the back of the vector. * * @returns The value at the back of the vector, or `undefined` if * the vector is empty. * * #### Complexity * Constant. * * #### Iterator Validity * No changes. */ readonly back: T; /** * Get the value at the specified index. * * @param index - The positive integer index of interest. * * @returns The value at the specified index. * * #### Undefined Behavior * An `index` which is non-integral or out of range. */ at(index: number): T; /** * Set the value at the specified index. * * @param index - The positive integer index of interest. * * @param value - The value to set at the specified index. * * #### Complexity * Constant. * * #### Iterator Validity * No changes. * * #### Undefined Behavior * An `index` which is non-integral or out of range. */ set(index: number, value: T): void; /** * Add a value to the back of the vector. * * @param value - The value to add to the back of the vector. * * @returns The new length of the vector. * * #### Complexity * Constant. * * #### Iterator Validity * No changes. */ pushBack(value: T): number; /** * Remove and return the value at the back of the vector. * * @returns The value at the back of the vector, or `undefined` if * the vector is empty. * * #### Complexity * Constant. * * #### Iterator Validity * Iterators pointing at the removed value are invalidated. */ popBack(): T; /** * Insert a value into the vector at a specific index. * * @param index - The index at which to insert the value. * * @param value - The value to set at the specified index. * * @returns The new length of the vector. * * #### Complexity * Linear. * * #### Iterator Validity * No changes. * * #### Notes * The `index` will be clamped to the bounds of the vector. * * #### Undefined Behavior * An `index` which is non-integral. */ insert(index: number, value: T): number; /** * Remove the first occurrence of a value from the vector. * * @param value - The value of interest. * * @returns The index of the removed value, or `-1` if the value * is not contained in the vector. * * #### Complexity * Linear. * * #### Iterator Validity * Iterators pointing at the removed value and beyond are invalidated. */ remove(value: T): number; /** * Remove and return the value at a specific index. * * @param index - The index of the value of interest. * * @returns The value at the specified index, or `undefined` if the * index is out of range. * * #### Complexity * Constant. * * #### Iterator Validity * Iterators pointing at the removed value and beyond are invalidated. * * #### Undefined Behavior * An `index` which is non-integral. */ removeAt(index: number): T; /** * Remove all values from the vector. * * #### Complexity * Linear. * * #### Iterator Validity * All current iterators are invalidated. */ clear(): void; /** * Move a value from one index to another. * * @parm fromIndex - The index of the element to move. * * @param toIndex - The index to move the element to. * * #### Complexity * Constant. * * #### Iterator Validity * Iterators pointing at the lesser of the `fromIndex` and the `toIndex` * and beyond are invalidated. * * #### Undefined Behavior * A `fromIndex` or a `toIndex` which is non-integral. */ move(fromIndex: number, toIndex: number): void; /** * Push a set of values to the back of the vector. * * @param values - An iterable or array-like set of values to add. * * @returns The new length of the vector. * * #### Complexity * Linear. * * #### Iterator Validity * No changes. */ pushAll(values: IterableOrArrayLike): number; /** * Insert a set of items into the vector at the specified index. * * @param index - The index at which to insert the values. * * @param values - The values to insert at the specified index. * * @returns The new length of the vector. * * #### Complexity. * Linear. * * #### Iterator Validity * No changes. * * #### Notes * The `index` will be clamped to the bounds of the vector. * * #### Undefined Behavior. * An `index` which is non-integral. */ insertAll(index: number, values: IterableOrArrayLike): number; /** * Remove a range of items from the vector. * * @param startIndex - The start index of the range to remove (inclusive). * * @param endIndex - The end index of the range to remove (exclusive). * * @returns The new length of the vector. * * #### Complexity * Linear. * * #### Iterator Validity * Iterators pointing to the first removed value and beyond are invalid. * * #### Undefined Behavior * A `startIndex` or `endIndex` which is non-integral. */ removeRange(startIndex: number, endIndex: number): number; } /** * A concrete implementation of [[IObservableVector]]. */ export declare class ObservableVector extends Vector implements IObservableVector { /** * Construct a new observable map. */ constructor(options?: ObservableVector.IOptions); /** * A signal emitted when the vector has changed. */ readonly changed: ISignal>; /** * Test whether the vector has been disposed. */ readonly isDisposed: boolean; /** * Dispose of the resources held by the vector. */ dispose(): void; /** * Set the value at the specified index. * * @param index - The positive integer index of interest. * * @param value - The value to set at the specified index. * * #### Complexity * Constant. * * #### Iterator Validity * No changes. * * #### Undefined Behavior * An `index` which is non-integral or out of range. */ set(index: number, value: T): void; /** * Add a value to the back of the vector. * * @param value - The value to add to the back of the vector. * * @returns The new length of the vector. * * #### Complexity * Constant. * * #### Iterator Validity * No changes. */ pushBack(value: T): number; /** * Remove and return the value at the back of the vector. * * @returns The value at the back of the vector, or `undefined` if * the vector is empty. * * #### Complexity * Constant. * * #### Iterator Validity * Iterators pointing at the removed value are invalidated. */ popBack(): T; /** * Insert a value into the vector at a specific index. * * @param index - The index at which to insert the value. * * @param value - The value to set at the specified index. * * @returns The new length of the vector. * * #### Complexity * Linear. * * #### Iterator Validity * No changes. * * #### Notes * The `index` will be clamped to the bounds of the vector. * * #### Undefined Behavior * An `index` which is non-integral. */ insert(index: number, value: T): number; /** * Remove the first occurrence of a value from the vector. * * @param value - The value of interest. * * @returns The index of the removed value, or `-1` if the value * is not contained in the vector. * * #### Complexity * Linear. * * #### Iterator Validity * Iterators pointing at the removed value and beyond are invalidated. */ remove(value: T): number; /** * Remove and return the value at a specific index. * * @param index - The index of the value of interest. * * @returns The value at the specified index, or `undefined` if the * index is out of range. * * #### Complexity * Constant. * * #### Iterator Validity * Iterators pointing at the removed value and beyond are invalidated. * * #### Undefined Behavior * An `index` which is non-integral. */ removeAt(index: number): T; /** * Remove all values from the vector. * * #### Complexity * Linear. * * #### Iterator Validity * All current iterators are invalidated. */ clear(): void; /** * Move a value from one index to another. * * @parm fromIndex - The index of the element to move. * * @param toIndex - The index to move the element to. * * #### Complexity * Constant. * * #### Iterator Validity * Iterators pointing at the lesser of the `fromIndex` and the `toIndex` * and beyond are invalidated. * * #### Undefined Behavior * A `fromIndex` or a `toIndex` which is non-integral. */ move(fromIndex: number, toIndex: number): void; /** * Push a set of values to the back of the vector. * * @param values - An iterable or array-like set of values to add. * * @returns The new length of the vector. * * #### Complexity * Linear. * * #### Iterator Validity * No changes. */ pushAll(values: IterableOrArrayLike): number; /** * Insert a set of items into the vector at the specified index. * * @param index - The index at which to insert the values. * * @param values - The values to insert at the specified index. * * @returns The new length of the vector. * * #### Complexity. * Linear. * * #### Iterator Validity * No changes. * * #### Notes * The `index` will be clamped to the bounds of the vector. * * #### Undefined Behavior. * An `index` which is non-integral. */ insertAll(index: number, values: IterableOrArrayLike): number; /** * Remove a range of items from the vector. * * @param startIndex - The start index of the range to remove (inclusive). * * @param endIndex - The end index of the range to remove (exclusive). * * @returns The new length of the vector. * * #### Complexity * Linear. * * #### Iterator Validity * Iterators pointing to the first removed value and beyond are invalid. * * #### Undefined Behavior * A `startIndex` or `endIndex` which is non-integral. */ removeRange(startIndex: number, endIndex: number): number; private _isDisposed; private _itemCmp; private _changed; } /** * The namespace for `ObservableVector` class statics. */ export declare namespace ObservableVector { /** * The options used to initialize an observable map. */ interface IOptions { /** * An optional intial set of values. */ values?: T[]; /** * The item comparison function for change detection on `set`. * * If not given, strict `===` equality will be used. */ itemCmp?: (first: T, second: T) => boolean; } /** * The change types which occur on an observable vector. */ type ChangeType = 'add' | 'move' | 'remove' | 'set'; /** * The changed args object which is emitted by an observable vector. */ interface IChangedArgs { /** * The type of change undergone by the vector. */ type: ChangeType; /** * The new index associated with the change. */ newIndex: number; /** * The new values associated with the change. * * #### Notes * The values will be contiguous starting at the `newIndex`. */ newValues: T[]; /** * The old index associated with the change. */ oldIndex: number; /** * The old values associated with the change. * * #### Notes * The values will be contiguous starting at the `oldIndex`. */ oldValues: T[]; } }