8000 $dispatch: should also trigger event on self · jslegers/vue@b4a3a63 · GitHub
[go: up one dir, main page]

Skip to content

Commit b4a3a63

Browse files
committed
$dispatch: should also trigger event on self
1 parent 2f0945b commit b4a3a63

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

src/api/events.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ exports.$broadcast = function (event) {
134134
*/
135135

136136
exports.$dispatch = function () {
137+
this.$emit.apply(this, arguments)
137138
var parent = this.$parent
138139
while (parent) {
139140
parent.$emit.apply(parent, arguments)

test/unit/specs/api/events_spec.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,11 @@ describe('Events API', function () {
134134
it('$dispatch', function () {
135135
var child = vm.$addChild()
136136
var child2 = child.$addChild()
137+
child2.$on('test', spy)
137138
child.$on('test', spy)
138139
vm.$on('test', spy)
139140
child2.$dispatch('test')
140-
expect(spy.calls.count()).toBe(1) // should not propagate by default
141+
expect(spy.calls.count()).toBe(2) // should trigger on self, but not propagate to root
141142
})
142143

143144
it('$dispatch with propagation', function () {

0 commit comments

Comments
 (0)
0