Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export const test_ObservableArray_sortShouldReturnNewSortedArray = function () {
// >> observable-array-sort
const array = new ObservableArray([3, 2, 1]);
const result = array.sort();
// << observable-array-sort
TKUnit.assert(result[0] === 1 && result.length === 3, "ObservableArray sort() should return new sorted array!");
};
export const test_ObservableArray_sliceWithParamsShouldReturnSectionAsNewArray = function () {
// >> observable-array-slice-args
const array = new ObservableArray([1, 2, 3, 4, 5]);
const result = array.slice(2, 4);
// << observable-array-slice-args
TKUnit.assert(result[1] === 4 && result.length === 2, "ObservableArray slice() should return section according to specified arguments!");
};
export const test_ObservableArray_indexOfShouldReturnCorrectIndex = function () {
// >> observable-array-indexof
const array = new ObservableArray(["one", "two", "three"]);
const result = array.indexOf("two");
// << observable-array-indexof
TKUnit.assert(result === 1, "ObservableArray indexOf() should return correct index!");
};
export const test_ObservableArray_unshiftShouldInsertNewElementsFromTheStartAndRaiseChangeEventWithCorrectArgs = function () {
let result: ChangedData;
// >> observable-array-unshift-change
const array = new ObservableArray([1, 2, 3]);
array.on(ObservableArray.changeEvent, (args: ChangedData) => {
//// Argument (args) is ChangedData.
//// args.eventName is "change".
//// args.action is "add".
//// args.index is 0.
//// args.removed.length is 0.
//// args.addedCount is equal to the number of inserted items.
// >> (hide)
result = args;
// << (hide)
});
array.unshift(4, 5);
// << observable-array-unshift-change
export const test_ObservableArray_spliceShouldInsertNewItemsInPlaceOfRemovedItemsStartingFromSpecifiedIndex = function () {
// >> observable-array-splice-args
const array = new ObservableArray(["one", "two", "three"]);
const result = array.splice(1, 2, "six", "seven");
// << observable-array-splice-args
TKUnit.assert(result.length === 2 && result[0] === "two" && array.length === 3 && array.getItem(2) === "seven",
"ObservableArray splice() should insert new items in place of removed!");
};
private getItems(size: number) {
let array = new ObservableArray();
for (let i = 0; i < size; i++) {
array.push(new DataItem("Item " + i, i, "Description " + i));
}
return array;
}
}
.then((cars) => {
this.set("cars", new ObservableArray(cars));
this.set("isLoading", false);
})
.catch(() => {
private getItems(size: number) {
let array = new ObservableArray();
for (let i = 0; i < size; i++) {
array.push("Item " + i);
}
return array;
}
}
.subscribe((cars: Array) => {
this.cars = new ObservableArray(cars);
this.isLoading = false;
});