Skip to content

Commit

Permalink
test: add example test for scheduler
Browse files Browse the repository at this point in the history
  • Loading branch information
cuixiaorui committed Jul 17, 2020
1 parent 0e1ec54 commit ce5e5ad
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 5 deletions.
9 changes: 4 additions & 5 deletions example/App.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { h, ref, reactive } from "../lib/mini-vue.esm.js";
import PatchChildren from "./components/PatchChildren.js"
import PatchChildren from "./components/PatchChildren.js";
import NextTicker from "./components/NextTicker.js";
// import HelloWorld from "./components/HelloWorld.js";
// import { h, ref } from "../../lib/mini-vue.esm.js";

Expand Down Expand Up @@ -35,17 +36,15 @@ import PatchChildren from "./components/PatchChildren.js"
// },
// };




export default {
name: "App",
setup() {},

render() {
return h("div", { tId: 1 }, [
h("p", {}, "主页"),
h(PatchChildren),
// h(PatchChildren),
h(NextTicker),
]);
},
};
40 changes: 40 additions & 0 deletions example/components/NextTicker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// 测试 nextTick 逻辑
import { h, ref } from "../../lib/mini-vue.esm.js";

// 如果 for 循环改变 count 的值 100 次的话
// 会同时触发 100 次的 update 页面逻辑
// 这里可以把 update 页面的逻辑放到微任务中执行
// 避免更改了响应式对象就会执行 update 的逻辑
// 因为只有最后一次调用 update 才是有价值的
window.count = ref(1);

// 如果一个响应式变量同时触发了两个组件的 update
// 会发生什么有趣的事呢?
const Child1 = {
name: "NextTickerChild1",
setup() {},
render() {
return h("div", {}, `child1 count: ${window.count.value}`);
},
};

const Child2 = {
name: "NextTickerChild2",
setup() {},
render() {
return h("div", {}, `child2 count: ${window.count.value}`);
},
};

export default {
name: "NextTicker",
setup() {},
render() {
return h(
"div",
{ tId: "nextTicker" },
[h(Child1), h(Child2)]
// `for nextTick: count: ${window.count.value}`
);
},
};

0 comments on commit ce5e5ad

Please sign in to comment.