mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-09-10 11:40:16 +08:00
Merge pull request #3770 from conficient/master
Refactored knockout components
This commit is contained in:
@@ -605,52 +605,50 @@ function test_allBindingsAccessor() {
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
function test_Components() {
|
||||
|
||||
// test all possible ko.components.register() overloads
|
||||
function test_Register() {
|
||||
// test all possible ko.components.register() overloads
|
||||
// reused parameters
|
||||
var nodeArray = [new Node, new Node];
|
||||
var singleNode = new Node;
|
||||
var viewModelFn = function (params: any) { return <any>null; }
|
||||
|
||||
// ------- string-templates with different viewmodel overloads:
|
||||
// ------- viewmodel overloads:
|
||||
|
||||
// string template and inline function (commonly used in examples)
|
||||
ko.components.register("name", { template: "string-template", viewModel: function (params) { return null; } });
|
||||
// viewModel as inline function (commonly used in examples)
|
||||
ko.components.register("name", { template: "string-template", viewModel: viewModelFn });
|
||||
|
||||
// string template and instance vm
|
||||
// viewModel from shared instance
|
||||
ko.components.register("name", { template: "string-template", viewModel: { instance: null } });
|
||||
|
||||
// string template and createViewModel factory method
|
||||
ko.components.register("name", { template: "string-template", viewModel: { createViewModel: function (params: any, componentInfo: KnockoutComponentInfo) { return null; } } });
|
||||
// viewModel from createViewModel factory method
|
||||
ko.components.register("name", { template: "string-template", viewModel: { createViewModel: function (params: any, componentInfo: KnockoutComponentTypes.ComponentInfo) { return null; } } });
|
||||
|
||||
// string template and require module vm
|
||||
// viewModel from an AMD module
|
||||
ko.components.register("name", { template: "string-template", viewModel: { require: "module" } });
|
||||
|
||||
// ------- non-string templates
|
||||
// ------- template overloads
|
||||
|
||||
// viewmodel as function and four types of template
|
||||
ko.components.register("name", { template: { element: "elementID" }, viewModel: function (params) { return null; } });
|
||||
// Node template for element and inline function (commonly used in examples)
|
||||
ko.components.register("name", { template: { element: singleNode }, viewModel: function (params) { return null; } });
|
||||
// object template for element and inline function (commonly used in examples)
|
||||
ko.components.register("name", { template: nodeArray, viewModel: function (params) { return null; } });
|
||||
// object template for element and inline function (commonly used in examples)
|
||||
ko.components.register("name", { template: { require: "module" }, viewModel: function (params) { return null; } });
|
||||
|
||||
// viewmodel as object, and four types of non-string tempalte
|
||||
ko.components.register("name", { template: { element: "elementID" }, viewModel: { instance: null } });
|
||||
// Node template for element and inline function (commonly used in examples)
|
||||
ko.components.register("name", { template: { element: singleNode }, viewModel: { instance: null } });
|
||||
// object template for element and inline function (commonly used in examples)
|
||||
ko.components.register("name", { template: nodeArray, viewModel: { instance: null } });
|
||||
// object template for element and inline function (commonly used in examples)
|
||||
ko.components.register("name", { template: { require: "module" }, viewModel: { instance: null } });
|
||||
// template from named element
|
||||
ko.components.register("name", { template: { element: "elementID" }, viewModel: viewModelFn });
|
||||
|
||||
// template using single Node
|
||||
ko.components.register("name", { template: { element: singleNode }, viewModel: viewModelFn });
|
||||
|
||||
// template using Node array
|
||||
ko.components.register("name", { template: nodeArray, viewModel: viewModelFn });
|
||||
|
||||
// template using an AMD module
|
||||
ko.components.register("name", { template: { require: "text!module" }, viewModel: viewModelFn });
|
||||
|
||||
// Empty config for registering custom elements that are handled by name convention
|
||||
ko.components.register('name', { /* No config needed */ });
|
||||
ko.components.register('name', { /* No config needed */ });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function testUnwrapUnion() {
|
||||
|
||||
var possibleObs: KnockoutObservable<number> | number;
|
||||
|
||||
Reference in New Issue
Block a user