UNPKG

@airgram/vue

Version:
46 lines (45 loc) 1.8 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); function installMixin(Vue) { Vue.mixin({ beforeCreate: function () { var options = this.$options; var optionValue = options.airgramProvider; if (optionValue) { this.$_airgramProvider = typeof optionValue === 'function' ? optionValue() : optionValue; } else if (options.parent && options.parent.$_airgramProvider) { this.$_airgramProvider = options.parent.$_airgramProvider; } }, created: function () { var _this = this; var airgramProvider = this.$_airgramProvider; if (this.$_airgramSubscriptions || !airgramProvider) { return; } this.$_airgramSubscriptions = []; // Prepare properties var handlers = this.$options.airgram; if (handlers && !this.$isServer) { Object.keys(handlers).forEach(function (name) { if (name.charAt(0) !== '$' && _this.$_airgramSubscriptions) { var handler = handlers[name]; _this.$_airgramSubscriptions.push(airgramProvider.on(name, handler)); } }); } }, destroyed: function () { if (this.$_airgramDollar) { this.$_airgramDollar._destroy(); delete this.$_airgramDollar; } if (this.$_airgramSubscriptions) { this.$_airgramSubscriptions.forEach(function (unsubscribe) { return unsubscribe(); }); delete this.$_airgramSubscriptions; } } }); } exports.installMixin = installMixin;