Vue Source Code Interpret
What is change detection?
Implications: Change detection is an update of the data or tracking state, and if a change occurs, it is immediately followed by a change.
Angularity: The angularity is varied by a dirty value detection procedure.
REACT: React is the process of making changes via virtual dom.
VUE: VUE have their own set of change detections.
No.1
No.1.1 Make object data change become observal。
No.1.1.1 Pass object.DefinedProperty() of get() make only get then pass set() make changes
Notice: We give each value add up once index
No.2
What is dependency collection
Dependency collection is who dependency this data, we will just take control of who put in this dependency midst, like then when this data happened changes we just control each dependency all infrom once pass
No.2.1
When gather dependency? When from dependency?
We know data flow is pass get updata later set up data like that we in getter medium dependency, in setter medium setter dependency.
No.2.2
Dependency on earth who’s?
in vue medium also realization once call watcher type when who used this watcher dependency time when this data happen changes, this dependency will to conduct data update
-summarize
First we use Object.definedProperty() function realize the right object of data conduct observability. Meanwhile, packaging observer type makes it easier for us to control object medium of all property including all children of property all transform getter or setter of from to carry on change detection.
hereafter we study what dependency collection is? Meanwhile, we know getter medium gather dependency.
in setter medium infrom dependency also packaging management dep use for deposit dependency
The process is as follows:
- data pass observer change into getter/setter proceed follow up change.
- When from outside pass watcher only gets data, meet trigger getter thus will watcher add dependency medium.
- When data happen meet trigger setter thus towards dep medium (watcher) send infrom.
- watcher receive from meet outwards send infrom transform from arrive outside likely trigger update view as likely trigger user some callback function.
Array dependency collection
summarize: array dependency collection also in getter medium get.
array none setter function in proceed gather dependency but pass array of seven pieces built-in of methods come proceed rewrite
summarize: first we analyze array type also getter medium gather dependency, then we discover array be visit of time we very easily know but modification we be not easy know for solve the problem we create array methods interceptor thus success of see array of observability
Vue medium of virtual dom
- What is virtual dom?
virtual dom is once js use object to describe dom node - Why have virtual dom?
We know virtual dom is data drive view of data update, happen update of in view happen, inescapability need operation virtual dom, operation true dom expend more of performance, so this precisely why we have virtual of cause.
Vnode of type
1.1 comment node
1.2 text node
1.3 element node
1.4 component node
1.5 function component node
1.6 clone node
Vue medium of DOM-Diff of arithmetic
create node
Create node only three kinds have access to: comment node text node element node
summarize: dom diff arithmetic patch course create node delete node renewal node
updata children node
optimization updata node
Divide into four parts
- front children node array of all untreated children node new front call (新前)
- front children node array of all untreated children node new later call (新后)
- raw children node array of all untreated child node of once children node raw front call (旧前)
- raw children node array of all untreated child node of once children node raw later call (旧后)
---------- ok we have finished updata child node --------
NO.1
What is a template compile?
user in template label medium of write type analogy proteins html of content conduct compile, control protogenesis html of content find out, reput wrong protogenesis html find out, pass a series of logical processing generate function, namely render function of this one passage course call by template compile flow.
The whole process
user write of template
template compile
render function
vnode
patch
view
The first three call template complie the behind three call virtual dom
template interior flow user write of template resolveroptimizingcode generationrenderer apply function
template compile flow template analysis optimizing stack generation stage