From bb2432ce6925b6ce704f74a4268b63be7fe2b6ce Mon Sep 17 00:00:00 2001 From: Igor Oleinikov Date: Sat, 28 Jun 2014 14:18:59 +0400 Subject: [PATCH 01/10] Added ko.computedContext, ko.pureComputed. --- knockout/knockout.d.ts | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/knockout/knockout.d.ts b/knockout/knockout.d.ts index 71252985d..57d4d4bf1 100644 --- a/knockout/knockout.d.ts +++ b/knockout/knockout.d.ts @@ -64,8 +64,8 @@ interface KnockoutComputedStatic { (): KnockoutComputed; (func: () => T, context?: any, options?: any): KnockoutComputed; - (def: KnockoutComputedDefine): KnockoutComputed; - (options?: any): KnockoutComputed; + (def: KnockoutComputedDefine, context?: any): KnockoutComputed; + (options?: any, context?: any): KnockoutComputed; } interface KnockoutComputed extends KnockoutObservable, KnockoutComputedFunctions { @@ -397,7 +397,11 @@ interface KnockoutStatic { subscribable: KnockoutSubscribableStatic; observable: KnockoutObservableStatic; - computed: KnockoutComputedStatic; + + computed: KnockoutComputedStatic; + pureComputed(evaluatorFunction: () => T, context?: any): KnockoutComputed; + pureComputed(options: KnockoutComputedDefine, context?: any): KnockoutComputed; + observableArray: KnockoutObservableArrayStatic; contextFor(node: any): any; @@ -412,7 +416,9 @@ interface KnockoutStatic { cleanNode(node: Element): Element; renderTemplate(template: Function, viewModel: any, options?: any, target?: any, renderMode?: any): any; renderTemplate(template: string, viewModel: any, options?: any, target?: any, renderMode?: any): any; - unwrap(value: any): any; + unwrap(value: any): any; + + computedContext: KnockoutComputedContext; ////////////////////////////////// // templateSources.js @@ -513,6 +519,12 @@ interface KnockoutStatic { }; } +interface KnockoutComputedContext { + getDependenciesCount(): number; + isInitial: boolean; + isSleeping: boolean; +} + declare module "knockout" { export = ko; } From 2b88f1cf8b4bee60cc2f1705cd989975f947622d Mon Sep 17 00:00:00 2001 From: Igor Oleinikov Date: Sat, 28 Jun 2014 14:47:31 +0400 Subject: [PATCH 02/10] Added rateLimit extender. --- knockout/knockout.d.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/knockout/knockout.d.ts b/knockout/knockout.d.ts index 57d4d4bf1..45548a5c7 100644 --- a/knockout/knockout.d.ts +++ b/knockout/knockout.d.ts @@ -69,6 +69,7 @@ interface KnockoutComputedStatic { } interface KnockoutComputed extends KnockoutObservable, KnockoutComputedFunctions { + fn: KnockoutComputedFunctions; dispose(): void; isActive(): boolean; @@ -109,6 +110,7 @@ interface KnockoutComputedDefine { disposeWhen? (): boolean; owner?: any; deferEvaluation?: boolean; + pure?: boolean; } interface KnockoutBindingContext { @@ -190,7 +192,10 @@ interface KnockoutVirtualElements { interface KnockoutExtenders { throttle(target: any, timeout: number): KnockoutComputed; - notify(target: any, notifyWhen: string): any; + notify(target: any, notifyWhen: string): any; + + rateLimit(target: any, timeout: number): any; + rateLimit(target: any, options: { timeout: number; method?: string; }): any; } interface KnockoutUtils { From b753ba68cc5c3205d7230effc6cd1d512299fdbd Mon Sep 17 00:00:00 2001 From: Igor Oleinikov Date: Sat, 28 Jun 2014 17:37:29 +0400 Subject: [PATCH 03/10] Added trackArrayChanges extender, ko.getBindingHandler, ko.applyBindingAccessorsToNode. --- knockout/knockout.d.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/knockout/knockout.d.ts b/knockout/knockout.d.ts index 45548a5c7..3fe5908ec 100644 --- a/knockout/knockout.d.ts +++ b/knockout/knockout.d.ts @@ -196,6 +196,8 @@ interface KnockoutExtenders { rateLimit(target: any, timeout: number): any; rateLimit(target: any, options: { timeout: number; method?: string; }): any; + + trackArrayChanges(target: any): any; } interface KnockoutUtils { @@ -392,12 +394,19 @@ interface KnockoutTemplateEngine extends KnockoutNativeTemplateEngine { interface KnockoutStatic { utils: KnockoutUtils; memoization: KnockoutMemoization; - bindingHandlers: KnockoutBindingHandlers; + + bindingHandlers: KnockoutBindingHandlers; + getBindingHandler(handler: string): KnockoutBindingHandler; + virtualElements: KnockoutVirtualElements; extenders: KnockoutExtenders; applyBindings(viewModel: any, rootNode?: any): void; - applyBindingsToDescendants(viewModel: any, rootNode: any): void; + applyBindingsToDescendants(viewModel: any, rootNode: any): void; + applyBindingAccessorsToNode(node: Node, bindings: (bindingContext: KnockoutBindingContext, node: Node) => {}, bindingContext: KnockoutBindingContext): void; + applyBindingAccessorsToNode(node: Node, bindings: {}, bindingContext: KnockoutBindingContext): void; + applyBindingAccessorsToNode(node: Node, bindings: (bindingContext: KnockoutBindingContext, node: Node) => {}, viewModel: any): void; + applyBindingAccessorsToNode(node: Node, bindings: {}, viewModel: any): void; applyBindingsToNode(node: Element, options: any, viewModel: any): void; subscribable: KnockoutSubscribableStatic; From c181fd930975562b147f6ed92fd31d4895cfbfc4 Mon Sep 17 00:00:00 2001 From: Igor Oleinikov Date: Sat, 28 Jun 2014 17:56:50 +0400 Subject: [PATCH 04/10] Added KnockoutBindingProvider, KnockoutComponents, KnockoutComponentLoader. Added stubs for KnockoutComponentDefinition, KnockoutComponentConfig. --- knockout/knockout.d.ts | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/knockout/knockout.d.ts b/knockout/knockout.d.ts index 3fe5908ec..e2a5e2738 100644 --- a/knockout/knockout.d.ts +++ b/knockout/knockout.d.ts @@ -519,7 +519,7 @@ interface KnockoutStatic { ///////////////////////////////// - bindingProvider: any; + bindingProvider: KnockoutBindingProvider; ///////////////////////////////// // selectExtensions.js @@ -533,6 +533,33 @@ interface KnockoutStatic { }; } +interface KnockoutBindingProvider { + nodeHasBindings(node: Node): boolean; + getBindings(node: Node, bindingContext: KnockoutBindingContext): {}; + getBindingsString(node: Node, bindingContext: KnockoutBindingContext): string; + getBindingAccessors(node: Node, bindingContext: KnockoutBindingContext): { [key: string]: string; }; +} + +interface KnockoutComponents { + get(componentName: string, callback: (definition: KnockoutComponentDefinition) => void): void; + clearCachedDefinition(componentName: string): void; + loaders: any[]; +} + +interface KnockoutComponentDefinition { + // todo +} + +interface KnockoutComponentLoader { + getConfig? (componentName: string, callback: (result: KnockoutComponentConfig) => void): void; + loadComponent? (componentName: string, config: KnockoutComponentConfig, callback: (result: KnockoutComponentDefinition) => void): void; + suppressLoaderExceptions?: boolean; +} + +interface KnockoutComponentConfig { + // todo +} + interface KnockoutComputedContext { getDependenciesCount(): number; isInitial: boolean; From 7b4b881fbcdc1f1cfd34881defead166caab71e8 Mon Sep 17 00:00:00 2001 From: Igor Oleinikov Date: Sat, 28 Jun 2014 18:55:04 +0400 Subject: [PATCH 05/10] Added ko.component KnockoutComponents: register, isRegistered, unregister; KnockoutComponentDefinition: template, createViewModel; KnockoutComponentLoader: loadTemplate, loadViewModel; KnockoutComponentConfig: template, createViewModel. --- knockout/knockout.d.ts | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/knockout/knockout.d.ts b/knockout/knockout.d.ts index e2a5e2738..e3d5e42cb 100644 --- a/knockout/knockout.d.ts +++ b/knockout/knockout.d.ts @@ -167,7 +167,10 @@ interface KnockoutBindingHandlers { uniqueName: KnockoutBindingHandler; // Rendering templates - template: KnockoutBindingHandler; + template: KnockoutBindingHandler; + + // Components (new for v3.2) + component: KnockoutBindingHandler; } interface KnockoutMemoization { @@ -541,23 +544,31 @@ interface KnockoutBindingProvider { } interface KnockoutComponents { + register(componentName: string, definition: KnockoutComponentDefinition): void; + isRegistered(componentName: string): boolean; + unregister(componentName: string): void; get(componentName: string, callback: (definition: KnockoutComponentDefinition) => void): void; - clearCachedDefinition(componentName: string): void; - loaders: any[]; + clearCachedDefinition(componentName: string): void + defaultLoader: KnockoutComponentLoader; + loaders: KnockoutComponentLoader[]; } interface KnockoutComponentDefinition { - // todo + template: Node[]; + createViewModel?(params: any, options: { element: Node; }): any; } interface KnockoutComponentLoader { getConfig? (componentName: string, callback: (result: KnockoutComponentConfig) => void): void; loadComponent? (componentName: string, config: KnockoutComponentConfig, callback: (result: KnockoutComponentDefinition) => void): void; + loadTemplate? (componentName: string, templateConfig: any, callback: (result: Node[]) => void): void; + loadViewModel? (componentName: string, viewModelConfig: any, callback: (result: any) => void): void; suppressLoaderExceptions?: boolean; } interface KnockoutComponentConfig { - // todo + template: any; + createViewModel?: any; } interface KnockoutComputedContext { From d72558d1598a48f27c0751882f41a52cbddd136a Mon Sep 17 00:00:00 2001 From: Igor Oleinikov Date: Sat, 28 Jun 2014 19:06:51 +0400 Subject: [PATCH 06/10] Removed ko.bindingProvider.getBindingsString. --- knockout/knockout.d.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/knockout/knockout.d.ts b/knockout/knockout.d.ts index e3d5e42cb..4428e48ac 100644 --- a/knockout/knockout.d.ts +++ b/knockout/knockout.d.ts @@ -539,7 +539,6 @@ interface KnockoutStatic { interface KnockoutBindingProvider { nodeHasBindings(node: Node): boolean; getBindings(node: Node, bindingContext: KnockoutBindingContext): {}; - getBindingsString(node: Node, bindingContext: KnockoutBindingContext): string; getBindingAccessors(node: Node, bindingContext: KnockoutBindingContext): { [key: string]: string; }; } From 73778d52f70083e45bd9cd4894e26e35e31b91f2 Mon Sep 17 00:00:00 2001 From: Igor Oleinikov Date: Sat, 28 Jun 2014 19:20:44 +0400 Subject: [PATCH 07/10] Added KnockoutTemplateAnonymous, fixed ko.templateSources.domElement. --- knockout/knockout.d.ts | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/knockout/knockout.d.ts b/knockout/knockout.d.ts index 4428e48ac..7a2fcfd50 100644 --- a/knockout/knockout.d.ts +++ b/knockout/knockout.d.ts @@ -347,22 +347,28 @@ interface KnockoutArrayChange { ////////////////////////////////// interface KnockoutTemplateSourcesDomElement { + text(): any; + text(value: any): void; - text(valueToWrite?: any): any; - - data(key: string, valueToWrite?: any): any; + data(key: string): any; + data(key: string, value: any): any; } +interface KnockoutTemplateAnonymous extends KnockoutTemplateSourcesDomElement { + nodes(): any; + nodes(value: any): void; +} interface KnockoutTemplateSources { - domElement: KnockoutTemplateSourcesDomElement; + domElement: { + prototype: KnockoutTemplateSourcesDomElement + new (element: Element): KnockoutTemplateSourcesDomElement + }; anonymousTemplate: { - - prototype: KnockoutTemplateSourcesDomElement; - - new (element: Element): KnockoutTemplateSourcesDomElement; + prototype: KnockoutTemplateAnonymous; + new (element: Element): KnockoutTemplateAnonymous; }; } @@ -550,6 +556,7 @@ interface KnockoutComponents { clearCachedDefinition(componentName: string): void defaultLoader: KnockoutComponentLoader; loaders: KnockoutComponentLoader[]; + getComponentNameForNode(node: Node): string; } interface KnockoutComponentDefinition { From e001f7dd6eacf9e574702e18c4856d3b4fd0a785 Mon Sep 17 00:00:00 2001 From: Igor Oleinikov Date: Sat, 28 Jun 2014 19:40:45 +0400 Subject: [PATCH 08/10] Version bump to 3.2.0-beta. --- 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 7a2fcfd50..ec569049e 100644 --- a/knockout/knockout.d.ts +++ b/knockout/knockout.d.ts @@ -1,6 +1,6 @@ -// Type definitions for Knockout 2.3 +// Type definitions for Knockout v3.2.0-beta // Project: http://knockoutjs.com -// Definitions by: Boris Yankov +// Definitions by: Boris Yankov , Igor Oleinikov // Definitions: https://github.com/borisyankov/DefinitelyTyped From 3f015d97e103b082b4cd7f8cd637881c49032980 Mon Sep 17 00:00:00 2001 From: Igor Oleinikov Date: Sat, 28 Jun 2014 19:49:55 +0400 Subject: [PATCH 09/10] Fixed ko.bindingProvider. --- knockout/knockout.d.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/knockout/knockout.d.ts b/knockout/knockout.d.ts index ec569049e..9c581cd27 100644 --- a/knockout/knockout.d.ts +++ b/knockout/knockout.d.ts @@ -528,7 +528,10 @@ interface KnockoutStatic { ///////////////////////////////// - bindingProvider: KnockoutBindingProvider; + bindingProvider: { + instance: KnockoutBindingProvider; + new (): KnockoutBindingProvider; + } ///////////////////////////////// // selectExtensions.js From 416505eb3ed5d9c753f9ef6ca00f19ec2663f44a Mon Sep 17 00:00:00 2001 From: Igor Oleinikov Date: Sat, 28 Jun 2014 19:57:23 +0400 Subject: [PATCH 10/10] Fixed tests/knockout-templatingBehaviors-tests.ts. --- knockout/knockout.d.ts | 2 +- knockout/tests/knockout-templatingBehaviors-tests.ts | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/knockout/knockout.d.ts b/knockout/knockout.d.ts index 9c581cd27..9b86be44d 100644 --- a/knockout/knockout.d.ts +++ b/knockout/knockout.d.ts @@ -548,7 +548,7 @@ interface KnockoutStatic { interface KnockoutBindingProvider { nodeHasBindings(node: Node): boolean; getBindings(node: Node, bindingContext: KnockoutBindingContext): {}; - getBindingAccessors(node: Node, bindingContext: KnockoutBindingContext): { [key: string]: string; }; + getBindingAccessors?(node: Node, bindingContext: KnockoutBindingContext): { [key: string]: string; }; } interface KnockoutComponents { diff --git a/knockout/tests/knockout-templatingBehaviors-tests.ts b/knockout/tests/knockout-templatingBehaviors-tests.ts index 7be02d4cd..50ec27572 100644 --- a/knockout/tests/knockout-templatingBehaviors-tests.ts +++ b/knockout/tests/knockout-templatingBehaviors-tests.ts @@ -363,11 +363,11 @@ describe('Templating', function() { // and external (non-rewritten) ones var originalBindingProvider = ko.bindingProvider.instance; ko.bindingProvider.instance = { - nodeHasBindings: function(node, bindingContext) { - return (node.tagName == 'EM') || originalBindingProvider.nodeHasBindings(node, bindingContext); + nodeHasBindings: function(node) { + return ((node).tagName == 'EM') || originalBindingProvider.nodeHasBindings(node); }, getBindings: function(node, bindingContext) { - if (node.tagName == 'EM') + if ((node).tagName == 'EM') return { text: ++model.numBindings }; return originalBindingProvider.getBindings(node, bindingContext); }