-
Notifications
You must be signed in to change notification settings - Fork 0
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源码解析——diff #19
Comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
diff算法是比较两个节点,这里我们先设老节点1和新节点2分别为n1和n2
基本流程
类型是否相同是按照下面的代码判断的,如果两个vnode的节点
type
和key
相同,则类型相同type
属性,进行后续的判断基本的流程如上,下面我们就各个类型进行具体分析。在__test__文件夹里面找到测试代码
element类型
情况1, 新的根节点, 测试代码如下
直接进入到
processElement
函数内部看一下,这个时候n1为nullmountElement
方法,把n2作为新的节点挂载判断vnode.el是否为空,非空说明是这个静态节点正在被
reused
。只需要克隆这个el即可?在
mountElement
方法中,就把n2挂载到container
节点下面情况2, 两个节点类型不一样, 测试代码如下:
根据上面的分析,n1和n2的节点类型是不一样的.这个时候会吧老节点n1卸载掉,然后把新节点n2挂载.下面会说一下卸载节点的方法
The text was updated successfully, but these errors were encountered: