Skip to content

Commit

Permalink
Keyed children diff optimization (#663)
Browse files Browse the repository at this point in the history
* Keyed children diff optimization
 * Detect when keyed child matches the next old child
 * Results in fewer "insertBefore" calls
 * Keyed <input> stay focuses

* Inline "next old keyed node" lookup
  • Loading branch information
SkaterDad authored and jorgebucaran committed Apr 6, 2018
1 parent d29c389 commit f16f7fc
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,14 @@ export function app(state, actions, view, container) {
continue
}

if (newKey != null && newKey === getKey(oldChildren[i + 1])) {
if (oldKey == null) {
removeElement(element, oldElements[i], oldChildren[i])
}
i++
continue
}

if (newKey == null || isRecycling) {
if (oldKey == null) {
patch(element, oldElements[i], oldChildren[i], children[k], isSvg)
Expand Down

0 comments on commit f16f7fc

Please sign in to comment.