chore: format

This commit is contained in:
Nathan Walker
2020-07-05 14:57:06 -07:00
parent 8f2900ad0b
commit da3c0b973d
379 changed files with 71587 additions and 54582 deletions

View File

@@ -2,36 +2,36 @@ import { Observable, EventData } from "../observable";
import * as types from "../../utils/types";
export class ChangeType {
static Add = "add";
static Delete = "delete";
static Update = "update";
static Splice = "splice";
static Change = "change";
static Add = "add";
static Delete = "delete";
static Update = "update";
static Splice = "splice";
static Change = "change";
}
/**
* Event args for "changed" event.
*/
export interface ChangedData<T> extends EventData {
/**
* Change type.
*/
action: string;
/**
* Change type.
*/
action: string;
/**
* Start index.
*/
index: number;
/**
* Start index.
*/
index: number;
/**
* Removed items.
*/
removed: Array<T>;
/**
* Removed items.
*/
removed: Array<T>;
/**
* Number of added items.
*/
addedCount: number;
/**
* Number of added items.
*/
addedCount: number;
}
const CHANGE = "change";
@@ -40,344 +40,395 @@ const CHANGE = "change";
* Advanced array like class used when you want to be notified when a change occurs.
*/
export class ObservableArray<T> extends Observable {
/**
* String value used when hooking to change event.
*/
public static changeEvent = CHANGE;
/**
* String value used when hooking to change event.
*/
public static changeEvent = CHANGE;
private _array: Array<any>;
private _addArgs: ChangedData<T>;
private _deleteArgs: ChangedData<T>;
private _array: Array<any>;
private _addArgs: ChangedData<T>;
private _deleteArgs: ChangedData<T>;
/**
* Create ObservableArray<T> with specified length or from source Array<T>.
*/
constructor(_args?: number | T[]) {
super();
/**
* Create ObservableArray<T> with specified length or from source Array<T>.
*/
constructor(_args?: number | T[]) {
super();
if (arguments.length === 1 && Array.isArray(arguments[0])) {
this._array = arguments[0].slice();
} else {
this._array = Array.apply(null, arguments);
}
if (arguments.length === 1 && Array.isArray(arguments[0])) {
this._array = arguments[0].slice();
}
else {
this._array = Array.apply(null, arguments);
}
this._addArgs = {
eventName: CHANGE,
object: this,
action: ChangeType.Add,
index: null,
removed: new Array(),
addedCount: 1,
};
this._addArgs = {
eventName: CHANGE, object: this,
action: ChangeType.Add,
index: null,
removed: new Array(),
addedCount: 1
};
this._deleteArgs = {
eventName: CHANGE,
object: this,
action: ChangeType.Delete,
index: null,
removed: null,
addedCount: 0,
};
}
this._deleteArgs = {
eventName: CHANGE, object: this,
action: ChangeType.Delete,
index: null,
removed: null,
addedCount: 0
};
}
/**
* Returns item at specified index.
*/
getItem(index: number): T {
return this._array[index];
}
/**
* Returns item at specified index.
*/
getItem(index: number): T {
return this._array[index];
}
/**
* Sets item at specified index.
*/
setItem(index: number, value: T) {
let oldValue = this._array[index];
this._array[index] = value;
/**
* Sets item at specified index.
*/
setItem(index: number, value: T) {
let oldValue = this._array[index];
this._array[index] = value;
this.notify(<ChangedData<T>>{
eventName: CHANGE,
object: this,
action: ChangeType.Update,
index: index,
removed: [oldValue],
addedCount: 1,
});
}
this.notify(<ChangedData<T>>{
eventName: CHANGE, object: this,
action: ChangeType.Update,
index: index,
removed: [oldValue],
addedCount: 1
});
}
/**
* Gets or sets the length of the array. This is a number one higher than the highest element defined in an array.
*/
get length(): number {
return this._array.length;
}
/**
* Gets or sets the length of the array. This is a number one higher than the highest element defined in an array.
*/
get length(): number {
return this._array.length;
}
set length(value: number) {
if (
types.isNumber(value) &&
this._array &&
this._array.length !== value
) {
this.splice(value, this._array.length - value);
}
}
set length(value: number) {
if (types.isNumber(value) && this._array && this._array.length !== value) {
this.splice(value, this._array.length - value);
}
}
/**
* Returns a string representation of an array.
*/
toString(): string {
return this._array.toString();
}
/**
* Returns a string representation of an array.
*/
toString(): string {
return this._array.toString();
}
toLocaleString(): string {
return this._array.toLocaleString();
}
toLocaleString(): string {
return this._array.toLocaleString();
}
/**
* Combines two or more arrays.
* @param items Additional items to add to the end of array1.
*/
concat(_args?: any): T[] {
this._addArgs.index = this._array.length;
const result = this._array.concat.apply(this._array, arguments);
/**
* Combines two or more arrays.
* @param items Additional items to add to the end of array1.
*/
concat(_args?: any): T[] {
this._addArgs.index = this._array.length;
const result = this._array.concat.apply(this._array, arguments);
return result;
}
return result;
}
/**
* Adds all the elements of an array separated by the specified separator string.
* @param separator A string used to separate one element of an array from the next in the resulting String. If omitted, the array elements are separated with a comma.
*/
join(separator?: string): string {
return this._array.join(separator);
}
/**
* Adds all the elements of an array separated by the specified separator string.
* @param separator A string used to separate one element of an array from the next in the resulting String. If omitted, the array elements are separated with a comma.
*/
join(separator?: string): string {
return this._array.join(separator);
}
/**
* Removes the last element from an array and returns it.
*/
pop(): T {
this._deleteArgs.index = this._array.length - 1;
/**
* Removes the last element from an array and returns it.
*/
pop(): T {
this._deleteArgs.index = this._array.length - 1;
const result = this._array.pop();
const result = this._array.pop();
this._deleteArgs.removed = [result];
this._deleteArgs.removed = [result];
this.notify(this._deleteArgs);
this._notifyLengthChange();
this.notify(this._deleteArgs);
this._notifyLengthChange();
return result;
}
return result;
}
/**
* Appends new elements to an array, and returns the new length of the array.
* @param item New element of the Array.
*/
push(_args?: any): number {
this._addArgs.index = this._array.length;
/**
* Appends new elements to an array, and returns the new length of the array.
* @param item New element of the Array.
*/
push(_args?: any): number {
this._addArgs.index = this._array.length;
if (arguments.length === 1 && Array.isArray(arguments[0])) {
const source = <Array<T>>arguments[0];
if (arguments.length === 1 && Array.isArray(arguments[0])) {
const source = <Array<T>>arguments[0];
for (let i = 0, l = source.length; i < l; i++) {
this._array.push(source[i]);
}
} else {
this._array.push.apply(this._array, arguments);
}
for (let i = 0, l = source.length; i < l; i++) {
this._array.push(source[i]);
}
}
else {
this._array.push.apply(this._array, arguments);
}
this._addArgs.addedCount = this._array.length - this._addArgs.index;
this._addArgs.addedCount = this._array.length - this._addArgs.index;
this.notify(this._addArgs);
this._notifyLengthChange();
this.notify(this._addArgs);
this._notifyLengthChange();
return this._array.length;
}
return this._array.length;
}
_notifyLengthChange() {
const lengthChangedData = this._createPropertyChangeData(
"length",
this._array.length
);
this.notify(lengthChangedData);
}
_notifyLengthChange() {
const lengthChangedData = this._createPropertyChangeData("length", this._array.length);
this.notify(lengthChangedData);
}
/**
* Reverses the elements in an Array.
*/
reverse(): T[] {
return this._array.reverse();
}
/**
* Reverses the elements in an Array.
*/
reverse(): T[] {
return this._array.reverse();
}
/**
* Removes the first element from an array and returns it.
*/
shift(): T {
const result = this._array.shift();
/**
* Removes the first element from an array and returns it.
*/
shift(): T {
const result = this._array.shift();
this._deleteArgs.index = 0;
this._deleteArgs.removed = [result];
this._deleteArgs.index = 0;
this._deleteArgs.removed = [result];
this.notify(this._deleteArgs);
this._notifyLengthChange();
this.notify(this._deleteArgs);
this._notifyLengthChange();
return result;
}
return result;
}
/**
* Returns a section of an array.
* @param start The beginning of the specified portion of the array.
* @param end The end of the specified portion of the array.
*/
slice(start?: number, end?: number): T[] {
return this._array.slice(start, end);
}
/**
* Returns a section of an array.
* @param start The beginning of the specified portion of the array.
* @param end The end of the specified portion of the array.
*/
slice(start?: number, end?: number): T[] {
return this._array.slice(start, end);
}
/**
* Sorts an array.
* @param compareFn The name of the function used to determine the order of the elements. If omitted, the elements are sorted in ascending, ASCII character order.
*/
sort(compareFn?: (a: T, b: T) => number): T[] {
return this._array.sort(compareFn);
}
/**
* Sorts an array.
* @param compareFn The name of the function used to determine the order of the elements. If omitted, the elements are sorted in ascending, ASCII character order.
*/
sort(compareFn?: (a: T, b: T) => number): T[] {
return this._array.sort(compareFn);
}
/**
* Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements.
* @param start The zero-based location in the array from which to start removing elements.
* @param deleteCount The number of elements to remove.
* @param items Elements to insert into the array in place of the deleted elements.
*/
splice(start: number, deleteCount?: number): T[] {
const length = this._array.length;
const result = this._array.splice.apply(this._array, arguments);
/**
* Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements.
* @param start The zero-based location in the array from which to start removing elements.
* @param deleteCount The number of elements to remove.
* @param items Elements to insert into the array in place of the deleted elements.
*/
splice(start: number, deleteCount?: number): T[] {
const length = this._array.length;
const result = this._array.splice.apply(this._array, arguments);
this.notify(<ChangedData<T>>{
eventName: CHANGE,
object: this,
action: ChangeType.Splice,
index: start,
removed: result,
addedCount: this._array.length + result.length - length,
});
if (this._array.length !== length) {
this._notifyLengthChange();
}
this.notify(<ChangedData<T>>{
eventName: CHANGE, object: this,
action: ChangeType.Splice,
index: start,
removed: result,
addedCount: this._array.length + result.length - length
});
if (this._array.length !== length) {
this._notifyLengthChange();
}
return result;
}
return result;
}
/**
* Inserts new elements at the start of an array.
* @param items Elements to insert at the start of the Array.
*/
unshift(): number {
const length = this._array.length;
const result = this._array.unshift.apply(this._array, arguments);
/**
* Inserts new elements at the start of an array.
* @param items Elements to insert at the start of the Array.
*/
unshift(): number {
const length = this._array.length;
const result = this._array.unshift.apply(this._array, arguments);
this._addArgs.index = 0;
this._addArgs.addedCount = result - length;
this._addArgs.index = 0;
this._addArgs.addedCount = result - length;
this.notify(this._addArgs);
this._notifyLengthChange();
this.notify(this._addArgs);
this._notifyLengthChange();
return result;
}
return result;
}
/**
* Returns the index of the first occurrence of a value in an array.
* @param searchElement The value to locate in the array.
* @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the search starts at index 0.
*/
indexOf(searchElement: T, fromIndex?: number): number {
const index = fromIndex ? fromIndex : 0;
for (let i = index, l = this._array.length; i < l; i++) {
if (this._array[i] === searchElement) {
return i;
}
}
/**
* Returns the index of the first occurrence of a value in an array.
* @param searchElement The value to locate in the array.
* @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the search starts at index 0.
*/
indexOf(searchElement: T, fromIndex?: number): number {
const index = fromIndex ? fromIndex : 0;
for (let i = index, l = this._array.length; i < l; i++) {
if (this._array[i] === searchElement) {
return i;
}
}
return -1;
}
return -1;
}
/**
* Returns the index of the last occurrence of a specified value in an array.
* @param searchElement The value to locate in the array.
* @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the search starts at the last index in the array.
*/
lastIndexOf(searchElement: T, fromIndex?: number): number {
const index = fromIndex ? fromIndex : this._array.length - 1;
/**
* Returns the index of the last occurrence of a specified value in an array.
* @param searchElement The value to locate in the array.
* @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the search starts at the last index in the array.
*/
lastIndexOf(searchElement: T, fromIndex?: number): number {
const index = fromIndex ? fromIndex : this._array.length - 1;
for (let i = index; i >= 0; i--) {
if (this._array[i] === searchElement) {
return i;
}
}
for (let i = index; i >= 0; i--) {
if (this._array[i] === searchElement) {
return i;
}
}
return -1;
}
return -1;
}
/**
* Determines whether all the members of an array satisfy the specified test.
* @param callbackfn A function that accepts up to three arguments. The every method calls the callbackfn function for each element in array1 until the callbackfn returns false, or until the end of the array.
* @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
*/
every(
callbackfn: (value: T, index: number, array: T[]) => boolean,
thisArg?: any
): boolean {
return this._array.every(callbackfn, thisArg);
}
/**
* Determines whether all the members of an array satisfy the specified test.
* @param callbackfn A function that accepts up to three arguments. The every method calls the callbackfn function for each element in array1 until the callbackfn returns false, or until the end of the array.
* @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
*/
every(callbackfn: (value: T, index: number, array: T[]) => boolean, thisArg?: any): boolean {
return this._array.every(callbackfn, thisArg);
}
/**
* Determines whether the specified callback function returns true for any element of an array.
* @param callbackfn A function that accepts up to three arguments. The some method calls the callbackfn function for each element in array1 until the callbackfn returns true, or until the end of the array.
* @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
*/
some(
callbackfn: (value: T, index: number, array: T[]) => boolean,
thisArg?: any
): boolean {
return this._array.some(callbackfn, thisArg);
}
/**
* Determines whether the specified callback function returns true for any element of an array.
* @param callbackfn A function that accepts up to three arguments. The some method calls the callbackfn function for each element in array1 until the callbackfn returns true, or until the end of the array.
* @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
*/
some(callbackfn: (value: T, index: number, array: T[]) => boolean, thisArg?: any): boolean {
return this._array.some(callbackfn, thisArg);
}
/**
* Performs the specified action for each element in an array.
* @param callbackfn A function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the array.
* @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
*/
forEach(
callbackfn: (value: T, index: number, array: T[]) => void,
thisArg?: any
): void {
this._array.forEach(callbackfn, thisArg);
}
/**
* Performs the specified action for each element in an array.
* @param callbackfn A function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the array.
* @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
*/
forEach(callbackfn: (value: T, index: number, array: T[]) => void, thisArg?: any): void {
this._array.forEach(callbackfn, thisArg);
}
/**
* Calls a defined callback function on each element of an array, and returns an array that contains the results.
* @param callbackfn A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array.
* @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
*/
map<U>(
callbackfn: (value: T, index: number, array: T[]) => U,
thisArg?: any
): U[] {
return this._array.map(callbackfn, thisArg);
}
/**
* Calls a defined callback function on each element of an array, and returns an array that contains the results.
* @param callbackfn A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array.
* @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
*/
map<U>(callbackfn: (value: T, index: number, array: T[]) => U, thisArg?: any): U[] {
return this._array.map(callbackfn, thisArg);
}
/**
* Returns the elements of an array that meet the condition specified in a callback function.
* @param callbackfn A function that accepts up to three arguments. The filter method calls the callbackfn function one time for each element in the array.
* @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
*/
filter(
callbackfn: (value: T, index: number, array: T[]) => boolean,
thisArg?: any
): T[] {
return this._array.filter(callbackfn, thisArg);
}
/**
* Returns the elements of an array that meet the condition specified in a callback function.
* @param callbackfn A function that accepts up to three arguments. The filter method calls the callbackfn function one time for each element in the array.
* @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
*/
filter(callbackfn: (value: T, index: number, array: T[]) => boolean, thisArg?: any): T[] {
return this._array.filter(callbackfn, thisArg);
}
/**
* Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
* @param callbackfn A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array.
* @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.
*/
reduce(
callbackfn: (
previousValue: T,
currentValue: T,
currentIndex: number,
array: T[]
) => T,
initialValue?: T
): T {
return initialValue !== undefined
? this._array.reduce(callbackfn, initialValue)
: this._array.reduce(callbackfn);
}
/**
* Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
* @param callbackfn A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array.
* @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.
*/
reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue?: T): T {
return initialValue !== undefined ? this._array.reduce(callbackfn, initialValue) : this._array.reduce(callbackfn);
}
/**
* Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
* @param callbackfn A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array.
* @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.
*/
reduceRight(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: T[]) => T, initialValue?: T): T {
return initialValue !== undefined ? this._array.reduceRight(callbackfn, initialValue) : this._array.reduceRight(callbackfn);
}
/**
* Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
* @param callbackfn A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array.
* @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.
*/
reduceRight(
callbackfn: (
previousValue: T,
currentValue: T,
currentIndex: number,
array: T[]
) => T,
initialValue?: T
): T {
return initialValue !== undefined
? this._array.reduceRight(callbackfn, initialValue)
: this._array.reduceRight(callbackfn);
}
}
export interface ObservableArray<T> {
/**
* A basic method signature to hook an event listener (shortcut alias to the addEventListener method).
* @param eventNames - String corresponding to events (e.g. "propertyChange"). Optionally could be used more events separated by `,` (e.g. "propertyChange", "change").
* @param callback - Callback function which will be executed when event is raised.
* @param thisArg - An optional parameter which will be used as `this` context for callback execution.
*/
on(eventNames: string, callback: (data: EventData) => void, thisArg?: any): void;
/**
* A basic method signature to hook an event listener (shortcut alias to the addEventListener method).
* @param eventNames - String corresponding to events (e.g. "propertyChange"). Optionally could be used more events separated by `,` (e.g. "propertyChange", "change").
* @param callback - Callback function which will be executed when event is raised.
* @param thisArg - An optional parameter which will be used as `this` context for callback execution.
*/
on(
eventNames: string,
callback: (data: EventData) => void,
thisArg?: any
): void;
on(event: "change", callback: (args: ChangedData<T>) => void, thisArg?: any): void;
on(
event: "change",
callback: (args: ChangedData<T>) => void,
thisArg?: any
): void;
}

