vue-inversify-decorator
Version:
PoC of combining vue-class-component and Inversify together
48 lines (43 loc) • 1.51 kB
JavaScript
/*!
* vue-inversify-decorator v0.1.0
* https://github.com/ktsn/vue-inversify-decorator
*
* @license
* Copyright (c) 2017 katashin
* Released under the MIT license
* https://github.com/ktsn/vue-inversify-decorator/blob/master/LICENSE
*/
;
Object.defineProperty(exports, '__esModule', { value: true });
var vueClassComponent = require('vue-class-component');
var containerKey = '__inversify_container__';
var Provide = function (container) { return vueClassComponent.createDecorator(function (options) {
options.mixins = options.mixins || [];
options.mixins.push({
provide: (_a = {},
_a[containerKey] = container,
_a)
});
var _a;
}); };
var Inject = function (identifier) { return function (proto, key) {
var Type;
if (typeof Reflect !== 'undefined' && typeof Reflect.getMetadata === 'function') {
Type = Reflect.getMetadata('design:type', proto, key);
}
return vueClassComponent.createDecorator(function (options, key) {
if (!options.__container_injected__) {
options.mixins = options.mixins || [];
options.mixins.push({
inject: [containerKey]
});
options.__container_injected__ = true;
}
options.computed = options.computed || {};
options.computed[key] = function () {
return this[containerKey].get(identifier || Type);
};
})(proto, key);
}; };
exports.Provide = Provide;
exports.Inject = Inject;