Skip to content

improve: the readability of updateChildren #5670

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

Merged
merged 1 commit into from
May 16, 2017

Conversation

gebilaoxiong
Copy link
Member

What kind of change does this PR introduce? (check at least one)

  • Bugfix
  • Feature
  • Code style update
  • Refactor
  • Build-related changes
  • Other, please describe:

Does this PR introduce a breaking change? (check one)

  • Yes
  • No

If yes, please describe the impact and migration path for existing applications:

The PR fulfills these requirements:

If adding a new feature, the PR's description includes:

  • A convincing reason for adding this feature (to avoid wasting your time, it's best to open a suggestion issue first and wait for approval before working on it)

Other information:

@gebilaoxiong
Copy link
Member Author

gebilaoxiong commented May 14, 2017

Well :

Although elmToMove.elm and newStartVnode.elm are the same thing

But :

When the element index of the old list changes

We operate the old list:

Such as : https://github.com/vuejs/vue/blob/dev/src/core/vdom/patch.js#L389

else if (sameVnode(oldStartVnode, newEndVnode)) { // Vnode moved right
  // ...
  canMove && nodeOps.insertBefore(parentElm, oldStartVnode.elm, nodeOps.nextSibling(oldEndVnode.elm))
  // ...
}

And : https://github.com/vuejs/vue/blob/dev/src/core/vdom/patch.js#L394

else if (sameVnode(oldEndVnode, newStartVnode)) { // Vnode moved left
  // ...
  canMove && nodeOps.insertBefore(parentElm, oldEndVnode.elm, oldStartVnode.elm)
  // ...
}

I think updateChildren is talking about:

Operation the old list, let it become to the new one

So I think there should be use elmToMove.elm, It can make the code easier to understand

@yyx990803 yyx990803 merged commit 34bc14e into vuejs:dev May 16, 2017
@gebilaoxiong gebilaoxiong deleted the improve-patch branch May 16, 2017 01:29
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

Successfully merging this pull request may close these issues.

2 participants