UNPKG

vue-happy-bus

Version:

Event Bus for Vue2. automatically cancel listening events when destroyed.

8 lines 1.26 kB
/*! name: vue-happy-bus version: 1.0.3 author: tangdaohai@outlook.com github: https://github.com/tangdaohai/vue-happy-bus */ !function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("vue")):"function"==typeof define&&define.amd?define(["exports","vue"],n):n(e["happy-bus"]={},e.Vue$)}(this,function(e,n){"use strict";var o=n=n&&n.hasOwnProperty("default")?n.default:n;"undefined"!=typeof window&&window.Vue&&(o=window.Vue);var i={},r=new o,t=function(){var e=i[this._uid];if(void 0!==e){for(var n in e){var o=Array.isArray(n)?n.join(","):n;r.$off(n,e[o])}delete i[this._uid]}},u=function(e){var n=e.$options.destroyed||[],o=e._uid;return i[o]={},!n.includes(t)&&e.$once("hook:destroyed",t),{$on:function(e,n){var t=Array.isArray(e)?e.join(","):e;i[o][t]=n,r.$on(e,n)},$off:function(e,n){if(!e)return delete i[o],void r.$off();var t=Array.isArray(e)?e.join(","):e;delete i[o][t],r.$off(e,n)},$once:function(){return r.$once.apply(r,arguments)},$emit:function(){return r.$emit.apply(r,arguments)}}};u.$emit=function(){return r.$emit.apply(r,arguments)},u.$once=function(){return r.$once.apply(r,arguments)},e.default=u,e.Bus=r,e.version="1.0.3",Object.defineProperty(e,"__esModule",{value:!0})}); //# sourceMappingURL=true