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

快速diff代码问题 #211

Open
hhy0706 opened this issue Jun 27, 2023 · 1 comment
Open

快速diff代码问题 #211

hhy0706 opened this issue Jun 27, 2023 · 1 comment

Comments

@hhy0706
Copy link

hhy0706 commented Jun 27, 2023

1、

const newVNode = {
      type: 'div',
      children: [
        { type: 'p', children: 'world', key: 3 },
       
      ]
    }

    const oldVNode = {
      type: 'div',
      children: [
        { type: 'p', children: '3', key: 3 },
        { type: 'p', children: '2', key: 2 },
        
      ]
    }

使用上面案例代入快速diff案例中,会爆错,应该增加oldVNode ,newVNode 是否为undefined的判断
image

  while (oldVNode.key === newVNode.key) {
          patch(oldVNode, newVNode, container)
          j++;
          oldVNode = oldChildren[j];
          newVNode = newChildren[j];
    
        }

2、
使用该案例不能正常添加新节点,在顺序没有改变(move=false)并且有新节点增加的情况下,不能挂载新节点

 const newVNode = {
      type: 'div',
      children: [
        { type: 'p', children: 'world', key: 3 },
        { type: 'p', children: '1', key: 1 },
        { type: 'p', children: '4', key: 4, },
      ]
    }

    const oldVNode = {
      type: 'div',
      children: [
        { type: 'p', children: '3', key: 3 },
        { type: 'p', children: '2', key: 2 },
        { type: 'p', children: '4', key: 4 },
      ]
    }
@Telanx
Copy link

Telanx commented Nov 27, 2023

#149

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

2 participants