-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathjsx.ts
More file actions
34 lines (30 loc) · 929 Bytes
/
Copy pathjsx.ts
File metadata and controls
34 lines (30 loc) · 929 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { elements } from ".";
import { Component } from "./component";
import { div } from "./elements";
import { DefaultOutput, Properties, ElementCreator } from "./dom-builder";
export function createElement(
node: string,
props: Properties<DefaultOutput> | null,
...children: any[]
): Component<{}, DefaultOutput> {
console.log("node", node);
console.log("props", props);
console.log("children", children);
const e: ElementCreator<any> = node in elements ? (<any>elements)[node] : div;
if (props !== null) {
let o = undefined;
if ("output" in props && typeof props === "object") {
o = props.output;
delete props.output;
}
const el = e(props, children);
return o !== undefined ? el.output(o) : el;
}
return e(children);
}
declare global {
namespace JSX {
type IntrinsicElements = { [k in keyof typeof elements]: any };
type Element = Component<any, any>;
}
}