Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vue源码学习笔记之 Dep 和 Watcher #50

Open
juzhiyuan opened this issue Jul 10, 2018 · 0 comments
Open

Vue源码学习笔记之 Dep 和 Watcher #50

juzhiyuan opened this issue Jul 10, 2018 · 0 comments

Comments

@juzhiyuan
Copy link
Owner

juzhiyuan commented Jul 10, 2018

xingbofeng/xingbofeng.github.io#15

image

在初始化的时候

  1. 首先通过 Object.defineProperty 改写 getter/setterData 注入观察者能力

  2. 在数据被调用的时候,getter 函数触发,调用方(会为调用方创建一个 Watcher)将会被加入到数据的订阅者序列;

  3. 当数据被改写的时候,setter 函数触发,变更将会通知到订阅者(Watcher)序列中,并由 Watcher 触发 re-render。后续的事情就是通过 render function code 生成虚拟 DOM,进行 diff 比对,将不同反应到真实的 DOM 中。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant