Jelajahi Sumber

events: fix propagation - should propagate when there are no callbacks on current instance

Evan You 10 tahun lalu
induk
melakukan
9facca5c9c
2 mengubah file dengan 3 tambahan dan 2 penghapusan
  1. 1 1
      src/api/events.js
  2. 2 1
      test/unit/specs/api/events_spec.js

+ 1 - 1
src/api/events.js

@@ -87,8 +87,8 @@ exports.$off = function (event, fn) {
  */
 
 exports.$emit = function (event) {
-  this._shouldPropagate = false
   var cbs = this._events[event]
+  this._shouldPropagate = !cbs
   if (cbs) {
     cbs = cbs.length > 1
       ? _.toArray(cbs)

+ 2 - 1
test/unit/specs/api/events_spec.js

@@ -143,12 +143,13 @@ describe('Events API', function () {
   it('$dispatch with propagation', function () {
     var child = vm.$addChild()
     var child2 = child.$addChild()
+    var child3 = child2.$addChild()
     child.$on('test', function () {
       spy()
       return true
     })
     vm.$on('test', spy)
-    child2.$dispatch('test')
+    child3.$dispatch('test')
     expect(spy.calls.count()).toBe(2)
   })