mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-16 06:50:19 +00:00
Merge pull request #2934 from DenEwout/master
Added support for Array Change subscriptions. Added tests to the test_observableArrays() in knockout-tests.ts.
This commit is contained in:
Vendored
+32
-19
@@ -1,4 +1,4 @@
|
||||
// Type definitions for Knockout v3.2.0-beta
|
||||
// Type definitions for Knockout v3.2.0
|
||||
// Project: http://knockoutjs.com
|
||||
// Definitions by: Boris Yankov <https://github.com/borisyankov/>, Igor Oleinikov <https://github.com/Igorbek/>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
@@ -53,12 +53,33 @@ interface KnockoutSubscription {
|
||||
}
|
||||
|
||||
interface KnockoutSubscribable<T> extends KnockoutSubscribableFunctions<T> {
|
||||
subscribe(callback: (newValue: T) => void, target?: any, event?: string): KnockoutSubscription;
|
||||
subscribe(callback: (param : any) => void, target?: any, event?: string): KnockoutSubscription;
|
||||
subscribe(callback: (param : any) => void, target: any, event: string): KnockoutSubscription;
|
||||
subscribe<TEvent>(callback: (newValue: TEvent) => void, target: any, event: string): KnockoutSubscription;
|
||||
extend(requestedExtenders: { [key: string]: any; }): KnockoutSubscribable<T>;
|
||||
getSubscriptionsCount(): number;
|
||||
}
|
||||
|
||||
interface KnockoutObservableProperties<T>{
|
||||
(): T;
|
||||
(value: T): void;
|
||||
|
||||
peek(): T;
|
||||
valueHasMutated?:{(): void;};
|
||||
valueWillMutate?:{(): void;};
|
||||
}
|
||||
|
||||
interface KnockoutObservableStatic {
|
||||
fn: KnockoutObservableFunctions<any>;
|
||||
|
||||
<T>(value?: T): KnockoutObservable<T>;
|
||||
}
|
||||
|
||||
interface KnockoutObservable<T> extends KnockoutSubscribable<T>, KnockoutObservableProperties<T>, KnockoutObservableFunctions<T> {
|
||||
subscribe(callback: (newValue : T) => void, target?: any, event?: string): KnockoutSubscription;
|
||||
extend(requestedExtenders: { [key: string]: any; }): KnockoutObservable<T>;
|
||||
}
|
||||
|
||||
interface KnockoutComputedStatic {
|
||||
fn: KnockoutComputedFunctions<any>;
|
||||
|
||||
@@ -83,26 +104,18 @@ interface KnockoutObservableArrayStatic {
|
||||
<T>(value?: T[]): KnockoutObservableArray<T>;
|
||||
}
|
||||
|
||||
interface KnockoutObservableArray<T> extends KnockoutObservable<T[]>, KnockoutObservableArrayFunctions<T> {
|
||||
interface KnockoutObservableArray<T> extends KnockoutSubscribable<T[]>, KnockoutObservableProperties<T[]>,KnockoutObservableArrayFunctions<T> {
|
||||
subscribe(callback: (changes : KnockoutArrayChange<T>[]) => void, target: any, event: string): KnockoutSubscription;
|
||||
subscribe(callback: (changes : KnockoutArrayChange<T>[]) => void, target: any, event: 'arrayChange'): KnockoutSubscription;
|
||||
|
||||
subscribe(callback: (param : T[]) => void, target?: any, event?: string): KnockoutSubscription;
|
||||
subscribe(callback: (param : T[]) => void, target: any, event: string): KnockoutSubscription;
|
||||
subscribe(callback: (param : T[]) => void, target: any, event: 'change'): KnockoutSubscription;
|
||||
subscribe(callback: (param : T[]) => void, target: any, event: 'beforeChange'): KnockoutSubscription;
|
||||
|
||||
extend(requestedExtenders: { [key: string]: any; }): KnockoutObservableArray<T>;
|
||||
}
|
||||
|
||||
interface KnockoutObservableStatic {
|
||||
fn: KnockoutObservableFunctions<any>;
|
||||
|
||||
<T>(value?: T): KnockoutObservable<T>;
|
||||
}
|
||||
|
||||
interface KnockoutObservable<T> extends KnockoutSubscribable<T>, KnockoutObservableFunctions<T> {
|
||||
(): T;
|
||||
(value: T): void;
|
||||
|
||||
peek(): T;
|
||||
valueHasMutated?:{(): void;};
|
||||
valueWillMutate?:{(): void;};
|
||||
extend(requestedExtenders: { [key: string]: any; }): KnockoutObservable<T>;
|
||||
}
|
||||
|
||||
interface KnockoutComputedDefine<T> {
|
||||
read(): T;
|
||||
write? (value: T): void;
|
||||
|
||||
@@ -108,6 +108,27 @@ function testGetter() {
|
||||
|
||||
function test_observableArrays() {
|
||||
var myObservableArray = ko.observableArray<any>();
|
||||
|
||||
myObservableArray.subscribe(function(changes){
|
||||
for(var i = 0; i < changes.length; i++){
|
||||
console.log(changes[i].index);
|
||||
console.log(changes[i].status);
|
||||
console.log(changes[i].value);
|
||||
}
|
||||
}, null, "arrayChange");
|
||||
|
||||
myObservableArray.subscribe(function(newValue){
|
||||
console.log(newValue);
|
||||
}, null, "change");
|
||||
|
||||
myObservableArray.subscribe(function(oldValue){
|
||||
console.log(oldValue);
|
||||
}, null, "beforeChange");
|
||||
|
||||
myObservableArray.subscribe(function(newValue){
|
||||
console.log(newValue);
|
||||
});
|
||||
|
||||
myObservableArray.push('Some value');
|
||||
var anotherObservableArray = ko.observableArray([
|
||||
{ name: "Bungle", type: "Bear" },
|
||||
|
||||
Reference in New Issue
Block a user