【VUE DIFF 算法原理】

文章详细阐述了Vue.js中的变更检测机制,包括如何使对象数据变得可观察,以及依赖收集的过程。同时,介绍了虚拟DOM的概念和类型,如VNode结构,以及DOM差异算法在更新子节点时的优化策略。此外,还提到了模板编译的过程,从用户编写模板到生成渲染函数的流程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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:

  1. data pass observer change into getter/setter proceed follow up change.
  2. When from outside pass watcher only gets data, meet trigger getter thus will watcher add dependency medium.
  3. When data happen meet trigger setter thus towards dep medium (watcher) send infrom.
  4. 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

  1. What is virtual dom?
    virtual dom is once js use object to describe dom node
  2. 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

  1. front children node array of all untreated children node new front call (新前)
  2. front children node array of all untreated children node new later call (新后)
  3. raw children node array of all untreated child node of once children node raw front call (旧前)
  4. 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

Template analysis course
sunmmarize
Template analysis precisely theory reason by analysis content of characteristic use regular wait way will be effective information analysis come out,reason analysis content different divide into html analysis, text analysis and filtration analysis,when text information of filtration information meanwhile exsit html label medium,so analysis maximum thread function parse medium first apply html analysis parsehtml function sure template string conduct analysis , if in analysis course medium encounter text maybe information filteration again call corrresponding analysis conduct analysis , in the end sure rigth total template string of analysis .

Template analysis total operation divide three stephtml analysis text analysisfilteration analysis
---------- html analysis interior flow mechanism -----
We know analysis html have an entrance is parse, parse interior call parsehtml, parsehtml interior include four functions respectively are start end chars comment four function:
start function when analysis start label call this function
end function analysis end label call this functionchars function analysis text label call this function comment function when analysis annotation label call this function

One side analysis diverse of content one side call correlation of hook function generate corresponding ast node, finally sure total template string transform ast, this is html analysis to do work.

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值