Skip to content

Commit 59a0ee8

Browse files
committed
Merge pull request DefinitelyTyped#8640 from ntrrgc/master
Add ko.untrack() to knockout.es5
2 parents 99355c7 + ed3f222 commit 59a0ee8

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

knockout.es5/knockout.es5-tests.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ class OrderLine {
5454
public getSubtotal(): string {
5555
return "$" + (this.price * this.quantity).toFixed(2);
5656
}
57+
58+
public dispose() {
59+
// Dispose of all the observables of this object to prevent memory leaks
60+
ko.untrack(this);
61+
}
5762
}
5863

5964
class Order {
@@ -83,4 +88,4 @@ anOrder.lines.removeAll();
8388

8489
anOrder.lines.destroy(someOrderLine);
8590
anOrder.lines.destroyAll([someOrderLine]);
86-
anOrder.lines.destroyAll();
91+
anOrder.lines.destroyAll();

knockout.es5/knockout.es5.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
interface KnockoutStatic {
99
track(obj: any, propertyNames?: Array<string>): any;
10+
untrack(obj: any, propertyNames?: Array<string>): any;
1011
defineProperty(obj: any, propertyName: string, evaluator: Function): any;
1112
defineProperty(obj: any, propertyName: string, options: KnockoutDefinePropertyOptions): any;
1213
getObservable(obj: any, propertyName: string): KnockoutObservable<any>;
@@ -26,4 +27,4 @@ interface Array<T> {
2627
destroy(item: T): void;
2728
destroyAll(items: T[]): void;
2829
destroyAll(): void;
29-
}
30+
}

0 commit comments

Comments
 (0)