(Vue)
| 9230 | } |
| 9231 | |
| 9232 | function eventsAPI (Vue) { |
| 9233 | /** |
| 9234 | * Listen on the given `event` with `fn`. |
| 9235 | * |
| 9236 | * @param {String} event |
| 9237 | * @param {Function} fn |
| 9238 | */ |
| 9239 | |
| 9240 | Vue.prototype.$on = function (event, fn) { |
| 9241 | (this._events[event] || (this._events[event] = [])).push(fn); |
| 9242 | modifyListenerCount(this, event, 1); |
| 9243 | return this; |
| 9244 | }; |
| 9245 | |
| 9246 | /** |
| 9247 | * Adds an `event` listener that will be invoked a single |
| 9248 | * time then automatically removed. |
| 9249 | * |
| 9250 | * @param {String} event |
| 9251 | * @param {Function} fn |
| 9252 | */ |
| 9253 | |
| 9254 | Vue.prototype.$once = function (event, fn) { |
| 9255 | var self = this; |
| 9256 | function on() { |
| 9257 | self.$off(event, on); |
| 9258 | fn.apply(this, arguments); |
| 9259 | } |
| 9260 | on.fn = fn; |
| 9261 | this.$on(event, on); |
| 9262 | return this; |
| 9263 | }; |
| 9264 | |
| 9265 | /** |
| 9266 | * Remove the given callback for `event` or all |
| 9267 | * registered callbacks. |
| 9268 | * |
| 9269 | * @param {String} event |
| 9270 | * @param {Function} fn |
| 9271 | */ |
| 9272 | |
| 9273 | Vue.prototype.$off = function (event, fn) { |
| 9274 | var cbs; |
| 9275 | // all |
| 9276 | if (!arguments.length) { |
| 9277 | if (this.$parent) { |
| 9278 | for (event in this._events) { |
| 9279 | cbs = this._events[event]; |
| 9280 | if (cbs) { |
| 9281 | modifyListenerCount(this, event, -cbs.length); |
| 9282 | } |
| 9283 | } |
| 9284 | } |
| 9285 | this._events = {}; |
| 9286 | return this; |
| 9287 | } |
| 9288 | // specific event |
| 9289 | cbs = this._events[event]; |
no test coverage detected