Design with multiple changes and only one update
Each time data is modified, dependency updates of the data are triggered. So, if you make three changes, you should call the update function three times, but it will only be called once.
Data change monitor
If the data changes, the set method is used, and then dep.notify is executed
Depend on the update
- If a property in data is modified in the event callback, the dependency will be updated and watcher.update will be executed.
- If the watcher attribute is changed, it is the same watcher. If the watcher attribute is changed, it is the same watcher. If the watcher is changed, it is the same Watcher.
Vue nextTick source code analysis
General execution steps:
- Place registered callback functions in the Callbacks queue;
- Check whether pending is executed;
- Watcher.run () performs dependency updates;
- Watcher.prototype.update calls nextTick;
- Calling vue.$nextTick manually is like adding a queue to callbacks. Callbacks iterate through each registration event, including water. Update patchNode, before executing the second nextTick callback. Therefore, nextTick implements asynchronous update, and the updated content of DOM nodes can be obtained from nextTick.
nextTick
- Cb callbacks are pushed into the Callbacks array through uniform processing
- Execute asynchronous delay function and set flag bit to judge
- Returns a promise-like call when nextTick passes no function arguments
flushCallbacks
FlushCallbacks is used to execute the callback function in callbacks
- Copy the callbacks
- Empty the original callbacks
- Iterate through the replicated Callbacks and execute them one by one
Vue series of courses
Vue source code analysis will be conducted in succession recently, a series of courses are as follows:
The state series
- Principle of props
- Principle of the methods
- Principle of the data
- Principles of the computed
- Watch the principle
Lifecycle series
- Life cycle principle
The event series
- Principle of the event
Render series
- Render principle
Inject/dojo.provide series
- Inject/dojo.provide principle
The plugins series
- Vue – principle of the router
- Vue Router stuff
- Vuex something you should know
- Vue source code analysis of vuex principle
- Vue custom plug-in
Component series
- Keep alive – principle
- Vue single file component
- Communication between Vue components
- Vue virtual list
Series of instructions
- Vue custom command
- Caching principles for vue source code parsing
The algorithm series
- Principle of diff
- Vue compiler source code analysis
Asynchronous tasks
- NextTick principle of vUE source code parsing
other
- Vue unit tests
- Vue multicast components
- Things you didn’t know about Vue
- Vue skills big decryption