Skip to content

Commit 673a70f

Browse files
committed
optimize moving a single item in v-for (close #1807)
1 parent e94b3b9 commit 673a70f

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/directives/public/for.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,14 @@ module.exports = {
171171
: start
172172
if (frag.reused && !frag.staggerCb) {
173173
currentPrev = findPrevFrag(frag, start, this.id)
174-
if (currentPrev !== targetPrev) {
174+
if (
175+
currentPrev !== targetPrev && (
176+
!currentPrev ||
177+
// optimization for moving a single item.
178+
// thanks to suggestions by @livoras in #1807
179+
findPrevFrag(currentPrev, start, this.id) !== targetPrev
180+
)
181+
) {
175182
this.move(frag, prevEl)
176183
}
177184
} else {

test/unit/specs/directives/public/for/for_spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -944,7 +944,7 @@ function assertMutations (vm, el, done) {
944944
)
945945
.then(
946946
function () {
947-
vm.items.shift()
947+
vm.items.push(vm.items.shift())
948948
},
949949
assertMarkup
950950
)

0 commit comments

Comments
 (0)