UNPKG

@snap/camera-kit

Version:
37 lines 1.84 kB
export function Injectable(token, dependenciesOrFn, maybeFn) { const dependencies = Array.isArray(dependenciesOrFn) ? dependenciesOrFn : []; const fn = typeof dependenciesOrFn === "function" ? dependenciesOrFn : maybeFn; if (!fn) { throw new TypeError("[Injectable] Received invalid arguments. The factory function must be either the second " + "or third argument."); } if (fn.length !== dependencies.length) { throw new TypeError("[Injectable] Function arity does not match the number of dependencies. Function has arity " + `${fn.length}, but ${dependencies.length} dependencies were specified.` + `\nDependencies: ${JSON.stringify(dependencies)}`); } const factory = (...args) => fn(...args); factory.token = token; factory.dependencies = dependencies; return factory; } export function ConcatInjectable(token, dependenciesOrFn, maybeFn) { const dependencies = Array.isArray(dependenciesOrFn) ? dependenciesOrFn : []; const fn = typeof dependenciesOrFn === "function" ? dependenciesOrFn : maybeFn; if (!fn) { throw new TypeError("[ConcatInjectable] Received invalid arguments. The factory function must be either the second " + "or third argument."); } if (fn.length !== dependencies.length) { throw new TypeError("[Injectable] Function arity does not match the number of dependencies. Function has arity " + `${fn.length}, but ${dependencies.length} dependencies were specified.` + `\nDependencies: ${JSON.stringify(dependencies)}`); } const factory = (array, ...args) => { return array.concat(fn(...args)); }; factory.token = token; factory.dependencies = [token, ...dependencies]; return factory; } //# sourceMappingURL=Injectable.js.map