private-neactor-dom 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +33 -0
  2. package/package.json +9 -0
package/index.js ADDED
@@ -0,0 +1,33 @@
1
+ export function myCreateElement(type, props, ...children) {
2
+ return { type, props, children };
3
+ }
4
+
5
+ export function render(vdom, container) {
6
+ if (typeof vdom === "string") {
7
+ const textNode = document.createTextNode(vdom);
8
+ container.appendChild(textNode);
9
+ } else if (typeof vdom.type === "function") {
10
+ const childDom = vdom.type(vdom.props);
11
+ render(childDom, container);
12
+ } else {
13
+ const element = document.createElement(vdom.type);
14
+ if (vdom.props) {
15
+ Object.keys(vdom.props).map((key) => {
16
+ if (key === "style") {
17
+ Object.assign(element.style, vdom.props.style);
18
+ } else if (key.startsWith("on")) {
19
+ element[key.toLocaleLowerCase()] = vdom.props[key];
20
+ } else {
21
+ element[key] = vdom.props[key];
22
+ }
23
+ });
24
+ }
25
+ if (vdom.children) {
26
+ vdom.children.forEach((child) => {
27
+ render(child, element);
28
+ });
29
+ }
30
+
31
+ container.appendChild(element);
32
+ }
33
+ }
package/package.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "name": "private-neactor-dom",
3
+ "version": "1.0.0",
4
+ "type": "module",
5
+ "main": "./index.js",
6
+ "exports": {
7
+ ".": "./index.js"
8
+ }
9
+ }