BaseArrayClass
September 29, 2018 ยท View on GitHub
let mvcArray: BaseArrayClass<any> = new BaseArrayClass<any>();
mvcArray.on('insert_at', (index: number, element: any) => {
console.log(`[insert: ${index}]`, index, element);
});
mvcArray.push({
'title': "1",
'position': { 'lat': ..., 'lng': ...},
'dbId': "db_1"
});
mvcArray.push({
'title': "2",
'position': { 'lat': ..., 'lng': ...},
'dbId': "db_2"
});
mvcArray.push({
'title': "3",
'position': { 'lat': ..., 'lng': ...},
'dbId': "db_3"
});
API Reference
new BaseArrayClass(initialData?)
| Params | Type | Details |
|---|---|---|
| initialData | T[] | any | (optional)initialData |
Instance method
-
empty(noNotify?)
Adds an event listener.
Params Type Details noNotify boolean Set true to prevent remove_at events. -
forEach(fn)
Iterate over each element, calling the provided callback.
Params Type Details fn Function(element: T, index?: number) => void your code -
forEachAsync(fn)
Iterate over each element, calling the provided callback.
Params Type Details fn Function(element: T, callback: () => void) => void your code :arrow_right:
Promise<void> -
map(fn)
Iterate over each element, then Returns a new value. Then you can get the results of each callback.
Params Type Details fn Function(element: T, index: number) => any) your code :arrow_right:
any[] -
mapAsync(fn)
Iterate over each element, calling the provided callback. Then you can get the results of each callback.
Params Type Details fn Function((element: T, callback: (newElement: any) => void) => void) your code :arrow_right:
Promise<any[]> -
mapSeries(fn)
Same as
mapAsync, but keep the execution order.Params Type Details fn Function((element: T, callback: (newElement: any) => void) => void) your code :arrow_right:
Promise<any[]> -
filter(fn)
The filter() method creates a new array with all elements that pass the test implemented by the provided function.
Params Type Details fn Function(element: T, index: number) => boolean your code :arrow_right:
T[] -
filterAsync(fn)
The filterAsync() method creates a new array with all elements that pass the test implemented by the provided function.
Params Type Details fn Function(element: T, callback: (result: boolean) => void) => void your code :arrow_right:
Promise<T[]> -
getArray()
Returns a reference to the underlying Array.
:arrow_right:
T[] -
getAt(index)
Returns the element at the specified index.
Params Type Details index number array index :arrow_right:
T -
getLength()
Returns the number of the elements.
:arrow_right:
number -
indexOf(element)
The indexOf() method returns the first index at which a given element can be found in the array, or -1 if it is not present.
Params Type Details element T the element you want to search :arrow_right:
number -
reverse()
The reverse() method reverses an array in place.
-
sort()
The sort() method sorts the elements of an array in place and returns the array.
-
insertAt(index, element, noNotify?)
Inserts an element at the specified index.
Params Type Details index number array index element T new element noNotify boolean (optional)Set true to prevent insert_at event. -
pop(noNotify?)
Removes the last element of the array and returns that element.
Params Type Details noNotify boolean (optional)Set true to prevent remove_at event. :arrow_right:
T -
push(element, noNotify?)
Adds one element to the end of the array and returns the new length of the array.
Params Type Details element T new element noNotify boolean (optional)Set true to prevent remove_at event. :arrow_right:
T -
removeAt(index, noNotify?)
Removes an element from the specified index.
Params Type Details index number array index noNotify boolean (optional)Set true to prevent remove_at event. :arrow_right:
T -
setAt(index, element, noNotify?)
Removes an element from the specified index.
Params Type Details index number array index element T new element noNotify boolean (optional)Set true to prevent remove_at event.