Skip to content

Commit 83f418e

Browse files
committed
fix event propagation check when chained emits (fix #1839)
1 parent 5fe6e55 commit 83f418e

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/instance/api/events.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,12 @@ export default function (Vue) {
8686
* Trigger an event on self.
8787
*
8888
* @param {String} event
89+
* @return {Boolean} shouldPropagate
8990
*/
9091

9192
Vue.prototype.$emit = function (event) {
9293
var cbs = this._events[event]
93-
this._shouldPropagate = !cbs
94+
var shouldPropagate = !cbs
9495
if (cbs) {
9596
cbs = cbs.length > 1
9697
? toArray(cbs)
@@ -99,11 +100,11 @@ export default function (Vue) {
99100
for (var i = 0, l = cbs.length; i < l; i++) {
100101
var res = cbs[i].apply(this, args)
101102
if (res === true) {
102-
this._shouldPropagate = true
103+
shouldPropagate = true
103104
}
104105
}
105106
}
106-
return this
107+
return shouldPropagate
107108
}
108109

109110
/**
@@ -120,8 +121,8 @@ export default function (Vue) {
120121
var children = this.$children
121122
for (var i = 0, l = children.length; i < l; i++) {
122123
var child = children[i]
123-
child.$emit.apply(child, arguments)
124-
if (child._shouldPropagate) {
124+
var shouldPropagate = child.$emit.apply(child, arguments)
125+
if (shouldPropagate) {
125126
child.$broadcast.apply(child, arguments)
126127
}
127128
}
@@ -139,8 +140,8 @@ export default function (Vue) {
139140
this.$emit.apply(this, arguments)
140141
var parent = this.$parent
141142
while (parent) {
142-
parent.$emit.apply(parent, arguments)
143-
parent = parent._shouldPropagate
143+
var shouldPropagate = parent.$emit.apply(parent, arguments)
144+
parent = shouldPropagate
144145
? parent.$parent
145146
: null
146147
}

src/instance/internal/init.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ export default function (Vue) {
3939
// events bookkeeping
4040
this._events = {} // registered callbacks
4141
this._eventsCount = {} // for $broadcast optimization
42-
this._shouldPropagate = false // for event propagation
4342

4443
// fragment instance properties
4544
this._isFragment = false

0 commit comments

Comments
 (0)