Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Commit

Permalink
Avoid de-opts in updateChildren
Browse files Browse the repository at this point in the history
  • Loading branch information
Antonio Scandurra committed May 10, 2017
1 parent 3f4c63a commit 4641263
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions lib/patch.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,17 @@ function updateComponent (oldVirtualNode, newVirtualNode, options) {
let mapPool = [new Map(), new Map(), new Map(), new Map()]

function updateChildren (parentElement, oldChildren, newChildren, options) {
let oldStartIndex = 0
let oldEndIndex = oldChildren.length - 1
let oldStartChild = oldChildren[0]
let oldEndChild = oldChildren[oldEndIndex]
var oldStartIndex = 0
var oldEndIndex = oldChildren.length - 1
var oldStartChild = oldChildren[0]
var oldEndChild = oldChildren[oldEndIndex]

let newStartIndex = 0
let newEndIndex = newChildren.length - 1
let newStartChild = newChildren[0]
let newEndChild = newChildren[newEndIndex]
var newStartIndex = 0
var newEndIndex = newChildren.length - 1
var newStartChild = newChildren[0]
var newEndChild = newChildren[newEndIndex]

let oldIndicesByKey
var oldIndicesByKey

while (oldStartIndex <= oldEndIndex && newStartIndex <= newEndIndex) {
if (!oldStartChild) {
Expand Down Expand Up @@ -102,13 +102,13 @@ function updateChildren (parentElement, oldChildren, newChildren, options) {
mapOldKeysToIndices(oldIndicesByKey, oldChildren, oldStartIndex, oldEndIndex)
}

const key = getKey(newStartChild)
const oldIndex = key ? oldIndicesByKey.get(key) : null
var key = getKey(newStartChild)
var oldIndex = key ? oldIndicesByKey.get(key) : null
if (oldIndex == null) {
parentElement.insertBefore(render(newStartChild, options), oldStartChild.domNode)
newStartChild = newChildren[++newStartIndex]
} else {
const oldChildToMove = oldChildren[oldIndex]
var oldChildToMove = oldChildren[oldIndex]
patch(oldChildToMove, newStartChild, options)
oldChildren[oldIndex] = undefined
parentElement.insertBefore(oldChildToMove.domNode, oldStartChild.domNode)
Expand All @@ -118,13 +118,13 @@ function updateChildren (parentElement, oldChildren, newChildren, options) {
}

if (oldStartIndex > oldEndIndex) {
const subsequentElement = newChildren[newEndIndex + 1] ? newChildren[newEndIndex + 1].domNode : null
var subsequentElement = newChildren[newEndIndex + 1] ? newChildren[newEndIndex + 1].domNode : null
for (let i = newStartIndex; i <= newEndIndex; i++) {
parentElement.insertBefore(render(newChildren[i], options), subsequentElement)
}
} else if (newStartIndex > newEndIndex) {
for (let i = oldStartIndex; i <= oldEndIndex; i++) {
const child = oldChildren[i]
var child = oldChildren[i]
if (child) removeVirtualNode(child, options && options.refs)
}
}
Expand Down

0 comments on commit 4641263

Please sign in to comment.