| title | ObservableArray |
|---|---|
| titleTemplate | title - API / NativeScript |
| description | Advanced array like class used when you want to be notified when a change occurs. |
| contributors | false |
Defined in: data/observable-array/index.ts
Advanced array like class used when you want to be notified when a change occurs.
| Type Parameter |
|---|
T |
new ObservableArray<T>(arrayLength?: number): ObservableArray<T>;Defined in: data/observable-array/index.ts
Create ObservableArray<T> with specified length.
| Parameter | Type |
|---|---|
arrayLength? |
number |
ObservableArray<T>
new ObservableArray<T>(items: T[]): ObservableArray<T>;Defined in: data/observable-array/index.ts
Create ObservableArray<T> from source Array<T>.
| Parameter | Type |
|---|---|
items |
T[] |
ObservableArray<T>
Observable.constructornew ObservableArray<T>(...items: T[]): ObservableArray<T>;Defined in: data/observable-array/index.ts
Create ObservableArray<T> from T items.
| Parameter | Type |
|---|---|
...items |
T[] |
ObservableArray<T>
Observable.constructorstatic changeEvent: string;Defined in: data/observable-array/index.ts
String value used when hooking to change event.
static propertyChangeEvent: string;Defined in: data/observable/index.ts
String value used when hooking to propertyChange event.
propertyChange
Observable.propertyChangeEvent
get length(): number;Defined in: data/observable-array/index.ts
Gets or sets the length of the array. This is a number one higher than the highest element defined in an array.
number
set length(value: number): void;Defined in: data/observable-array/index.ts
| Parameter | Type |
|---|---|
value |
number |
void
_createPropertyChangeData(
propertyName: string,
value: any,
oldValue?: any): PropertyChangeData;Defined in: data/observable/index.ts
This method is intended to be overriden by inheritors to provide additional implementation.
| Parameter | Type |
|---|---|
propertyName |
string |
value |
any |
oldValue? |
any |
Observable._createPropertyChangeData
_emit(eventName: string): void;Defined in: data/observable/index.ts
| Parameter | Type |
|---|---|
eventName |
string |
void
_notifyLengthChange(): void;Defined in: data/observable-array/index.ts
void
iterator: Generator<T, void, unknown>;Defined in: data/observable-array/index.ts
Generator<T, void, unknown>
addEventListener(
eventName: string,
callback: (data: EventData) => void,
thisArg?: any,
once?: boolean): void;Defined in: data/observable/index.ts
Adds a listener for the specified event name.
| Parameter | Type | Description |
|---|---|---|
eventName |
string |
Name of the event to attach to. |
callback |
(data: EventData) => void |
A function to be called when some of the specified event(s) is raised. |
thisArg? |
any |
An optional parameter which when set will be used as "this" in callback method call. |
once? |
boolean |
An optional parameter which when set will cause the event listener to fire once. |
void
concat(...args: any[]): ObservableArray<T>;Defined in: data/observable-array/index.ts
Combines two or more arrays.
| Parameter | Type |
|---|---|
...args |
any[] |
ObservableArray<T>
every(callbackfn: (value: T, index: number, array: ObservableArray<T>) => boolean, thisArg?: any): boolean;Defined in: data/observable-array/index.ts
Determines whether all the members of an array satisfy the specified test.
| Parameter | Type | Description |
|---|---|---|
callbackfn |
(value: T, index: number, array: ObservableArray<T>) => boolean |
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. |
thisArg? |
any |
An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value. |
boolean
filter(callbackfn: (value: T, index: number, array: ObservableArray<T>) => boolean, thisArg?: any): ObservableArray<T>;Defined in: data/observable-array/index.ts
Returns the elements of an array that meet the condition specified in a callback function.
| Parameter | Type | Description |
|---|---|---|
callbackfn |
(value: T, index: number, array: ObservableArray<T>) => boolean |
A function that accepts up to three arguments. The filter method calls the callbackfn function one time for each element in the array. |
thisArg? |
any |
An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value. |
ObservableArray<T>
find(callbackfn: (value: T, index: number, array: ObservableArray<T>) => any, thisArg?: any): T;Defined in: data/observable-array/index.ts
Returns the first element in the array where predicate is true, and null otherwise.
| Parameter | Type | Description |
|---|---|---|
callbackfn |
(value: T, index: number, array: ObservableArray<T>) => any |
- |
thisArg? |
any |
If provided, it will be used as the this value for each invocation of predicate. If it is not provided, undefined is used instead. |
T
findIndex(callbackfn: (value: T, index: number, array: ObservableArray<T>) => any, thisArg?: any): number;Defined in: data/observable-array/index.ts
Returns the index of the first element in the array where predicate is true, and -1 otherwise.
| Parameter | Type | Description |
|---|---|---|
callbackfn |
(value: T, index: number, array: ObservableArray<T>) => any |
- |
thisArg? |
any |
If provided, it will be used as the this value for each invocation of predicate. If it is not provided, undefined is used instead. |
number
forEach(callbackfn: (value: T, index: number, array: ObservableArray<T>) => void, thisArg?: any): void;Defined in: data/observable-array/index.ts
Performs the specified action for each element in an array.
| Parameter | Type | Description |
|---|---|---|
callbackfn |
(value: T, index: number, array: ObservableArray<T>) => void |
A function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the array. |
thisArg? |
any |
An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value. |
void
get(name: string): any;Defined in: data/observable/index.ts
Gets the value of the specified property.
| Parameter | Type |
|---|---|
name |
string |
any
getItem(pos: number): T;Defined in: data/observable-array/index.ts
Returns item at specified position. Supports relative indexing from the end of the array when passed a negative index.
| Parameter | Type |
|---|---|
pos |
number |
T
hasListeners(eventName: string): boolean;Defined in: data/observable/index.ts
Checks whether a listener is registered for the specified event name.
| Parameter | Type | Description |
|---|---|---|
eventName |
string |
The name of the event to check for. |
boolean
includes(searchElement: T, fromIndex?: number): boolean;Defined in: data/observable-array/index.ts
Determines whether the specified element exists inside the array.
| Parameter | Type | Description |
|---|---|---|
searchElement |
T |
The value to locate in the array. |
fromIndex? |
number |
The array index at which to begin the search. If fromIndex is omitted, the search starts at index 0. |
boolean
indexOf(searchElement: T, fromIndex?: number): number;Defined in: data/observable-array/index.ts
Returns the index of the first occurrence of a value in an array.
| Parameter | Type | Description |
|---|---|---|
searchElement |
T |
The value to locate in the array. |
fromIndex? |
number |
The array index at which to begin the search. If fromIndex is omitted, the search starts at index 0. |
number
join(separator?: string): string;Defined in: data/observable-array/index.ts
Adds all the elements of an array separated by the specified separator string.
| Parameter | Type | Description |
|---|---|---|
separator? |
string |
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. |
string
lastIndexOf(searchElement: T, fromIndex?: number): number;Defined in: data/observable-array/index.ts
Returns the index of the last occurrence of a specified value in an array.
| Parameter | Type | Description |
|---|---|---|
searchElement |
T |
The value to locate in the array. |
fromIndex? |
number |
The array index at which to begin the search. If fromIndex is omitted, the search starts at the last index in the array. |
number
map<U>(callbackfn: (value: T, index: number, array: ObservableArray<T>) => U, thisArg?: any): ObservableArray<U>;Defined in: data/observable-array/index.ts
Calls a defined callback function on each element of an array, and returns an array that contains the results.
| Type Parameter |
|---|
U |
| Parameter | Type | Description |
|---|---|---|
callbackfn |
(value: T, index: number, array: ObservableArray<T>) => U |
A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array. |
thisArg? |
any |
An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value. |
ObservableArray<U>
notify<T>(data: T): void;Defined in: data/observable/index.ts
Notify this Observable instance with some data. This causes all event handlers on the Observable instance to be called, as well as any 'global' event handlers set on the instance's class.
| Type Parameter |
|---|
T extends Optional<EventData, "object"> |
| Parameter | Type | Description |
|---|---|---|
data |
T |
an object that satisfies the EventData interface, though with an optional 'object' property. If left undefined, the 'object' property will implicitly be set as this Observable instance. |
void
notifyPropertyChange(
name: string,
value: any,
oldValue?: any): void;Defined in: data/observable/index.ts
Notifies all the registered listeners for the property change event.
| Parameter | Type |
|---|---|
name |
string |
value |
any |
oldValue? |
any |
void
Observable.notifyPropertyChange
off(
eventName: string,
callback?: (data: EventData) => void,
thisArg?: any): void;Defined in: data/observable/index.ts
Removes the listener(s) for the specified event name.
| Parameter | Type | Description |
|---|---|---|
eventName |
string |
The name of the event. |
callback? |
(data: EventData) => void |
An optional specific event listener to remove (if omitted, all event listeners by this name will be removed). |
thisArg? |
any |
An optional parameter which, when set, will be used to refine search of the correct event listener to be removed. |
void
on(
eventName: string,
callback: (data: EventData) => void,
thisArg?: any): void;Defined in: data/observable-array/index.ts
Adds a listener for the specified event name.
| Parameter | Type | Description |
|---|---|---|
eventName |
string |
The name of the event. |
callback |
(data: EventData) => void |
The event listener to add. Will be called when an event of the given name is raised. |
thisArg? |
any |
An optional parameter which, when set, will be bound as the this context when the callback is called. Falsy values will be not be bound. |
void
on(
event: "change",
callback: (args: ChangedData<T>) => void,
thisArg?: any): void;Defined in: data/observable-array/index.ts
| Parameter | Type |
|---|---|
event |
"change" |
callback |
(args: ChangedData<T>) => void |
thisArg? |
any |
void
Observable.ononce(
eventName: string,
callback: (data: EventData) => void,
thisArg?: any): void;Defined in: data/observable/index.ts
Adds a listener for the specified event name, which, once fired, will remove itself.
| Parameter | Type | Description |
|---|---|---|
eventName |
string |
The name of the event. |
callback |
(data: EventData) => void |
The event listener to add. Will be called when an event of the given name is raised. |
thisArg? |
any |
An optional parameter which, when set, will be bound as the this context when the callback is called. Falsy values will be not be bound. |
void
pop(): T;Defined in: data/observable-array/index.ts
Removes the last element from an array and returns it.
T
push(...args: T[]): number;Defined in: data/observable-array/index.ts
Appends new elements to an array, and returns the new length of the array.
| Parameter | Type |
|---|---|
...args |
T[] |
number
reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: ObservableArray<T>) => T, initialValue?: T): T;Defined in: data/observable-array/index.ts
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.
| Parameter | Type | Description |
|---|---|---|
callbackfn |
(previousValue: T, currentValue: T, currentIndex: number, array: ObservableArray<T>) => T |
A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array. |
initialValue? |
T |
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. |
T
reduceRight(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: ObservableArray<T>) => T, initialValue?: T): T;Defined in: data/observable-array/index.ts
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.
| Parameter | Type | Description |
|---|---|---|
callbackfn |
(previousValue: T, currentValue: T, currentIndex: number, array: ObservableArray<T>) => T |
A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array. |
initialValue? |
T |
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. |
T
removeEventListener(
eventName: string,
callback?: (data: EventData) => void,
thisArg?: any): void;Defined in: data/observable/index.ts
Removes listener(s) for the specified event name.
| Parameter | Type | Description |
|---|---|---|
eventName |
string |
Name of the event to attach to. |
callback? |
(data: EventData) => void |
An optional parameter pointing to a specific listener. If not defined, all listeners for the event names will be removed. |
thisArg? |
any |
An optional parameter which when set will be used to refine search of the correct callback which will be removed as event listener. |
void
Observable.removeEventListener
reverse(): ObservableArray<T>;Defined in: data/observable-array/index.ts
Reverses the elements in an Array. This method uses 'in place' algorithm.
ObservableArray<T>
set(name: string, value: any): void;Defined in: data/observable/index.ts
Updates the specified property with the provided value.
| Parameter | Type |
|---|---|
name |
string |
value |
any |
void
setItem(pos: number, value: T): void;Defined in: data/observable-array/index.ts
Sets item at specified position. Supports relative indexing from the end of the array when passed a negative index.
| Parameter | Type |
|---|---|
pos |
number |
value |
T |
void
setProperty(name: string, value: any): void;Defined in: data/observable/index.ts
Updates the specified property with the provided value and raises a property change event and a specific change event based on the property name.
| Parameter | Type |
|---|---|
name |
string |
value |
any |
void
shift(): T;Defined in: data/observable-array/index.ts
Removes the first element from an array and returns it.
T
slice(start?: number, end?: number): ObservableArray<T>;Defined in: data/observable-array/index.ts
Returns a section of an array.
| Parameter | Type | Description |
|---|---|---|
start? |
number |
The beginning of the specified portion of the array. |
end? |
number |
The end of the specified portion of the array. |
ObservableArray<T>
some(callbackfn: (value: T, index: number, array: ObservableArray<T>) => boolean, thisArg?: any): boolean;Defined in: data/observable-array/index.ts
Determines whether the specified callback function returns true for any element of an array.
| Parameter | Type | Description |
|---|---|---|
callbackfn |
(value: T, index: number, array: ObservableArray<T>) => boolean |
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. |
thisArg? |
any |
An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value. |
boolean
sort(compareFn?: (a: T, b: T) => number): ObservableArray<T>;Defined in: data/observable-array/index.ts
Sorts an array. This method uses 'in place' algorithm.
| Parameter | Type | Description |
|---|---|---|
compareFn? |
(a: T, b: T) => number |
The name of the function used to determine the order of the elements. If omitted, the elements are sorted in ascending, ASCII character order. |
ObservableArray<T>
splice(
start: number,
deleteCount?: number, ...
items: T[]): ObservableArray<T>;Defined in: data/observable-array/index.ts
Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements. This method uses 'in place' algorithm.
| Parameter | Type | Description |
|---|---|---|
start |
number |
The zero-based location in the array from which to start removing elements. |
deleteCount? |
number |
The number of elements to remove. |
...items? |
T[] |
Elements to insert into the array in place of the deleted elements. |
ObservableArray<T>
toJSON(): any[];Defined in: data/observable-array/index.ts
any[]
toLocaleString(): string;Defined in: data/observable-array/index.ts
Returns a date converted to a string using the current locale.
string
toString(): string;Defined in: data/observable-array/index.ts
Returns a string representation of an array.
string
unshift(...args: T[]): number;Defined in: data/observable-array/index.ts
Inserts new elements at the start of an array.
| Parameter | Type |
|---|---|
...args |
T[] |
number
static addEventListener(
eventName: string,
callback: (data: EventData) => void,
thisArg?: any,
once?: boolean): void;Defined in: data/observable/index.ts
Please avoid using the static event-handling APIs as they will be removed in future.
| Parameter | Type |
|---|---|
eventName |
string |
callback |
(data: EventData) => void |
thisArg? |
any |
once? |
boolean |
void
static off(
eventName: string,
callback?: (data: EventData) => void,
thisArg?: any): void;Defined in: data/observable/index.ts
Please avoid using the static event-handling APIs as they will be removed in future.
| Parameter | Type |
|---|---|
eventName |
string |
callback? |
(data: EventData) => void |
thisArg? |
any |
void
static on(
eventName: string,
callback: (data: EventData) => void,
thisArg?: any,
once?: boolean): void;Defined in: data/observable/index.ts
Please avoid using the static event-handling APIs as they will be removed in future.
| Parameter | Type |
|---|---|
eventName |
string |
callback |
(data: EventData) => void |
thisArg? |
any |
once? |
boolean |
void
static once(
eventName: string,
callback: (data: EventData) => void,
thisArg?: any): void;Defined in: data/observable/index.ts
Please avoid using the static event-handling APIs as they will be removed in future.
| Parameter | Type |
|---|---|
eventName |
string |
callback |
(data: EventData) => void |
thisArg? |
any |
void
static removeEventListener(
eventName: string,
callback?: (data: EventData) => void,
thisArg?: any): void;Defined in: data/observable/index.ts
Please avoid using the static event-handling APIs as they will be removed in future.
| Parameter | Type |
|---|---|
eventName |
string |
callback? |
(data: EventData) => void |
thisArg? |
any |
void