[knockout] Introduce specialized signatures for subscribe method, specifically common "change" and "beforeChange"

Add subscribe for "arrayChange" event for observable array (fixes #11203)
Improve KnockoutArrayChange status typing.
This commit is contained in:
Igor Oleinikov
2016-09-14 11:27:33 -07:00
parent f46e806408
commit 47588ba8f9
3 changed files with 45 additions and 3 deletions

View File

@@ -680,3 +680,38 @@ function test_tasks() {
setTimeout(callback, 0);
};
}
function observableEventsTests() {
var observable = ko.observable(1);
observable.subscribe(value => {
var num: number = value;
});
observable.subscribe(value => {
var num: number = value;
}, null, "change");
observable.subscribe(value => {
var num: number = value;
}, null, "beforeChange");
}
function observableArrayEventsTests() {
var observableArray = ko.observableArray([1, 2, 3, 4]);
observableArray.subscribe(array => {
var arr: number[] = array;
});
observableArray.subscribe(array => {
var arr: number[] = array;
}, null, "change");
observableArray.subscribe(array => {
var arr: number[] = array;
}, null, "beforeChange");
var count = 0;
observableArray.subscribe(changes => {
changes.forEach(change => {
if (change.status == "added")
count++;
else if (change.status == "deleted")
count--;
});
}, null, "arrayChange");
}