Skip to content

Commit 6dc5985

Browse files
committed
fix binding.unbind() removing wrong subs from dependency
1 parent e1ea3fc commit 6dc5985

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

src/binding.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ BindingProto.unbind = function () {
9595
var subs
9696
while (i--) {
9797
subs = this.deps[i].subs
98-
subs.splice(subs.indexOf(this), 1)
98+
var j = subs.indexOf(this)
99+
if (j > -1) subs.splice(j, 1)
99100
}
100101
}
101102

src/compiler.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,7 @@ CompilerProto.destroy = function () {
909909
if (this.destroyed) return
910910

911911
var compiler = this,
912-
i, key, dir, dirs, binding,
912+
i, j, key, dir, dirs, binding,
913913
vm = compiler.vm,
914914
el = compiler.el,
915915
directives = compiler.dirs,
@@ -933,7 +933,10 @@ CompilerProto.destroy = function () {
933933
// * empty and literal bindings do not have binding.
934934
if (dir.binding && dir.binding.compiler !== compiler) {
935935
dirs = dir.binding.dirs
936-
if (dirs) dirs.splice(dirs.indexOf(dir), 1)
936+
if (dirs) {
937+
j = dirs.indexOf(dir)
938+
if (j > -1) dirs.splice(j, 1)
939+
}
937940
}
938941
dir.unbind()
939942
}
@@ -960,7 +963,8 @@ CompilerProto.destroy = function () {
960963

961964
// remove self from parent
962965
if (parent) {
963-
parent.children.splice(parent.children.indexOf(compiler), 1)
966+
j = parent.children.indexOf(compiler)
967+
if (j > -1) parent.children.splice(j, 1)
964968
}
965969

966970
// finally remove dom element

src/deps-parser.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ function catchDeps (binding) {
1818
// avoid duplicate bindings
1919
(has && has.compiler === dep.compiler) ||
2020
// avoid repeated items as dependency
21-
// since all inside changes trigger array change too
22-
(dep.compiler.repeat && dep.compiler.parent === binding.compiler)
21+
// only when the binding is from self or the parent chain
22+
(dep.compiler.repeat && !isParentOf(dep.compiler, binding.compiler))
2323
) {
2424
return
2525
}
@@ -32,6 +32,18 @@ function catchDeps (binding) {
3232
catcher.off('get')
3333
}
3434

35+
/**
36+
* Test if A is a parent of or equals B
37+
*/
38+
function isParentOf (a, b) {
39+
while (b) {
40+
if (a === b) {
41+
return true
42+
}
43+
b = b.parent
44+
}
45+
}
46+
3547
module.exports = {
3648

3749
/**

0 commit comments

Comments
 (0)