forked from Matt-Esch/virtual-dom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathh.js
43 lines (32 loc) · 916 Bytes
/
h.js
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
35
36
37
38
39
40
41
42
43
var extend = require("extend")
var isArray = require("./lib/is-array")
var isString = require("./lib/is-string")
var parseTag = require("./lib/parse-tag")
var VirtualDOMNode = require("./virtual-dom-node.js")
module.exports = h
function h(tagName, properties, children) {
var childNodes = []
var tag, props
if (!children) {
if (isChildren(properties)) {
children = properties
props = {}
}
}
props = props || extend({}, properties)
tag = parseTag(tagName, props)
if (children) {
if (isArray(children)) {
childNodes.push.apply(childNodes, children)
} else {
childNodes.push(children)
}
}
return new VirtualDOMNode(tag, props, childNodes)
}
function isChild(x) {
return isString(x) || (x instanceof VirtualDOMNode)
}
function isChildren(x) {
return isChild(x) || isArray(x)
}