UNPKG

injection-js

Version:

Dependency Injection library for JavaScript and TypeScript

1 lines 2.54 kB
{"version":3,"file":"injector.js","sourceRoot":"","sources":["../lib/injector.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAK1C,MAAM,mBAAmB,GAAG,IAAI,MAAM,EAAE,CAAC;AACzC,MAAM,CAAC,MAAM,kBAAkB,GAAG,mBAAmB,CAAC;AAEtD,4DAA4D;AAC5D,MAAM,aAAa;IACjB,GAAG,CAAC,KAAU,EAAE,gBAAqB,mBAAmB;QACtD,IAAI,aAAa,KAAK,mBAAmB,EAAE,CAAC;YAC1C,MAAM,IAAI,KAAK,CAAC,mBAAmB,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC1D,CAAC;QACD,OAAO,aAAa,CAAC;IACvB,CAAC;CACF;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,OAAgB,QAAQ;;AACrB,2BAAkB,GAAG,mBAAmB,CAAC;AACzC,aAAI,GAAa,IAAI,aAAa,EAAE,CAAC","sourcesContent":["/**\n * @license\n * Copyright Google Inc. All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\n\nimport { stringify } from './facade/lang';\nimport { Type } from './facade/type';\n\nimport { InjectionToken } from './injection_token';\n\nconst _THROW_IF_NOT_FOUND = new Object();\nexport const THROW_IF_NOT_FOUND = _THROW_IF_NOT_FOUND;\n\n// tslint:disable-next-line:class-name no-use-before-declare\nclass _NullInjector implements Injector {\n get(token: any, notFoundValue: any = _THROW_IF_NOT_FOUND): any {\n if (notFoundValue === _THROW_IF_NOT_FOUND) {\n throw new Error(`No provider for ${stringify(token)}!`);\n }\n return notFoundValue;\n }\n}\n\n/**\n * @whatItDoes Injector interface\n * @howToUse\n * ```\n * const injector: Injector = ...;\n * injector.get(...);\n * ```\n *\n * @description\n * For more details, see the {@linkDocs guide/dependency-injection \"Dependency Injection Guide\"}.\n *\n * ### Example\n *\n * {@example core/di/ts/injector_spec.ts region='Injector'}\n *\n * `Injector` returns itself when given `Injector` as a token:\n * {@example core/di/ts/injector_spec.ts region='injectInjector'}\n *\n * @stable\n */\nexport abstract class Injector {\n static THROW_IF_NOT_FOUND = _THROW_IF_NOT_FOUND;\n static NULL: Injector = new _NullInjector();\n\n /**\n * Retrieves an instance from the injector based on the provided token.\n * If not found:\n * - Throws {@link NoProviderError} if no `notFoundValue` that is not equal to\n * Injector.THROW_IF_NOT_FOUND is given\n * - Returns the `notFoundValue` otherwise\n */\n abstract get<T>(token: Type<T> | InjectionToken<T>, notFoundValue?: T): T;\n /**\n * @deprecated from v4.0.0 use Type<T> or InjectionToken<T>\n * @suppress {duplicate}\n */\n abstract get(token: any, notFoundValue?: any): any;\n}\n"]}