-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ts
44 lines (41 loc) · 1.28 KB
/
main.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
34
35
36
37
38
39
40
41
42
43
44
import { render } from "./utils/render.js";
import { mount } from "./utils/mount.js";
import { patch } from "./utils/patch.js";
// First timeout for creating virtual DOM elements
setTimeout(() => {
console.log("CREATING VIRTUAL DOM");
const vdom1 = render(
1,
"div",
{ class: "container-1" },
[],
"VDOM 1 Parent text"
);
const vdom2 = render(
2,
"div",
{ class: "container-2" },
[],
"VDOM 2 Parent text"
);
console.log(vdom1);
console.log(vdom2);
console.log("---------------------------------");
// Second timeout for mounting virtual DOM elements
setTimeout(() => {
console.log("MOUNTING VIRTUAL DOM TO THE REAL DOM");
const appElement = document.getElementById("app");
if (appElement) {
mount({ vnode: vdom1, container: appElement });
} else {
console.log("Failed to find the app element in the DOM.");
}
console.log("---------------------------------");
// Third timeout for patching virtual DOM elements
setTimeout(() => {
console.log("PATCHING VIRTUAL DOM ELEMENTS");
patch({ oldVNode: vdom1, newVNode: vdom2 });
console.log("---------------------------------");
}, 2000); // 2 seconds after mounting
}, 2000); // 2 seconds after creating
}, 3000); // Initial 2 seconds delay