forked from cuixiaorui/mini-vue
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add example test for scheduler
- Loading branch information
1 parent
0e1ec54
commit ce5e5ad
Showing
2 changed files
with
44 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}` | ||
); | ||
}, | ||
}; |