From ed3f2229094197f111e1ad3db2cc5d87f2dab6c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Luis=20Boya=20Garc=C3=ADa?= Date: Sat, 19 Mar 2016 18:16:23 +0100 Subject: [PATCH] Add ko.untrack() to knockout.es5 See https://github.com/SteveSanderson/knockout-es5/blob/75773a52f543380aa6dbf6ccffb4b8fc56fa8a2a/src/knockout-es5.js#L196 --- knockout.es5/knockout.es5-tests.ts | 7 ++++++- knockout.es5/knockout.es5.d.ts | 3 ++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/knockout.es5/knockout.es5-tests.ts b/knockout.es5/knockout.es5-tests.ts index f35ea44b84..4177d303b0 100644 --- a/knockout.es5/knockout.es5-tests.ts +++ b/knockout.es5/knockout.es5-tests.ts @@ -54,6 +54,11 @@ class OrderLine { public getSubtotal(): string { return "$" + (this.price * this.quantity).toFixed(2); } + + public dispose() { + // Dispose of all the observables of this object to prevent memory leaks + ko.untrack(this); + } } class Order { @@ -83,4 +88,4 @@ anOrder.lines.removeAll(); anOrder.lines.destroy(someOrderLine); anOrder.lines.destroyAll([someOrderLine]); -anOrder.lines.destroyAll(); \ No newline at end of file +anOrder.lines.destroyAll(); diff --git a/knockout.es5/knockout.es5.d.ts b/knockout.es5/knockout.es5.d.ts index a62f5d8a81..06309059ef 100644 --- a/knockout.es5/knockout.es5.d.ts +++ b/knockout.es5/knockout.es5.d.ts @@ -7,6 +7,7 @@ interface KnockoutStatic { track(obj: any, propertyNames?: Array): any; + untrack(obj: any, propertyNames?: Array): any; defineProperty(obj: any, propertyName: string, evaluator: Function): any; defineProperty(obj: any, propertyName: string, options: KnockoutDefinePropertyOptions): any; getObservable(obj: any, propertyName: string): KnockoutObservable; @@ -26,4 +27,4 @@ interface Array { destroy(item: T): void; destroyAll(items: T[]): void; destroyAll(): void; -} \ No newline at end of file +}