From 5d0618b145a887d69b8282119aacae2748927a39 Mon Sep 17 00:00:00 2001 From: Manuel Schweigert Date: Thu, 12 May 2016 14:58:31 +0200 Subject: [PATCH 1/2] Add expressionRewriting members These members are needed to create custom two-way bindings. --- knockout/knockout.d.ts | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/knockout/knockout.d.ts b/knockout/knockout.d.ts index 6e53ac2e25..14dbce04a5 100644 --- a/knockout/knockout.d.ts +++ b/knockout/knockout.d.ts @@ -523,8 +523,26 @@ interface KnockoutStatic { renderTemplateForEach(template: any, arrayOrObservableArray: KnockoutObservable, options: Object, targetNode: Node, parentBindingContext: KnockoutBindingContext): any; expressionRewriting: { - bindingRewriteValidators: any; - parseObjectLiteral: { (objectLiteralString: string): any[] } + bindingRewriteValidators: any[]; + twoWayBindings: any; + parseObjectLiteral: (objectLiteralString: string): any[]; + + /** + Internal, private KO utility for updating model properties from within bindings + property: If the property being updated is (or might be) an observable, pass it here + If it turns out to be a writable observable, it will be written to directly + allBindings: An object with a get method to retrieve bindings in the current execution context. + This will be searched for a '_ko_property_writers' property in case you're writing to a non-observable + (See note below) + key: The key identifying the property to be written. Example: for { hasFocus: myValue }, write to 'myValue' by specifying the key 'hasFocus' + value: The value to be written + checkIfDifferent: If true, and if the property being written is a writable observable, the value will only be written if + it is !== existing value on that writable observable + + Note that if you need to write to the viewModel without an observable property, + you need to set ko.expressionRewriting.twoWayBindings[key] = true; *before* the binding evaluation. + */ + writeValueToProperty: (property: KnockoutObservable | any, allBindings: KnockoutAllBindingsAccessor, key: string, value: any, checkIfDifferent?: boolean): void; }; ///////////////////////////////// From 1a3b6bdf54455b5dd828afb149e6fc758acd23b6 Mon Sep 17 00:00:00 2001 From: Manuel Schweigert Date: Thu, 12 May 2016 15:09:47 +0200 Subject: [PATCH 2/2] Fix build error --- knockout/knockout.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/knockout/knockout.d.ts b/knockout/knockout.d.ts index 14dbce04a5..6321cff0a5 100644 --- a/knockout/knockout.d.ts +++ b/knockout/knockout.d.ts @@ -525,7 +525,7 @@ interface KnockoutStatic { expressionRewriting: { bindingRewriteValidators: any[]; twoWayBindings: any; - parseObjectLiteral: (objectLiteralString: string): any[]; + parseObjectLiteral: (objectLiteralString: string) => any[]; /** Internal, private KO utility for updating model properties from within bindings @@ -542,7 +542,7 @@ interface KnockoutStatic { Note that if you need to write to the viewModel without an observable property, you need to set ko.expressionRewriting.twoWayBindings[key] = true; *before* the binding evaluation. */ - writeValueToProperty: (property: KnockoutObservable | any, allBindings: KnockoutAllBindingsAccessor, key: string, value: any, checkIfDifferent?: boolean): void; + writeValueToProperty: (property: KnockoutObservable | any, allBindings: KnockoutAllBindingsAccessor, key: string, value: any, checkIfDifferent?: boolean) => void; }; /////////////////////////////////