Merge pull request #2427 from Igorbek/knockout-3.1

Knockout 3.2.0-beta
This commit is contained in:
Igorbek
2014-06-28 20:01:30 +04:00
2 changed files with 95 additions and 22 deletions
+92 -19
View File
@@ -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 <https://github.com/borisyankov/>
// Definitions by: Boris Yankov <https://github.com/borisyankov/>, Igor Oleinikov <https://github.com/Igorbek/>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
@@ -64,11 +64,12 @@ interface KnockoutComputedStatic {
<T>(): KnockoutComputed<T>;
<T>(func: () => T, context?: any, options?: any): KnockoutComputed<T>;
<T>(def: KnockoutComputedDefine<T>): KnockoutComputed<T>;
(options?: any): KnockoutComputed<any>;
<T>(def: KnockoutComputedDefine<T>, context?: any): KnockoutComputed<T>;
(options?: any, context?: any): KnockoutComputed<any>;
}
interface KnockoutComputed<T> extends KnockoutObservable<T>, KnockoutComputedFunctions<T> {
fn: KnockoutComputedFunctions<any>;
dispose(): void;
isActive(): boolean;
@@ -109,6 +110,7 @@ interface KnockoutComputedDefine<T> {
disposeWhen? (): boolean;
owner?: any;
deferEvaluation?: boolean;
pure?: boolean;
}
interface KnockoutBindingContext {
@@ -165,7 +167,10 @@ interface KnockoutBindingHandlers {
uniqueName: KnockoutBindingHandler;
// Rendering templates
template: KnockoutBindingHandler;
template: KnockoutBindingHandler;
// Components (new for v3.2)
component: KnockoutBindingHandler;
}
interface KnockoutMemoization {
@@ -190,7 +195,12 @@ interface KnockoutVirtualElements {
interface KnockoutExtenders {
throttle(target: any, timeout: number): KnockoutComputed<any>;
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;
trackArrayChanges(target: any): any;
}
interface KnockoutUtils {
@@ -337,22 +347,28 @@ interface KnockoutArrayChange<T> {
//////////////////////////////////
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;
};
}
@@ -387,17 +403,28 @@ 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;
observable: KnockoutObservableStatic;
computed: KnockoutComputedStatic;
computed: KnockoutComputedStatic;
pureComputed<T>(evaluatorFunction: () => T, context?: any): KnockoutComputed<T>;
pureComputed<T>(options: KnockoutComputedDefine<T>, context?: any): KnockoutComputed<T>;
observableArray: KnockoutObservableArrayStatic;
contextFor(node: any): any;
@@ -412,7 +439,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
@@ -499,7 +528,10 @@ interface KnockoutStatic {
/////////////////////////////////
bindingProvider: any;
bindingProvider: {
instance: KnockoutBindingProvider;
new (): KnockoutBindingProvider;
}
/////////////////////////////////
// selectExtensions.js
@@ -513,6 +545,47 @@ interface KnockoutStatic {
};
}
interface KnockoutBindingProvider {
nodeHasBindings(node: Node): boolean;
getBindings(node: Node, bindingContext: KnockoutBindingContext): {};
getBindingAccessors?(node: Node, bindingContext: KnockoutBindingContext): { [key: string]: string; };
}
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
defaultLoader: KnockoutComponentLoader;
loaders: KnockoutComponentLoader[];
getComponentNameForNode(node: Node): string;
}
interface KnockoutComponentDefinition {
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 {
template: any;
createViewModel?: any;
}
interface KnockoutComputedContext {
getDependenciesCount(): number;
isInitial: boolean;
isSleeping: boolean;
}
declare module "knockout" {
export = ko;
}
@@ -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 ((<Element>node).tagName == 'EM') || originalBindingProvider.nodeHasBindings(node);
},
getBindings: function(node, bindingContext) {
if (node.tagName == 'EM')
if ((<Element>node).tagName == 'EM')
return { text: ++model.numBindings };
return originalBindingProvider.getBindings(node, bindingContext);
}