Skip to content

Commit 278e7b1

Browse files
committed
improve prop two-way lock
1 parent 75c7e55 commit 278e7b1

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

src/directives/prop.js

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,26 @@ module.exports = {
1717
// without this it would stabilize too, but this makes
1818
// sure it doesn't cause other watchers to re-evaluate.
1919
var locked = false
20+
function withLock (fn) {
21+
return function (val) {
22+
if (!locked) {
23+
locked = true
24+
fn(val)
25+
_.nextTick(function () {
26+
locked = false
27+
})
28+
}
29+
}
30+
}
2031

2132
this.parentWatcher = new Watcher(
2233
parent,
2334
parentKey,
24-
function (val) {
25-
if (!locked) {
26-
locked = true
27-
// all props have been initialized already
28-
if (_.assertProp(prop, val)) {
29-
child[childKey] = val
30-
}
31-
locked = false
35+
withLock(function (val) {
36+
if (_.assertProp(prop, val)) {
37+
child[childKey] = val
3238
}
33-
}
39+
})
3440
)
3541

3642
// set the child initial value first, before setting
@@ -47,13 +53,9 @@ module.exports = {
4753
this.childWatcher = new Watcher(
4854
child,
4955
childKey,
50-
function (val) {
51-
if (!locked) {
52-
locked = true
53-
parent.$set(parentKey, val)
54-
locked = false
55-
}
56-
}
56+
withLock(function (val) {
57+
parent.$set(parentKey, val)
58+
})
5759
)
5860
}
5961
},

0 commit comments

Comments
 (0)