-
Notifications
You must be signed in to change notification settings - Fork 0
/
ReactDOM.ts
33 lines (29 loc) · 902 Bytes
/
ReactDOM.ts
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
import { stateCursor, globalState } from './index';
export default {
render: function (reactElementOrStringOrNumber, container: HTMLElement) {
const actualDOMElement: HTMLElement = document.createElement(
reactElementOrStringOrNumber.type
);
if (['string', 'number'].includes(typeof reactElementOrStringOrNumber)) {
container.appendChild(
document.createTextNode(String(reactElementOrStringOrNumber))
);
return;
}
const {
props: { children, ...restProps },
} = reactElementOrStringOrNumber;
for (let key in restProps) {
if (['__self', '__source'].includes(key)) {
continue;
}
actualDOMElement[key] = restProps[key];
}
if (children.length > 0) {
children.forEach((child) => {
this.render(child, actualDOMElement);
});
}
container.appendChild(actualDOMElement);
},
};