Add virtual-dom tests and fix syntax to appease DT's automated checkers

This commit is contained in:
Christopher Brown 2015-06-10 12:29:45 -05:00
parent 1e2a1e22e5
commit df507c636c
2 changed files with 51 additions and 8 deletions

View File

@ -0,0 +1,33 @@
/// <reference path="virtual-dom.d.ts" />
import virtual_dom = require("virtual-dom");
import VNode = virtual_dom.VNode;
import h = virtual_dom.h;
function renderAny(object: any): VNode {
if (object === undefined) {
return h('i.undefined', 'undefined');
}
else if (object === null) {
return h('b.null', 'null');
}
else if (Array.isArray(object)) {
return h('span.array', ['[', object.map(renderAny), ']']);
}
else if (typeof object === 'object') {
var object_children = Object.keys(object).map(key => {
var child = object[key];
return h('div', [
h('span.key', [key, ':']),
renderAny(child),
]);
});
return h('div.object', object_children);
}
else if (typeof object === 'number') {
return h('span.number', object.toString());
}
else if (typeof object === 'boolean') {
return h('span.boolean', object.toString());
}
return h('span.string', object.toString());
}

View File

@ -1,3 +1,8 @@
// Type definitions for virtual-dom 2.0.1
// Project: https://github.com/Matt-Esch/virtual-dom
// Definitions by: Christopher Brown <https://github.com/chbrown>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
declare module VirtualDOM {
interface VHook {
hook(node: Element, propertyName: string): void;
@ -39,7 +44,7 @@ declare module VirtualDOM {
interface VText {
text: string;
new (text: any);
new(text: any): VText;
version: string;
type: string; // 'VirtualText'
}
@ -71,7 +76,7 @@ declare module VirtualDOM {
// THUNK = 8
// }
interface VPatch {
vNode: VNode,
vNode: VNode;
patch: any;
new(type: number, vNode: VNode, patch: any): VPatch;
version: string;
@ -93,8 +98,8 @@ declare module VirtualDOM {
create() calls either document.createElement() or document.createElementNS(),
for which the common denominator is Element (not HTMLElement).
*/
function create(vnode: VText, opts?: {document?: Document, warn?: boolean}): Text;
function create(vnode: VNode | Widget | Thunk, opts?: {document?: Document, warn?: boolean}): Element;
function create(vnode: VText, opts?: {document?: Document; warn?: boolean}): Text;
function create(vnode: VNode | Widget | Thunk, opts?: {document?: Document; warn?: boolean}): Element;
function h(tagName: string, properties: createProperties, children: string | VChild[]): VNode;
function h(tagName: string, children: string | VChild[]): VNode;
function diff(left: VTree, right: VTree): VPatch[];
@ -106,16 +111,21 @@ declare module VirtualDOM {
}
declare module "virtual-dom/h" {
export = VirtualDOM.h;
// export = VirtualDOM.h; works just fine, but the DT checker doesn't like it
import h = VirtualDOM.h;
export = h;
}
declare module "virtual-dom/create-element" {
export = VirtualDOM.create;
import create = VirtualDOM.create;
export = create;
}
declare module "virtual-dom/diff" {
export = VirtualDOM.diff;
import diff = VirtualDOM.diff;
export = diff;
}
declare module "virtual-dom/patch" {
export = VirtualDOM.patch;
import patch = VirtualDOM.patch;
export = patch;
}
declare module "virtual-dom" {
export = VirtualDOM;