-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
47 lines (38 loc) · 940 Bytes
/
index.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
44
45
46
47
var React = require('react');
function objIsNode(prop) {
if (prop instanceof Array) return true;
return React.isValidElement(prop);
}
function isNode(prop) {
switch (typeof prop) {
case 'number': return true
case 'string': return true
case 'boolean': return !prop
case 'object': return objIsNode(prop)
default: return false
}
}
function component(el, argsObj) {
var args = Array.prototype.slice.call(argsObj);
var props = args[0] || {};
var children = args.slice(1, args.length);
if (isNode(props)) {
children = args;
props = {};
}
if (children.length > 1) {
props.children = children;
} else if (children.length === 1) {
props.children = children[0];
}
return React.createElement(el, props);
}
function dom(el) {
return function() {
return component(el, arguments);
}
}
Object.keys(React.DOM).forEach(function(k) {
dom[k] = dom(k);
});
module.exports = dom;