import { ReactiveObject } from "./reactive-object"; import { Observable } from "rxjs/Rx"; import { CollectionChangedEventArgs } from "./events/collection-changed-event-args"; import { PropertyChangedEventArgs } from "./events/property-changed-event-args"; /** * Defines a class that provides powerful observable functionality * around a traditional array. */ export declare class ReactiveArray extends ReactiveObject { private _array; private _changed; /** * Creates a new ReactiveArray. * Optionally copies the values from the given array. * @param arr The array that should be used to create this array. */ constructor(arr?: T[] | ReactiveArray); private emitArrayChanges(addStartIndex, addedItems, deleteStartIndex, deletedItems); /** * Gets an observable that resolves whenever the array changes. * Note that changes are only observed for the ReactiveArray itself. * This means that only operations such as push(), pop(), splice(), shift(), and unshift() * emit changed() events. */ readonly changed: Observable>; /** * Gets an observable that resolves whenever a new item is added to the array. */ readonly itemsAdded: Observable>; /** * Gets an observable that resolves whenever a item is removed from the array. */ readonly itemsRemoved: Observable>; /** * Gets the item at the given index in the array. */ getItem(index: number): T; /** * Sets the value of the given index to the given item in the array. */ setItem(index: number, value: T): void; /** * Adds each of the given arguments to the beginning of this array. * @param values The values that should be added to the array. */ unshift(...values: T[]): void; /** * Removes a single item from the beginning of this array and returns it. */ shift(): T; /** * Adds each of the given arguments to the end of this array. * @param values The values that should be added to the array. */ push(...values: T[]): void; /** * Removes a single item from the end of this array and returns it. */ pop(): T; /** * Gets the number of items that are currently stored in the array. */ readonly length: number; /** * Creates a new ReactiveArray from the given subset of this array. * @param start If specified, marks the index of the first element that should be included in the new array. * @param end If specified, marks the index of the last element that should be included in the new array. */ slice(start?: number, end?: number): ReactiveArray; /** * Changes the contents of this array by removing a specified number of elements * at the given index, and optionally inserting any number of items in their place. * @param start The index that the array should be changed at. * @param deleteCount The number of items that should be deleted from the start index. * @param items The items that should be inserted at the start index. */ splice(start: number, deleteCount: number, ...items: T[]): ReactiveArray; /** * Sorts the array, optionally using the given comparator to determin the sort order of each element, and returns * a new ReactiveArray that represents the reorded items. * @param compareFunction If specified, determines the relative sort order between two given elements in the array. * If omitted, elements are sorted by the sort order of the numerical representation of their toString() unicode code points. */ sort(compareFunction?: (first: T, second: T) => number): ReactiveArray; /** * Produces a new ReactiveArray from this array where each element from this array has been transformed by the given callback function. * elements. * @param callback A function that, given an element, index, and the containing array, produces a new value for the element at that index. * @param thisArg Optional. The value that should be used as `this` when executing the given callback function. */ map(callback: (currentValue: T, index?: number, array?: ReactiveArray) => TNew, thisArg?: any): ReactiveArray; /** * Produces a new ReactiveArray from this array where only elements that passed the given predicate callback function from this array * are included in the new array. * @param callback A function that, given an element, index, and the containing array, produces `true` if the value should be included * in the new array, or `false` if it should be omitted. * @param thisArg Optional. The value that should be used as `this` when executing the given callback function. */ filter(callback: (value: T, index?: number, array?: ReactiveArray) => boolean, thisArg?: any): ReactiveArray; /** * Returns the index of the first element in this array that equals the given value. * Returns -1 if no element in the array equals the given value. * @param value The value that the array should be searched for. * @param fromIndex Optional. The lower-bound index that the search should begin from. */ indexOf(value: T, fromIndex?: number): number; /** * Returns the index of the last element in this array that equals the given value. * Returns -1 if no element in the array equals the given value. * @param value The value that the array should be searched for. * @param fromIndex The upper-bound index that the search should begin from. */ lastIndexOf(value: T, fromIndex?: number): number; /** * Iterates over each of the elements in this array and executes the given callback function on each of them. * @param callback A function that, given an element, index, and the containing array, performs an operation. * @param thisArg Optional. The value that should be used as `this` when executing the given callback function. */ forEach(callback: (value: T, index?: number, array?: ReactiveArray) => void, thisArg?: any): void; /** * Applies the given accumulator callback function across each of the elements in the array and returns the final value from the chain. * @param callback A function that, given two values, index and the containing array, produces a value. * @param initialValue Optional. The value that should be used as the `previousValue` in the given callback function for the first index. */ reduce(callback: (previousValue: T, currentValue: T, currentIndex: number, arr: ReactiveArray) => T, initialValue?: T): T; /** * Determines whether every value in the array passes the given predicate callback function. * @param callback A function that, given an element, index, and the containing array, produces a predicate value. * @param thisArg Optional. The value that should be used as `this` when executing the given callback function. */ every(callback: (currentValue: T, index?: number, array?: ReactiveArray) => boolean, thisArg?: any): boolean; /** * Determines whether at least one value in the array passes the given predicate callback function. * @param callback A function that, given an element, index, and the containing array, produces a predicate value. * @param thisArg Optional. The value that should be used as `this` when executing the given callback function. */ some(callback: (currentValue: T, index?: number, array?: ReactiveArray) => boolean, thisArg?: any): boolean; /** * Returns the first element in the array that passes the given predicate callback function. * If no element passes the callback, undefined is returned. * @param callback A function that, given an element, index, and the containing array, produces a predicate value. * @param thisArg Optional. The value that should be used as `this` when executing the given callback function. */ find(callback: (element: T, index?: number, array?: ReactiveArray) => boolean, thisArg?: any): T; /** * Returns the index of the first element in the array that passes the given predicate callback function. * If no element passes the callback, -1 is returned. * @param callback A function that, given an element, index, and the containing array, produces a predicate value. * @param thisArg Optional. The value that should be used as `this` when executing the given callback function. */ findIndex(callback: (element: T, index?: number, array?: ReactiveArray) => boolean, thisArg?: any): number; /** * Gets a cold observable that resolves with the PropertyChangedEventArgs of any item in the array when * the specified property changes any item. * @param property The name of the property that should be watched on each item in the array. */ whenAnyItem(property: (((vm: T) => TProp) | string)): Observable>; /** * Gets a cold observable that resolves when any property on any item in the array * changes. */ whenAnyItemProperty(): Observable>; /** * Gets a cold observable that resolves with the specified property value of any item in the array when * the property changes on any item. * @param property The name of the property that should be watched on each item in the array. */ whenAnyItemValue(property: (((vm: T) => TProp) | string)): Observable; /** * Gets a cold observable that resolves with the values from the observables from the specified property * on all of the items in the array. * @param properth The name of the property that should be watched. */ whenAnyItemObservable(property: (((vm: T) => Observable) | string)): Observable; /** * Gets a new builder object that can be used to create a child array from this array that tracks the changes made to this array. */ readonly derived: DerivedReactiveArrayBuilder; /** * Gets a new builder object that can be used to create an observable that calculates a single value * from this array. */ readonly computed: ComputedReactiveArrayBuilder; /** * Creates a new ReactiveArray from the given array. * @param arr The array that should be converted into a ReactiveArray. */ static from(arr: T[] | ReactiveArray): ReactiveArray; /** * Creates a new ReactiveArray from the given arguments. * @param values The values that should be in the array. */ static of(...values: T[]): ReactiveArray; /** * Converts this ReactiveArray into a traditional JavaScript array object. */ toArray(): T[]; /** * Converts this reactive array into an observable stream that contains * the snapshots of this array's values. */ toObservable(): Observable; /** * Gets the JSON object that represents the values in this array. */ toJSON(): any; /** * Gets the string representation of this ReactiveArray. */ toString(): string; } /** * Defines a class that acts as a builder for derived reactive arrays. */ export declare class DerivedReactiveArrayBuilder { private parent; private eventSteps; private arraySteps; private triggers; constructor(parent: ReactiveArray); private addEvent(transform); private addArray(transform); /** * Instructs the child reactive array to trigger updates when one of the given properties on the parent array * has changed. * @param properties The list of properties that should be watched on the items in the parent array. */ whenAnyItem(...properties: (string | ((obj: T) => TProp))[]): DerivedReactiveArrayBuilder; /** * Instructs the child reactive array to trigger updates when any property on one of the items from the parent * array has changed. */ whenAnyItemProperty(): DerivedReactiveArrayBuilder; /** * Filters elements from the parent array so that only elements that pass the given * predicate function will appear in the child array. * @param predicate A function that, given an element, index, and containing array, returns whether the value should be piped to the child array. */ filter(predicate: (value: T, index: number, arr: T[]) => boolean): DerivedReactiveArrayBuilder; /** * Transforms elements from the parent array into the child array. * @param transform A function that, given an element, index, and containing array, returns the value that should be piped to the child array. */ map(transform: (value: T, index: number, arr: T[]) => TNew): DerivedReactiveArrayBuilder; /** * Sorts the child array whenever a change is piped from the parent array into it. * @param compareFunction Optional. A function that, given two values, returns the relative sort order of those two values. * If omitted, the values will be sorted according to the default Array.prototype.sort() behavior. */ sort(compareFunction?: (first: T, second: T) => number): DerivedReactiveArrayBuilder; /** * Creates a new child array according to the rules previously defined with this builder object and returns it. * Currently, derived reactive arrays do not support direct modification via push(), pop(), splice(), etc. */ build(): ReactiveArray; } /** * Defines a class that acts as a builder for computed observables that are based on an array. */ export declare class ComputedReactiveArrayBuilder { private parent; constructor(parent: ReactiveArray); /** * Applies the given accumulator callback function whenever a change is observed in the array * and pipes the resulting values via the returned observable object. * @param callback A function that, given two values, index and the containing array, produces a value. * @param initialValue Optional. The value that should be used as the `previousValue` in the given callback function for the first index. */ reduce(callback: (previousValue: T, currentValue: T, currentIndex: number, arr: ReactiveArray) => T, initialValue?: T): Observable; /** * Determines whether every element in the array passes the given predicate function whenever a change is observed in the array * and pipes the resulting values via the the returned observable object. * @param callback A function that, given an element, index, and the containing array, produces a predicate value. * @param thisArg Optional. The value that should be used as `this` when executing the given callback function. */ every(callback: (currentValue: T, index?: number, array?: ReactiveArray) => boolean, thisArg?: any): Observable; /** * Determines whether at least one value in the array passes the given predicate callback function whenever a change is observed in the array * and pipes the resulting values via the returned observable object. * @param callback A function that, given an element, index, and the containing array, produces a predicate value. * @param thisArg Optional. The value that should be used as `this` when executing the given callback function. */ some(callback: (currentValue: T, index?: number, array?: ReactiveArray) => boolean, thisArg?: any): Observable; /** * Returns the first element in the array that passes the given predicate callback function whenever a change is observed in the array * and pipes the resulting values via the returned observable object. * If no element passes the callback, undefined is returned. * @param callback A function that, given an element, index, and the containing array, produces a predicate value. * @param thisArg Optional. The value that should be used as `this` when executing the given callback function. */ find(callback: (element: T, index?: number, array?: ReactiveArray) => boolean, thisArg?: any): Observable; /** * Returns the index of the first element in the array that passes the given predicate callback function whenever a change is observed * in the array and pipes the resulting values via the returned observable object. * If no element passes the callback, -1 is returned. * @param callback A function that, given an element, index, and the containing array, produces a predicate value. * @param thisArg Optional. The value that should be used as `this` when executing the given callback function. */ findIndex(callback: (element: T, index?: number, array?: ReactiveArray) => boolean, thisArg?: any): Observable; }