View File

@@ -2,32 +2,32 @@
* Base event data.
*/
export interface EventData {
/**
* The name of the event.
*/
eventName: string;
/**
* The Observable instance that has raised the event.
*/
object: Observable;
/**
* The name of the event.
*/
eventName: string;
/**
* The Observable instance that has raised the event.
*/
object: Observable;
}
/**
* Data for the "propertyChange" event.
*/
export interface PropertyChangeData extends EventData {
/**
* The name of the property that has changed.
*/
propertyName: string;
/**
* The new value of the property.
*/
value: any;
/**
* The previous value of the property.
*/
oldValue?: any;
/**
* The name of the property that has changed.
*/
propertyName: string;
/**
* The new value of the property.
*/
value: any;
/**
* The previous value of the property.
*/
oldValue?: any;
}
/**
@@ -36,140 +36,154 @@ export interface PropertyChangeData extends EventData {
* By wrapping object into a WrappedValue instance `same object restriction` will be passed.
*/
export class WrappedValue {
/**
* Property which holds the real value.
*/
wrapped: any;
/**
* Property which holds the real value.
*/
wrapped: any;
/**
* Creates an instance of WrappedValue object.
* @param value - the real value which should be wrapped.
*/
constructor(value: any);
/**
* Creates an instance of WrappedValue object.
* @param value - the real value which should be wrapped.
*/
constructor(value: any);
/**
* Gets the real value of previously wrappedValue.
* @param value - Value that should be unwraped. If there is no wrappedValue property of the value object then value will be returned.
*/
static unwrap(value: any): any;
/**
* Returns an instance of WrappedValue. The actual instance is get from a WrappedValues pool.
* @param value - Value that should be wrapped.
*/
static wrap(value: any): WrappedValue
/**
* Gets the real value of previously wrappedValue.
* @param value - Value that should be unwraped. If there is no wrappedValue property of the value object then value will be returned.
*/
static unwrap(value: any): any;
/**
* Returns an instance of WrappedValue. The actual instance is get from a WrappedValues pool.
* @param value - Value that should be wrapped.
*/
static wrap(value: any): WrappedValue;
}
/**
* Observable is used when you want to be notified when a change occurs. Use on/off methods to add/remove listener.
*/
export class Observable {
/**
* Please note that should you be using the `new Observable({})` constructor, it is **obsolete** since v3.0,
* and you have to migrate to the "data/observable" `fromObject({})` or the `fromObjectRecursive({})` functions.
*/
constructor();
/**
* Please note that should you be using the `new Observable({})` constructor, it is **obsolete** since v3.0,
* and you have to migrate to the "data/observable" `fromObject({})` or the `fromObjectRecursive({})` functions.
*/
constructor();
/**
* String value used when hooking to propertyChange event.
*/
public static propertyChangeEvent: string;
/**
* String value used when hooking to propertyChange event.
*/
public static propertyChangeEvent: string;
/**
* A basic method signature to hook an event listener (shortcut alias to the addEventListener method).
* @param eventNames - String corresponding to events (e.g. "propertyChange"). Optionally could be used more events separated by `,` (e.g. "propertyChange", "change").
* @param callback - Callback function which will be executed when event is raised.
* @param thisArg - An optional parameter which will be used as `this` context for callback execution.
*/
on(eventNames: string, callback: (data: EventData) => void, thisArg?: any);
/**
* A basic method signature to hook an event listener (shortcut alias to the addEventListener method).
* @param eventNames - String corresponding to events (e.g. "propertyChange"). Optionally could be used more events separated by `,` (e.g. "propertyChange", "change").
* @param callback - Callback function which will be executed when event is raised.
* @param thisArg - An optional parameter which will be used as `this` context for callback execution.
*/
on(eventNames: string, callback: (data: EventData) => void, thisArg?: any);
/**
* Raised when a propertyChange occurs.
*/
on(
event: "propertyChange",
callback: (data: EventData) => void,
thisArg?: any
);
/**
* Raised when a propertyChange occurs.
*/
on(event: "propertyChange", callback: (data: EventData) => void, thisArg?: any);
/**
* Adds one-time listener function for the event named `event`.
* @param event Name of the event to attach to.
* @param callback A function to be called when the specified event is raised.
* @param thisArg An optional parameter which when set will be used as "this" in callback method call.
*/
once(event: string, callback: (data: EventData) => void, thisArg?: any);
/**
* Adds one-time listener function for the event named `event`.
* @param event Name of the event to attach to.
* @param callback A function to be called when the specified event is raised.
* @param thisArg An optional parameter which when set will be used as "this" in callback method call.
*/
once(event: string, callback: (data: EventData) => void, thisArg?: any);
/**
* Shortcut alias to the removeEventListener method.
*/
off(eventNames: string, callback?: any, thisArg?: any);
/**
* Shortcut alias to the removeEventListener method.
*/
off(eventNames: string, callback?: any, thisArg?: any);
/**
* Adds a listener for the specified event name.
* @param eventNames Comma delimited names of the events to attach the listener to.
* @param callback A function to be called when some of the specified event(s) is raised.
* @param thisArg An optional parameter which when set will be used as "this" in callback method call.
*/
addEventListener(
eventNames: string,
callback: (data: EventData) => void,
thisArg?: any
);
/**
* Adds a listener for the specified event name.
* @param eventNames Comma delimited names of the events to attach the listener to.
* @param callback A function to be called when some of the specified event(s) is raised.
* @param thisArg An optional parameter which when set will be used as "this" in callback method call.
*/
addEventListener(eventNames: string, callback: (data: EventData) => void, thisArg?: any);
/**
* Removes listener(s) for the specified event name.
* @param eventNames Comma delimited names of the events the specified listener is associated with.
* @param callback An optional parameter pointing to a specific listener. If not defined, all listeners for the event names will be removed.
* @param thisArg An optional parameter which when set will be used to refine search of the correct callback which will be removed as event listener.
*/
removeEventListener(eventNames: string, callback?: any, thisArg?: any);
/**
* Removes listener(s) for the specified event name.
* @param eventNames Comma delimited names of the events the specified listener is associated with.
* @param callback An optional parameter pointing to a specific listener. If not defined, all listeners for the event names will be removed.
* @param thisArg An optional parameter which when set will be used to refine search of the correct callback which will be removed as event listener.
*/
removeEventListener(eventNames: string, callback?: any, thisArg?: any);
/**
* Updates the specified property with the provided value.
*/
set(name: string, value: any): void;
/**
* Updates the specified property with the provided value.
*/
set(name: string, value: any): void;
/**
* Updates the specified property with the provided value and raises a property change event and a specific change event based on the property name.
*/
setProperty(name: string, value: any): void;
/**
* Updates the specified property with the provided value and raises a property change event and a specific change event based on the property name.
*/
setProperty(name: string, value: any): void;
/**
* Gets the value of the specified property.
*/
get(name: string): any;
/**
* Gets the value of the specified property.
*/
get(name: string): any;
/**
* Notifies all the registered listeners for the event provided in the data.eventName.
* @param data The data associated with the event.
*/
notify<T extends EventData>(data: T): void;
/**
* Notifies all the registered listeners for the event provided in the data.eventName.
* @param data The data associated with the event.
*/
notify<T extends EventData>(data: T): void;
/**
* Notifies all the registered listeners for the property change event.
*/
notifyPropertyChange(
propertyName: string,
value: any,
oldValue?: any
): void;
/**
* Notifies all the registered listeners for the property change event.
*/
notifyPropertyChange(propertyName: string, value: any, oldValue?: any): void;
/**
* Checks whether a listener is registered for the specified event name.
* @param eventName The name of the event to check for.
*/
hasListeners(eventName: string): boolean;
/**
* Checks whether a listener is registered for the specified event name.
* @param eventName The name of the event to check for.
*/
hasListeners(eventName: string): boolean;
//@private
/**
* This method is intended to be overriden by inheritors to provide additional implementation.
* @private
*/
_createPropertyChangeData(
name: string,
value: any,
oldValue?: any
): PropertyChangeData;
//@private
/**
* This method is intended to be overriden by inheritors to provide additional implementation.
* @private
*/
_createPropertyChangeData(name: string, value: any, oldValue?: any): PropertyChangeData;
//@private
/**
* Filed to use instead of instanceof ViewBase.
* @private
*/
public _isViewBase: boolean;
//@private
/**
* Filed to use instead of instanceof ViewBase.
* @private
*/
public _isViewBase: boolean;
/**
* @private
*/
_emit(eventNames: string);
//@endprivate
/**
* @private
*/
_emit(eventNames: string);
//@endprivate
}
/**

View File

@@ -1,274 +1,324 @@
import { Observable as ObservableDefinition, WrappedValue as WrappedValueDefinition } from ".";
import {
Observable as ObservableDefinition,
WrappedValue as WrappedValueDefinition,
} from ".";
import { EventData, PropertyChangeData } from "./observable-interfaces";
export * from "./observable-interfaces";
interface ListenerEntry {
callback: (data: EventData) => void;
thisArg: any;
once?: true;
callback: (data: EventData) => void;
thisArg: any;
once?: true;
}
let _wrappedIndex = 0;
export class WrappedValue implements WrappedValueDefinition {
constructor(public wrapped: any) {
}
constructor(public wrapped: any) {}
public static unwrap(value: any) {
return (value instanceof WrappedValue) ? value.wrapped : value;
}
public static unwrap(value: any) {
return value instanceof WrappedValue ? value.wrapped : value;
}
public static wrap(value: any) {
const w = _wrappedValues[_wrappedIndex++ % 5];
w.wrapped = value;
public static wrap(value: any) {
const w = _wrappedValues[_wrappedIndex++ % 5];
w.wrapped = value;
return w;
}
return w;
}
}
let _wrappedValues = [
new WrappedValue(null),
new WrappedValue(null),
new WrappedValue(null),
new WrappedValue(null),
new WrappedValue(null)
new WrappedValue(null),
new WrappedValue(null),
new WrappedValue(null),
new WrappedValue(null),
new WrappedValue(null),
];
export class Observable implements ObservableDefinition {
public static propertyChangeEvent = "propertyChange";
public _isViewBase: boolean;
public static propertyChangeEvent = "propertyChange";
public _isViewBase: boolean;
private _observers = {};
private _observers = {};
public get(name: string): any {
return this[name];
}
public get(name: string): any {
return this[name];
}
public set(name: string, value: any) {
// TODO: Parameter validation
const oldValue = this[name];
if (this[name] === value) {
return;
}
public set(name: string, value: any) {
// TODO: Parameter validation
const oldValue = this[name];
if (this[name] === value) {
return;
}
const newValue = WrappedValue.unwrap(value);
this[name] = newValue;
this.notifyPropertyChange(name, newValue, oldValue);
}
const newValue = WrappedValue.unwrap(value);
this[name] = newValue;
this.notifyPropertyChange(name, newValue, oldValue);
}
public setProperty(name: string, value: any) {
const oldValue = this[name];
if (this[name] === value) {
return;
}
this[name] = value;
this.notifyPropertyChange(name, value, oldValue);
public setProperty(name: string, value: any) {
const oldValue = this[name];
if (this[name] === value) {
return;
}
this[name] = value;
this.notifyPropertyChange(name, value, oldValue);
const specificPropertyChangeEventName = name + "Change";
if (this.hasListeners(specificPropertyChangeEventName)) {
const eventData = this._createPropertyChangeData(name, value, oldValue);
eventData.eventName = specificPropertyChangeEventName;
this.notify(eventData);
}
}
const specificPropertyChangeEventName = name + "Change";
if (this.hasListeners(specificPropertyChangeEventName)) {
const eventData = this._createPropertyChangeData(
name,
value,
oldValue
);
eventData.eventName = specificPropertyChangeEventName;
this.notify(eventData);
}
}
public on(eventNames: string, callback: (data: EventData) => void, thisArg?: any) {
this.addEventListener(eventNames, callback, thisArg);
}
public on(
eventNames: string,
callback: (data: EventData) => void,
thisArg?: any
) {
this.addEventListener(eventNames, callback, thisArg);
}
public once(event: string, callback: (data: EventData) => void, thisArg?: any) {
const list = this._getEventList(event, true);
list.push({ callback, thisArg, once: true });
}
public once(
event: string,
callback: (data: EventData) => void,
thisArg?: any
) {
const list = this._getEventList(event, true);
list.push({ callback, thisArg, once: true });
}
public off(eventNames: string, callback?: any, thisArg?: any) {
this.removeEventListener(eventNames, callback, thisArg);
}
public off(eventNames: string, callback?: any, thisArg?: any) {
this.removeEventListener(eventNames, callback, thisArg);
}
public addEventListener(eventNames: string, callback: (data: EventData) => void, thisArg?: Object) {
if (typeof eventNames !== "string") {
throw new TypeError("Events name(s) must be string.");
}
public addEventListener(
eventNames: string,
callback: (data: EventData) => void,
thisArg?: Object
) {
if (typeof eventNames !== "string") {
throw new TypeError("Events name(s) must be string.");
}
if (typeof callback !== "function") {
throw new TypeError("callback must be function.");
}
if (typeof callback !== "function") {
throw new TypeError("callback must be function.");
}
const events = eventNames.split(",");
for (let i = 0, l = events.length; i < l; i++) {
const event = events[i].trim();
const list = this._getEventList(event, true);
// TODO: Performance optimization - if we do not have the thisArg specified, do not wrap the callback in additional object (ObserveEntry)
list.push({
callback: callback,
thisArg: thisArg
});
}
}
const events = eventNames.split(",");
for (let i = 0, l = events.length; i < l; i++) {
const event = events[i].trim();
const list = this._getEventList(event, true);
// TODO: Performance optimization - if we do not have the thisArg specified, do not wrap the callback in additional object (ObserveEntry)
list.push({
callback: callback,
thisArg: thisArg,
});
}
}
public removeEventListener(eventNames: string, callback?: any, thisArg?: Object) {
if (typeof eventNames !== "string") {
throw new TypeError("Events name(s) must be string.");
}
public removeEventListener(
eventNames: string,
callback?: any,
thisArg?: Object
) {
if (typeof eventNames !== "string") {
throw new TypeError("Events name(s) must be string.");
}
if (callback && typeof callback !== "function") {
throw new TypeError("callback must be function.");
}
if (callback && typeof callback !== "function") {
throw new TypeError("callback must be function.");
}
const events = eventNames.split(",");
for (let i = 0, l = events.length; i < l; i++) {
const event = events[i].trim();
if (callback) {
const list = this._getEventList(event, false);
if (list) {
const index = this._indexOfListener(list, callback, thisArg);
if (index >= 0) {
list.splice(index, 1);
}
if (list.length === 0) {
delete this._observers[event];
}
}
}
else {
this._observers[event] = undefined;
delete this._observers[event];
}
}
}
const events = eventNames.split(",");
for (let i = 0, l = events.length; i < l; i++) {
const event = events[i].trim();
if (callback) {
const list = this._getEventList(event, false);
if (list) {
const index = this._indexOfListener(
list,
callback,
thisArg
);
if (index >= 0) {
list.splice(index, 1);
}
if (list.length === 0) {
delete this._observers[event];
}
}
} else {
this._observers[event] = undefined;
delete this._observers[event];
}
}
}
public notify<T extends EventData>(data: T) {
const observers = <Array<ListenerEntry>>this._observers[data.eventName];
if (!observers) {
return;
}
public notify<T extends EventData>(data: T) {
const observers = <Array<ListenerEntry>>this._observers[data.eventName];
if (!observers) {
return;
}
for (let i = observers.length - 1; i >= 0; i--) {
let entry = observers[i];
if (entry.once) {
observers.splice(i, 1);
}
if (entry.thisArg) {
entry.callback.apply(entry.thisArg, [data]);
} else {
entry.callback(data);
}
}
}
for (let i = observers.length - 1; i >= 0; i--) {
let entry = observers[i];
if (entry.once) {
observers.splice(i, 1);
}
if (entry.thisArg) {
entry.callback.apply(entry.thisArg, [data]);
} else {
entry.callback(data);
}
}
}
public notifyPropertyChange(name: string, value: any, oldValue?: any) {
this.notify(this._createPropertyChangeData(name, value, oldValue));
}
public notifyPropertyChange(name: string, value: any, oldValue?: any) {
this.notify(this._createPropertyChangeData(name, value, oldValue));
}
public hasListeners(eventName: string) {
return eventName in this._observers;
}
public hasListeners(eventName: string) {
return eventName in this._observers;
}
public _createPropertyChangeData(propertyName: string, value: any, oldValue?: any): PropertyChangeData {
return { eventName: Observable.propertyChangeEvent, object: this, propertyName, value, oldValue };
}
public _createPropertyChangeData(
propertyName: string,
value: any,
oldValue?: any
): PropertyChangeData {
return {
eventName: Observable.propertyChangeEvent,
object: this,
propertyName,
value,
oldValue,
};
}
public _emit(eventNames: string) {
const events = eventNames.split(",");
public _emit(eventNames: string) {
const events = eventNames.split(",");
for (let i = 0, l = events.length; i < l; i++) {
const event = events[i].trim();
this.notify({ eventName: event, object: this });
}
}
for (let i = 0, l = events.length; i < l; i++) {
const event = events[i].trim();
this.notify({ eventName: event, object: this });
}
}
private _getEventList(eventName: string, createIfNeeded?: boolean): Array<ListenerEntry> {
if (!eventName) {
throw new TypeError("EventName must be valid string.");
}
private _getEventList(
eventName: string,
createIfNeeded?: boolean
): Array<ListenerEntry> {
if (!eventName) {
throw new TypeError("EventName must be valid string.");
}
let list = <Array<ListenerEntry>>this._observers[eventName];
if (!list && createIfNeeded) {
list = [];
this._observers[eventName] = list;
}
let list = <Array<ListenerEntry>>this._observers[eventName];
if (!list && createIfNeeded) {
list = [];
this._observers[eventName] = list;
}
return list;
}
return list;
}
private _indexOfListener(list: Array<ListenerEntry>, callback: (data: EventData) => void, thisArg?: any): number {
for (let i = 0; i < list.length; i++) {
const entry = list[i];
if (thisArg) {
if (entry.callback === callback && entry.thisArg === thisArg) {
return i;
}
}
else {
if (entry.callback === callback) {
return i;
}
}
}
private _indexOfListener(
list: Array<ListenerEntry>,
callback: (data: EventData) => void,
thisArg?: any
): number {
for (let i = 0; i < list.length; i++) {
const entry = list[i];
if (thisArg) {
if (entry.callback === callback && entry.thisArg === thisArg) {
return i;
}
} else {
if (entry.callback === callback) {
return i;
}
}
}
return -1;
}
return -1;
}
}
class ObservableFromObject extends Observable {
public _map = {};
public _map = {};
public get(name: string): any {
return this._map[name];
}
public get(name: string): any {
return this._map[name];
}
public set(name: string, value: any) {
const currentValue = this._map[name];
if (currentValue === value) {
return;
}
public set(name: string, value: any) {
const currentValue = this._map[name];
if (currentValue === value) {
return;
}
const newValue = WrappedValue.unwrap(value);
this._map[name] = newValue;
this.notifyPropertyChange(name, newValue, currentValue);
}
const newValue = WrappedValue.unwrap(value);
this._map[name] = newValue;
this.notifyPropertyChange(name, newValue, currentValue);
}
}
function defineNewProperty(target: ObservableFromObject, propertyName: string): void {
Object.defineProperty(target, propertyName, {
get: function () {
return target._map[propertyName];
},
set: function (value) {
target.set(propertyName, value);
},
enumerable: true,
configurable: true
});
function defineNewProperty(
target: ObservableFromObject,
propertyName: string
): void {
Object.defineProperty(target, propertyName, {
get: function () {
return target._map[propertyName];
},
set: function (value) {
target.set(propertyName, value);
},
enumerable: true,
configurable: true,
});
}
function addPropertiesFromObject(observable: ObservableFromObject, source: any, recursive: boolean = false) {
Object.keys(source).forEach(prop => {
let value = source[prop];
if (recursive
&& !Array.isArray(value)
&& value
&& typeof value === "object"
&& !(value instanceof Observable)) {
value = fromObjectRecursive(value);
}
function addPropertiesFromObject(
observable: ObservableFromObject,
source: any,
recursive: boolean = false
) {
Object.keys(source).forEach((prop) => {
let value = source[prop];
if (
recursive &&
!Array.isArray(value) &&
value &&
typeof value === "object" &&
!(value instanceof Observable)
) {
value = fromObjectRecursive(value);
}
defineNewProperty(observable, prop);
observable.set(prop, value);
});
defineNewProperty(observable, prop);
observable.set(prop, value);
});
}
export function fromObject(source: any): Observable {
let observable = new ObservableFromObject();
addPropertiesFromObject(observable, source, false);
let observable = new ObservableFromObject();
addPropertiesFromObject(observable, source, false);
return observable;
return observable;
}
export function fromObjectRecursive(source: any): Observable {
let observable = new ObservableFromObject();
addPropertiesFromObject(observable, source, true);
let observable = new ObservableFromObject();
addPropertiesFromObject(observable, source, true);
return observable;
return observable;
}

View File

@@ -2,12 +2,12 @@
import { Observable } from ".";
export interface EventData {
eventName: string;
object: Observable;
eventName: string;
object: Observable;
}
export interface PropertyChangeData extends EventData {
propertyName: string;
value: any;
oldValue?: any;
}
propertyName: string;
value: any;
oldValue?: any;
}

View File

@@ -5,222 +5,222 @@ import { ObservableArray, ChangedData, ChangeType } from "../observable-array";
* Event args for "itemsLoading" event.
*/
export interface ItemsLoading extends EventData {
/**
* Start index.
*/
index: number;
/**
* Start index.
*/
index: number;
/**
* Number of items to load.
*/
count: number;
/**
* Number of items to load.
*/
count: number;
}
/**
* Advanced array like class that helps loading items on demand.
*/
export class VirtualArray<T> extends Observable {
/**
* String value used when hooking to change event.
*/
public static changeEvent = ChangeType.Change;
/**
* String value used when hooking to itemsLoading event.
*/
public static itemsLoadingEvent = "itemsLoading";
/**
* String value used when hooking to change event.
*/
public static changeEvent = ChangeType.Change;
/**
* String value used when hooking to itemsLoading event.
*/
public static itemsLoadingEvent = "itemsLoading";
private _requestedIndexes: Array<number>;
private _loadedIndexes: Array<number>;
private _length: number;
private _cache: {};
private _requestedIndexes: Array<number>;
private _loadedIndexes: Array<number>;
private _length: number;
private _cache: {};
constructor(length = 0) {
super();
constructor(length = 0) {
super();
this._length = length;
this._cache = {};
this._length = length;
this._cache = {};
this._requestedIndexes = [];
this._loadedIndexes = [];
}
this._requestedIndexes = [];
this._loadedIndexes = [];
}
/**
* Gets or sets length for the virtual array.
*/
get length(): number {
return this._length;
}
set length(value: number) {
if (this._length !== value) {
const index = this._length;
const count = value - this._length;
/**
* Gets or sets length for the virtual array.
*/
get length(): number {
return this._length;
}
set length(value: number) {
if (this._length !== value) {
const index = this._length;
const count = value - this._length;
this._length = value;
this._length = value;
this.notify({
eventName: ChangeType.Change,
object: this,
action: count > 0 ? ChangeType.Add : ChangeType.Delete,
index: index,
removed: new Array(count < 0 ? Math.abs(count) : 0),
addedCount: count > 0 ? count : 0,
});
}
}
this.notify({
eventName: ChangeType.Change,
object: this,
action: count > 0 ? ChangeType.Add : ChangeType.Delete,
index: index,
removed: new Array(count < 0 ? Math.abs(count) : 0),
addedCount: count > 0 ? count : 0,
});
}
}
/**
* Gets or sets load size for the virtual array.
*/
private _loadSize: number;
get loadSize(): number {
return this._loadSize;
}
set loadSize(value: number) {
this._loadSize = value;
}
/**
* Gets or sets load size for the virtual array.
*/
private _loadSize: number;
get loadSize(): number {
return this._loadSize;
}
set loadSize(value: number) {
this._loadSize = value;
}
getItem(index: number): T {
const item = this._cache[index];
getItem(index: number): T {
const item = this._cache[index];
if (item === undefined) {
if (
index >= 0 &&
index < this.length &&
this._requestedIndexes.indexOf(index) < 0 &&
this._loadedIndexes.indexOf(index) < 0
) {
this.requestItems(index);
}
}
if (item === undefined) {
if (
index >= 0 &&
index < this.length &&
this._requestedIndexes.indexOf(index) < 0 &&
this._loadedIndexes.indexOf(index) < 0
) {
this.requestItems(index);
}
}
return item;
}
return item;
}
setItem(index: number, value: T) {
if (this._cache[index] !== value) {
this.load(index, [value]);
}
}
setItem(index: number, value: T) {
if (this._cache[index] !== value) {
this.load(index, [value]);
}
}
/**
* Loads items from an array starting at index.
*/
load(index: number, items: T[]): void {
for (let i = 0; i < items.length; i++) {
const itemIndex = index + i;
/**
* Loads items from an array starting at index.
*/
load(index: number, items: T[]): void {
for (let i = 0; i < items.length; i++) {
const itemIndex = index + i;
this._cache[itemIndex] = items[i];
this._cache[itemIndex] = items[i];
this._requestedIndexes.splice(
this._requestedIndexes.indexOf(itemIndex),
1
);
this._requestedIndexes.splice(
this._requestedIndexes.indexOf(itemIndex),
1
);
if (this._loadedIndexes.indexOf(itemIndex) < 0) {
this._loadedIndexes.push(itemIndex);
}
}
if (this._loadedIndexes.indexOf(itemIndex) < 0) {
this._loadedIndexes.push(itemIndex);
}
}
// Remove requested but never loaded indexes.
if (this._requestedIndexes.length > 0) {
for (let i = 0; i < this.loadSize - items.length; i++) {
this._requestedIndexes.splice(
this._requestedIndexes.indexOf(index + i),
1
);
}
}
// Remove requested but never loaded indexes.
if (this._requestedIndexes.length > 0) {
for (let i = 0; i < this.loadSize - items.length; i++) {
this._requestedIndexes.splice(
this._requestedIndexes.indexOf(index + i),
1
);
}
}
this.notify({
eventName: ChangeType.Change,
object: this,
action: ChangeType.Update,
index: index,
removed: new Array(items.length),
addedCount: items.length,
});
}
this.notify({
eventName: ChangeType.Change,
object: this,
action: ChangeType.Update,
index: index,
removed: new Array(items.length),
addedCount: items.length,
});
}
private requestItems(index: number): void {
const indexesToLoad = [];
private requestItems(index: number): void {
const indexesToLoad = [];
const pageIndex =
this._loadSize > 0
? this._loadSize * Math.floor(index / this._loadSize)
: index;
let count = 0;
let start = -1;
const pageIndex =
this._loadSize > 0
? this._loadSize * Math.floor(index / this._loadSize)
: index;
let count = 0;
let start = -1;
for (let i = 0; i < this.loadSize; i++) {
const itemIndex = pageIndex + i;
for (let i = 0; i < this.loadSize; i++) {
const itemIndex = pageIndex + i;
if (itemIndex >= this._length) {
break;
}
if (itemIndex >= this._length) {
break;
}
if (this._loadedIndexes.indexOf(itemIndex) < 0) {
if (start < 0) {
start = itemIndex;
}
if (this._loadedIndexes.indexOf(itemIndex) < 0) {
if (start < 0) {
start = itemIndex;
}
indexesToLoad.push(itemIndex);
indexesToLoad.push(itemIndex);
if (this._requestedIndexes.indexOf(itemIndex) < 0) {
this._requestedIndexes.push(itemIndex);
}
if (this._requestedIndexes.indexOf(itemIndex) < 0) {
this._requestedIndexes.push(itemIndex);
}
count++;
} else {
if (count > 0) {
this.notify({
eventName: VirtualArray.itemsLoadingEvent,
object: this,
index: start,
count: count,
});
}
count++;
} else {
if (count > 0) {
this.notify({
eventName: VirtualArray.itemsLoadingEvent,
object: this,
index: start,
count: count,
});
}
start = -1;
count = 0;
}
}
start = -1;
count = 0;
}
}
if (start >= 0 && count > 0) {
this.notify({
eventName: VirtualArray.itemsLoadingEvent,
object: this,
index: start,
count: count,
});
}
}
if (start >= 0 && count > 0) {
this.notify({
eventName: VirtualArray.itemsLoadingEvent,
object: this,
index: start,
count: count,
});
}
}
}
export interface VirtualArray<T> {
/**
* A basic method signature to hook an event listener (shortcut alias to the addEventListener method).
* @param eventNames - String corresponding to events (e.g. "propertyChange"). Optionally could be used more events separated by `,` (e.g. "propertyChange", "change").
* @param callback - Callback function which will be executed when event is raised.
* @param thisArg - An optional parameter which will be used as `this` context for callback execution.
*/
on(
eventNames: string,
callback: (data: EventData) => void,
thisArg?: any
): void;
/**
* Raised when still not loaded items are requested.
*/
on(
event: "itemsLoading",
callback: (args: ItemsLoading) => void,
thisArg?: any
): void;
/**
* Raised when a change occurs.
*/
on(
event: "change",
callback: (args: ChangedData<T>) => void,
thisArg?: any
): void;
/**
* A basic method signature to hook an event listener (shortcut alias to the addEventListener method).
* @param eventNames - String corresponding to events (e.g. "propertyChange"). Optionally could be used more events separated by `,` (e.g. "propertyChange", "change").
* @param callback - Callback function which will be executed when event is raised.
* @param thisArg - An optional parameter which will be used as `this` context for callback execution.
*/
on(
eventNames: string,
callback: (data: EventData) => void,
thisArg?: any
): void;
/**
* Raised when still not loaded items are requested.
*/
on(
event: "itemsLoading",
callback: (args: ItemsLoading) => void,
thisArg?: any
): void;
/**
* Raised when a change occurs.
*/
on(
event: "change",
callback: (args: ChangedData<T>) => void,
thisArg?: any
): void;
}