
No License
TypeScript
2019年07月17日
type NodeType = VNode | string | number
type Attributes = {[key: string]: string | Function }
export interface View<State, Actions> {
(state: State, actions: Actions): VNode;
}
/**
* 仮想DOM
*/
export interface VNode {
nodeName: keyof ElementTagNameMap
attributes: Attributes
children: NodeType[]
}
/**
* 仮想DOMを生成
*/
export function h(
nodeName: keyof ElementTagNameMap,
attributes: Attributes,
...children: NodeType[]
): VNode {
return { nodeName, attributes, children };
}
/**
* リアルDOMを生成
*/
export function createElement(node: NodeType): HTMLElement | Text {
if (!isVNode(node)) {
return document.createTextNode(node.toString());
}
const el = document.createElement(node.nodeName)
}
No one still commented. Please first comment.