diff --git a/demo/24-patch.html b/demo/24-patch.html new file mode 100644 index 0000000..c3b5eca --- /dev/null +++ b/demo/24-patch.html @@ -0,0 +1,127 @@ + + +
+ + + + \ No newline at end of file diff --git a/demo/23-counter.html b/demo/25-counter.html similarity index 100% rename from demo/23-counter.html rename to demo/25-counter.html diff --git a/demo/24-counter-using-render-function-options.html b/demo/26-counter-using-render-function-options.html similarity index 100% rename from demo/24-counter-using-render-function-options.html rename to demo/26-counter-using-render-function-options.html diff --git a/public/patch.excalidraw.png b/public/patch.excalidraw.png index 151bb33..7fd485b 100644 Binary files a/public/patch.excalidraw.png and b/public/patch.excalidraw.png differ diff --git a/slides.md b/slides.md index c6a2aec..2769f77 100644 --- a/slides.md +++ b/slides.md @@ -1351,7 +1351,7 @@ const ast = { } ``` -定义节点类型: +定义节点类型枚举: ```js const NodeTypes = { @@ -2415,9 +2415,36 @@ createApp({ --- +`patch` 函数的实现如下: + +```js +/** + * @param {*} n1 old vnode + * @param {*} n2 new vnode + */ +function patch(n1, n2) { + if (n1.tag === n2.tag) { + // ... + } else { + // ... + } +} +``` + +具体代码和demo见: `24-patch.html` + +--- + +现在,我们已经实现了 **挂载** 和 **更新**,整合之前的代码,接下来再来看下 **计数器** demo 的效果。 + +--- + ## Counter 计数器 -demo: `22-counter.html` +demo: `25-counter.html` + +> 打开 DevTools 的 Elements 查看效果 +