-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateElement.js
More file actions
28 lines (24 loc) · 796 Bytes
/
createElement.js
File metadata and controls
28 lines (24 loc) · 796 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
/**
* create element function
*/
/**
* This creates an object representing a dom node,
* @method render
* @param {string} type this is the element type (i.e "div", "span" etc.)
* @param {Object} props object representing all element props (i.e class, id, href, etc.)
* @param {Object} TODO <= fix this
* @return {object}
*/
const TEXT_ELEMENT = "TEXT ELEMENT";
export const createElement = (type, config, ...rest) => {
const props = Object.assign({}, config);
if (rest.length) {
props.children = rest
.filter(maybeChild => maybeChild != null && maybeChild !== false)
.map(child => child instanceof Object ? child : createTextElement(child));
}
return { type, props };
}
const createTextElement = (value) => {
return createElement(TEXT_ELEMENT, { nodeValue: value });
}