UNPKG

@pilotlab/lux-tools

Version:

A luxurious user experience framework, developed by your friends at Pilot.

44 lines 1.38 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); class Injector { static get(key) { return Injector._registry[key]; } static set(key, value) { Injector._registry[key] = value; } } Injector._registry = {}; exports.Injector = Injector; function injectMethod(...keys) { return (target, key, descriptor) => { let originalMethod = descriptor.value; descriptor.value = function (...args) { let add = keys.map((key) => Injector.get(key)); args = args.concat(add); return originalMethod.apply(this, args); }; return descriptor; }; } function injectProperty(...keys) { return (target, key) => { target[key] = Injector.get(keys[0]); }; } exports.injectProperty = injectProperty; function inject(...keys) { return (...args) => { let params = []; for (let i = 0; i < args.length; i++) { args[i] ? params.push(args[i]) : null; } switch (params.length) { case 2: return injectProperty(keys[0]).apply(this, args); case 3: return injectMethod(...keys).apply(this, args); default: throw new Error('Decorators are not valid here!'); } }; } exports.inject = inject; exports.default = Injector; //# sourceMappingURL=index.js.map