static-injector 5.0.2 → 6.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/import/change_detection/scheduling/zoneless_scheduling.d.ts +37 -0
- package/import/change_detection/scheduling/zoneless_scheduling_impl.d.ts +16 -0
- package/import/core_reactivity_export_internal.d.ts +17 -0
- package/import/di/contextual.d.ts +36 -0
- package/{typings → import}/di/create_injector.d.ts +1 -1
- package/{typings → import}/di/forward_ref.d.ts +2 -2
- package/import/di/index.d.ts +3 -0
- package/{typings → import}/di/initializer_token.d.ts +8 -1
- package/{typings → import}/di/inject_switch.d.ts +2 -2
- package/{typings → import}/di/injectable.d.ts +2 -2
- package/{typings → import}/di/injection_token.d.ts +3 -4
- package/{typings → import}/di/injector.d.ts +1 -1
- package/{typings → import}/di/injector_compatibility.d.ts +1 -1
- package/{typings → import}/di/injector_marker.d.ts +1 -1
- package/{typings → import}/di/injector_token.d.ts +1 -1
- package/{typings → import}/di/interface/defs.d.ts +1 -1
- package/{typings → import}/di/interface/injector.d.ts +1 -1
- package/{typings → import}/di/interface/provider.d.ts +1 -1
- package/{typings → import}/di/internal_tokens.d.ts +1 -1
- package/{typings → import}/di/metadata.d.ts +5 -9
- package/{typings → import}/di/null_injector.d.ts +1 -1
- package/{typings → import}/di/provider_collection.d.ts +31 -3
- package/{typings → import}/di/provider_token.d.ts +1 -1
- package/{typings → import}/di/r3_injector.d.ts +2 -2
- package/{typings → import}/di/scope.d.ts +1 -1
- package/{typings → import}/di.d.ts +1 -1
- package/import/error_handler.d.ts +45 -0
- package/{typings → import}/errors.d.ts +9 -7
- package/import/index.d.ts +37 -0
- package/{typings → import}/interface/lifecycle_hooks.d.ts +1 -1
- package/{typings → import}/interface/type.d.ts +4 -9
- package/import/linker/destroy_ref.d.ts +44 -0
- package/import/pending_tasks.d.ts +78 -0
- package/{typings → import}/render3/definition_factory.d.ts +1 -1
- package/{typings → import}/render3/errors_di.d.ts +1 -1
- package/{typings → import}/render3/fields.d.ts +1 -1
- package/{typings → import}/render3/instructions/di.d.ts +1 -1
- package/import/render3/reactivity/api.d.ts +27 -0
- package/import/render3/reactivity/asserts.d.ts +16 -0
- package/import/render3/reactivity/computed.d.ts +25 -0
- package/import/render3/reactivity/effect.d.ts +121 -0
- package/import/render3/reactivity/linked_signal.d.ts +33 -0
- package/import/render3/reactivity/microtask_effect.d.ts +21 -0
- package/import/render3/reactivity/patch.d.ts +11 -0
- package/import/render3/reactivity/root_effect_scheduler.d.ts +54 -0
- package/import/render3/reactivity/signal.d.ts +61 -0
- package/import/render3/reactivity/untracked.d.ts +12 -0
- package/import/resource/api.d.ts +219 -0
- package/{es2022/di/injectable.js → import/resource/index.d.ts} +3 -2
- package/import/resource/resource.d.ts +89 -0
- package/import/util/callback_scheduler.d.ts +35 -0
- package/{typings → import}/util/closure.d.ts +1 -1
- package/{typings → import}/util/decorators.d.ts +3 -3
- package/{typings → import}/util/empty.d.ts +1 -1
- package/{es2022/di/provider_token.js → import/util/noop.d.ts} +2 -2
- package/{typings → import}/util/property.d.ts +1 -1
- package/{typings → import}/util/stringify.d.ts +1 -1
- package/index.js +2349 -0
- package/index.js.map +7 -0
- package/index.mjs +2258 -0
- package/index.mjs.map +7 -0
- package/package.json +22 -11
- package/primitives/signals/index.d.ts +15 -0
- package/primitives/signals/src/computed.d.ts +55 -0
- package/primitives/signals/src/equality.d.ts +15 -0
- package/primitives/signals/src/errors.d.ts +10 -0
- package/primitives/signals/src/graph.d.ts +182 -0
- package/primitives/signals/src/linked_signal.d.ts +72 -0
- package/primitives/signals/src/signal.d.ts +29 -0
- package/primitives/signals/src/watch.d.ts +43 -0
- package/{es2022/di/injector_marker.js → primitives/signals/src/weak_ref.d.ts} +2 -2
- package/readme.md +19 -15
- package/commonjs/index.js +0 -1586
- package/es2022/di/create_injector.js +0 -32
- package/es2022/di/forward_ref.js +0 -80
- package/es2022/di/index.js +0 -1
- package/es2022/di/initializer_token.js +0 -15
- package/es2022/di/inject_switch.js +0 -51
- package/es2022/di/injection_token.js +0 -93
- package/es2022/di/injector.js +0 -60
- package/es2022/di/injector_compatibility.js +0 -265
- package/es2022/di/injector_token.js +0 -20
- package/es2022/di/interface/defs.js +0 -110
- package/es2022/di/interface/injector.js +0 -26
- package/es2022/di/interface/provider.js +0 -10
- package/es2022/di/internal_tokens.js +0 -9
- package/es2022/di/metadata.js +0 -48
- package/es2022/di/null_injector.js +0 -19
- package/es2022/di/provider_collection.js +0 -104
- package/es2022/di/r3_injector.js +0 -449
- package/es2022/di/scope.js +0 -14
- package/es2022/di.js +0 -24
- package/es2022/errors.js +0 -44
- package/es2022/index.js +0 -19
- package/es2022/interface/lifecycle_hooks.js +0 -8
- package/es2022/interface/type.js +0 -21
- package/es2022/render3/definition_factory.js +0 -10
- package/es2022/render3/errors_di.js +0 -13
- package/es2022/render3/fields.js +0 -22
- package/es2022/render3/instructions/di.js +0 -23
- package/es2022/render3/util/stringify_utils.js +0 -38
- package/es2022/util/closure.js +0 -19
- package/es2022/util/decorators.js +0 -31
- package/es2022/util/empty.js +0 -18
- package/es2022/util/property.js +0 -15
- package/es2022/util/stringify.js +0 -45
- package/fesm2022/index.js +0 -1547
- package/typings/di/index.d.ts +0 -1
- package/typings/index.d.ts +0 -18
- package/typings/render3/util/stringify_utils.d.ts +0 -21
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license
|
|
3
|
-
* Copyright Google LLC All Rights Reserved.
|
|
4
|
-
*
|
|
5
|
-
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
-
* found in the LICENSE file at https://angular.io/license
|
|
7
|
-
*/
|
|
8
|
-
import { EMPTY_ARRAY } from '../util/empty';
|
|
9
|
-
import { stringify } from '../util/stringify';
|
|
10
|
-
import { importProvidersFrom } from './provider_collection';
|
|
11
|
-
import { getNullInjector, R3Injector } from './r3_injector';
|
|
12
|
-
/**
|
|
13
|
-
* Create a new `Injector` which is configured using a `defType` of `InjectorType<any>`s.
|
|
14
|
-
*/
|
|
15
|
-
export function createInjector(defType, parent = null, additionalProviders = null, name) {
|
|
16
|
-
const injector = createInjectorWithoutInjectorInstances(defType, parent, additionalProviders, name);
|
|
17
|
-
injector.resolveInjectorInitializers();
|
|
18
|
-
return injector;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Creates a new injector without eagerly resolving its injector types. Can be used in places
|
|
22
|
-
* where resolving the injector types immediately can lead to an infinite loop. The injector types
|
|
23
|
-
* should be resolved at a later point by calling `_resolveInjectorDefTypes`.
|
|
24
|
-
*/
|
|
25
|
-
export function createInjectorWithoutInjectorInstances(defType, parent = null, additionalProviders = null, name, scopes = new Set()) {
|
|
26
|
-
const providers = [
|
|
27
|
-
additionalProviders || EMPTY_ARRAY,
|
|
28
|
-
importProvidersFrom(defType),
|
|
29
|
-
];
|
|
30
|
-
name = name || (typeof defType === 'object' ? undefined : stringify(defType));
|
|
31
|
-
return new R3Injector(providers, parent || getNullInjector(), name || null, scopes);
|
|
32
|
-
}
|
package/es2022/di/forward_ref.js
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license
|
|
3
|
-
* Copyright Google LLC All Rights Reserved.
|
|
4
|
-
*
|
|
5
|
-
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
-
* found in the LICENSE file at https://angular.io/license
|
|
7
|
-
*/
|
|
8
|
-
import { getClosureSafeProperty } from '../util/property';
|
|
9
|
-
import { stringify } from '../util/stringify';
|
|
10
|
-
const __forward_ref__ = getClosureSafeProperty({
|
|
11
|
-
__forward_ref__: getClosureSafeProperty,
|
|
12
|
-
});
|
|
13
|
-
/**
|
|
14
|
-
* Allows to refer to references which are not yet defined.
|
|
15
|
-
*
|
|
16
|
-
* For instance, `forwardRef` is used when the `token` which we need to refer to for the purposes of
|
|
17
|
-
* DI is declared, but not yet defined. It is also used when the `token` which we use when creating
|
|
18
|
-
* a query is not yet defined.
|
|
19
|
-
*
|
|
20
|
-
* `forwardRef` is also used to break circularities in standalone components imports.
|
|
21
|
-
*
|
|
22
|
-
* @usageNotes
|
|
23
|
-
* ### Circular dependency example
|
|
24
|
-
* {@example core/di/ts/forward_ref/forward_ref_spec.ts region='forward_ref'}
|
|
25
|
-
*
|
|
26
|
-
* ### Circular standalone reference import example
|
|
27
|
-
* ```ts
|
|
28
|
-
* @Component({
|
|
29
|
-
* standalone: true,
|
|
30
|
-
* imports: [ChildComponent],
|
|
31
|
-
* selector: 'app-parent',
|
|
32
|
-
* template: `<app-child [hideParent]="hideParent"></app-child>`,
|
|
33
|
-
* })
|
|
34
|
-
* export class ParentComponent {
|
|
35
|
-
* @Input() hideParent: boolean;
|
|
36
|
-
* }
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
* @Component({
|
|
40
|
-
* standalone: true,
|
|
41
|
-
* imports: [CommonModule, forwardRef(() => ParentComponent)],
|
|
42
|
-
* selector: 'app-child',
|
|
43
|
-
* template: `<app-parent *ngIf="!hideParent"></app-parent>`,
|
|
44
|
-
* })
|
|
45
|
-
* export class ChildComponent {
|
|
46
|
-
* @Input() hideParent: boolean;
|
|
47
|
-
* }
|
|
48
|
-
* ```
|
|
49
|
-
*
|
|
50
|
-
* @publicApi
|
|
51
|
-
*/
|
|
52
|
-
export function forwardRef(forwardRefFn) {
|
|
53
|
-
forwardRefFn.__forward_ref__ = forwardRef;
|
|
54
|
-
forwardRefFn.toString = function () {
|
|
55
|
-
return stringify(this());
|
|
56
|
-
};
|
|
57
|
-
return forwardRefFn;
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Lazily retrieves the reference value from a forwardRef.
|
|
61
|
-
*
|
|
62
|
-
* Acts as the identity function when given a non-forward-ref value.
|
|
63
|
-
*
|
|
64
|
-
* @usageNotes
|
|
65
|
-
* ### Example
|
|
66
|
-
*
|
|
67
|
-
* {@example core/di/ts/forward_ref/forward_ref_spec.ts region='resolve_forward_ref'}
|
|
68
|
-
*
|
|
69
|
-
* @see {@link forwardRef}
|
|
70
|
-
* @publicApi
|
|
71
|
-
*/
|
|
72
|
-
export function resolveForwardRef(type) {
|
|
73
|
-
return isForwardRef(type) ? type() : type;
|
|
74
|
-
}
|
|
75
|
-
/** Checks whether a function is wrapped by a `forwardRef`. */
|
|
76
|
-
export function isForwardRef(fn) {
|
|
77
|
-
return (typeof fn === 'function' &&
|
|
78
|
-
fn.hasOwnProperty(__forward_ref__) &&
|
|
79
|
-
fn.__forward_ref__ === forwardRef);
|
|
80
|
-
}
|
package/es2022/di/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license
|
|
3
|
-
* Copyright Google LLC All Rights Reserved.
|
|
4
|
-
*
|
|
5
|
-
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
-
* found in the LICENSE file at https://angular.io/license
|
|
7
|
-
*/
|
|
8
|
-
import { InjectionToken } from './injection_token';
|
|
9
|
-
/**
|
|
10
|
-
* A multi-provider token for initialization functions that will run upon construction of an
|
|
11
|
-
* environment injector.
|
|
12
|
-
*
|
|
13
|
-
* @publicApi
|
|
14
|
-
*/
|
|
15
|
-
export const ENVIRONMENT_INITIALIZER = new InjectionToken('');
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license
|
|
3
|
-
* Copyright Google LLC All Rights Reserved.
|
|
4
|
-
*
|
|
5
|
-
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
-
* found in the LICENSE file at https://angular.io/license
|
|
7
|
-
*/
|
|
8
|
-
import { throwProviderNotFoundError } from '../render3/errors_di';
|
|
9
|
-
import { getInjectableDef } from './interface/defs';
|
|
10
|
-
import { InjectFlags } from './interface/injector';
|
|
11
|
-
/**
|
|
12
|
-
* Current implementation of inject.
|
|
13
|
-
*
|
|
14
|
-
* By default, it is `injectInjectorOnly`, which makes it `Injector`-only aware. It can be changed
|
|
15
|
-
* to `directiveInject`, which brings in the `NodeInjector` system of ivy. It is designed this
|
|
16
|
-
* way for two reasons:
|
|
17
|
-
* 1. `Injector` should not depend on ivy logic.
|
|
18
|
-
* 2. To maintain tree shake-ability we don't want to bring in unnecessary code.
|
|
19
|
-
*/
|
|
20
|
-
let _injectImplementation;
|
|
21
|
-
export function getInjectImplementation() {
|
|
22
|
-
return _injectImplementation;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Sets the current inject implementation.
|
|
26
|
-
*/
|
|
27
|
-
export function setInjectImplementation(impl) {
|
|
28
|
-
const previous = _injectImplementation;
|
|
29
|
-
_injectImplementation = impl;
|
|
30
|
-
return previous;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Injects `root` tokens in limp mode.
|
|
34
|
-
*
|
|
35
|
-
* If no injector exists, we can still inject tree-shakable providers which have `providedIn` set to
|
|
36
|
-
* `"root"`. This is known as the limp mode injection. In such case the value is stored in the
|
|
37
|
-
* injectable definition.
|
|
38
|
-
*/
|
|
39
|
-
export function injectRootLimpMode(token, notFoundValue, flags) {
|
|
40
|
-
const injectableDef = getInjectableDef(token);
|
|
41
|
-
if (injectableDef && injectableDef.providedIn == 'root') {
|
|
42
|
-
return injectableDef.value === undefined
|
|
43
|
-
? (injectableDef.value = injectableDef.factory())
|
|
44
|
-
: injectableDef.value;
|
|
45
|
-
}
|
|
46
|
-
if (flags & InjectFlags.Optional)
|
|
47
|
-
return null;
|
|
48
|
-
if (notFoundValue !== undefined)
|
|
49
|
-
return notFoundValue;
|
|
50
|
-
throwProviderNotFoundError(token, 'Injector');
|
|
51
|
-
}
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license
|
|
3
|
-
* Copyright Google LLC All Rights Reserved.
|
|
4
|
-
*
|
|
5
|
-
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
-
* found in the LICENSE file at https://angular.io/license
|
|
7
|
-
*/
|
|
8
|
-
import { ɵɵdefineInjectable } from './interface/defs';
|
|
9
|
-
/**
|
|
10
|
-
* Creates a token that can be used in a DI Provider.
|
|
11
|
-
*
|
|
12
|
-
* Use an `InjectionToken` whenever the type you are injecting is not reified (does not have a
|
|
13
|
-
* runtime representation) such as when injecting an interface, callable type, array or
|
|
14
|
-
* parameterized type.
|
|
15
|
-
*
|
|
16
|
-
* `InjectionToken` is parameterized on `T` which is the type of object which will be returned by
|
|
17
|
-
* the `Injector`. This provides an additional level of type safety.
|
|
18
|
-
*
|
|
19
|
-
* <div class="alert is-helpful">
|
|
20
|
-
*
|
|
21
|
-
* **Important Note**: Ensure that you use the same instance of the `InjectionToken` in both the
|
|
22
|
-
* provider and the injection call. Creating a new instance of `InjectionToken` in different places,
|
|
23
|
-
* even with the same description, will be treated as different tokens by Angular's DI system,
|
|
24
|
-
* leading to a `NullInjectorError`.
|
|
25
|
-
*
|
|
26
|
-
* </div>
|
|
27
|
-
*
|
|
28
|
-
* <code-example format="typescript" language="typescript" path="injection-token/src/main.ts"
|
|
29
|
-
* region="InjectionToken"></code-example>
|
|
30
|
-
*
|
|
31
|
-
* When creating an `InjectionToken`, you can optionally specify a factory function which returns
|
|
32
|
-
* (possibly by creating) a default value of the parameterized type `T`. This sets up the
|
|
33
|
-
* `InjectionToken` using this factory as a provider as if it was defined explicitly in the
|
|
34
|
-
* application's root injector. If the factory function, which takes zero arguments, needs to inject
|
|
35
|
-
* dependencies, it can do so using the [`inject`](api/core/inject) function.
|
|
36
|
-
* As you can see in the Tree-shakable InjectionToken example below.
|
|
37
|
-
*
|
|
38
|
-
* Additionally, if a `factory` is specified you can also specify the `providedIn` option, which
|
|
39
|
-
* overrides the above behavior and marks the token as belonging to a particular `@NgModule` (note:
|
|
40
|
-
* this option is now deprecated). As mentioned above, `'root'` is the default value for
|
|
41
|
-
* `providedIn`.
|
|
42
|
-
*
|
|
43
|
-
* The `providedIn: NgModule` and `providedIn: 'any'` options are deprecated.
|
|
44
|
-
*
|
|
45
|
-
* @usageNotes
|
|
46
|
-
* ### Basic Examples
|
|
47
|
-
*
|
|
48
|
-
* ### Plain InjectionToken
|
|
49
|
-
*
|
|
50
|
-
* {@example core/di/ts/injector_spec.ts region='InjectionToken'}
|
|
51
|
-
*
|
|
52
|
-
* ### Tree-shakable InjectionToken
|
|
53
|
-
*
|
|
54
|
-
* {@example core/di/ts/injector_spec.ts region='ShakableInjectionToken'}
|
|
55
|
-
*
|
|
56
|
-
* @publicApi
|
|
57
|
-
*/
|
|
58
|
-
export class InjectionToken {
|
|
59
|
-
_desc;
|
|
60
|
-
/** @internal */
|
|
61
|
-
ngMetadataName = 'InjectionToken';
|
|
62
|
-
ɵprov;
|
|
63
|
-
/**
|
|
64
|
-
* @param _desc Description for the token,
|
|
65
|
-
* used only for debugging purposes,
|
|
66
|
-
* it should but does not need to be unique
|
|
67
|
-
* @param options Options for the token's usage, as described above
|
|
68
|
-
*/
|
|
69
|
-
constructor(_desc, options) {
|
|
70
|
-
this._desc = _desc;
|
|
71
|
-
this.ɵprov = undefined;
|
|
72
|
-
if (typeof options == 'number') {
|
|
73
|
-
// This is a special hack to assign __NG_ELEMENT_ID__ to this instance.
|
|
74
|
-
// See `InjectorMarkers`
|
|
75
|
-
}
|
|
76
|
-
else if (options !== undefined) {
|
|
77
|
-
this.ɵprov = ɵɵdefineInjectable({
|
|
78
|
-
token: this,
|
|
79
|
-
providedIn: options.providedIn || 'root',
|
|
80
|
-
factory: options.factory,
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* @internal
|
|
86
|
-
*/
|
|
87
|
-
get multi() {
|
|
88
|
-
return this;
|
|
89
|
-
}
|
|
90
|
-
toString() {
|
|
91
|
-
return `InjectionToken ${this._desc}`;
|
|
92
|
-
}
|
|
93
|
-
}
|
package/es2022/di/injector.js
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license
|
|
3
|
-
* Copyright Google LLC All Rights Reserved.
|
|
4
|
-
*
|
|
5
|
-
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
-
* found in the LICENSE file at https://angular.io/license
|
|
7
|
-
*/
|
|
8
|
-
import { createInjector } from './create_injector';
|
|
9
|
-
import { THROW_IF_NOT_FOUND, ɵɵinject } from './injector_compatibility';
|
|
10
|
-
import { INJECTOR } from './injector_token';
|
|
11
|
-
import { ɵɵdefineInjectable } from './interface/defs';
|
|
12
|
-
import { NullInjector } from './null_injector';
|
|
13
|
-
/**
|
|
14
|
-
* Concrete injectors implement this interface. Injectors are configured
|
|
15
|
-
* with [providers](guide/di/dependency-injection-providers) that associate
|
|
16
|
-
* dependencies of various types with [injection tokens](guide/di/dependency-injection-providers).
|
|
17
|
-
*
|
|
18
|
-
* @see [DI Providers](guide/di/dependency-injection-providers).
|
|
19
|
-
* @see {@link StaticProvider}
|
|
20
|
-
*
|
|
21
|
-
* @usageNotes
|
|
22
|
-
*
|
|
23
|
-
* The following example creates a service injector instance.
|
|
24
|
-
*
|
|
25
|
-
* {@example core/di/ts/provider_spec.ts region='ConstructorProvider'}
|
|
26
|
-
*
|
|
27
|
-
* ### Usage example
|
|
28
|
-
*
|
|
29
|
-
* {@example core/di/ts/injector_spec.ts region='Injector'}
|
|
30
|
-
*
|
|
31
|
-
* `Injector` returns itself when given `Injector` as a token:
|
|
32
|
-
*
|
|
33
|
-
* {@example core/di/ts/injector_spec.ts region='injectInjector'}
|
|
34
|
-
*
|
|
35
|
-
* @publicApi
|
|
36
|
-
*/
|
|
37
|
-
export class Injector {
|
|
38
|
-
static THROW_IF_NOT_FOUND = THROW_IF_NOT_FOUND;
|
|
39
|
-
static NULL = new NullInjector();
|
|
40
|
-
static create(options, parent) {
|
|
41
|
-
if (Array.isArray(options)) {
|
|
42
|
-
return createInjector({ name: '' }, parent, options, '');
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
const name = options.name ?? '';
|
|
46
|
-
return createInjector({ name }, options.parent, options.providers, name);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
/** @nocollapse */
|
|
50
|
-
static ɵprov = /** @pureOrBreakMyCode */ ɵɵdefineInjectable({
|
|
51
|
-
token: Injector,
|
|
52
|
-
providedIn: 'any',
|
|
53
|
-
factory: () => ɵɵinject(INJECTOR),
|
|
54
|
-
});
|
|
55
|
-
/**
|
|
56
|
-
* @internal
|
|
57
|
-
* @nocollapse
|
|
58
|
-
*/
|
|
59
|
-
static __NG_ELEMENT_ID__ = -1 /* InjectorMarkers.Injector */;
|
|
60
|
-
}
|
|
@@ -1,265 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license
|
|
3
|
-
* Copyright Google LLC All Rights Reserved.
|
|
4
|
-
*
|
|
5
|
-
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
-
* found in the LICENSE file at https://angular.io/license
|
|
7
|
-
*/
|
|
8
|
-
import { RuntimeError } from '../errors';
|
|
9
|
-
import { stringify } from '../util/stringify';
|
|
10
|
-
import { resolveForwardRef } from './forward_ref';
|
|
11
|
-
import { getInjectImplementation, injectRootLimpMode } from './inject_switch';
|
|
12
|
-
import { InjectFlags, } from './interface/injector';
|
|
13
|
-
const _THROW_IF_NOT_FOUND = {};
|
|
14
|
-
export const THROW_IF_NOT_FOUND = _THROW_IF_NOT_FOUND;
|
|
15
|
-
/*
|
|
16
|
-
* Name of a property (that we patch onto DI decorator), which is used as an annotation of which
|
|
17
|
-
* InjectFlag this decorator represents. This allows to avoid direct references to the DI decorators
|
|
18
|
-
* in the code, thus making them tree-shakable.
|
|
19
|
-
*/
|
|
20
|
-
const DI_DECORATOR_FLAG = '__NG_DI_FLAG__';
|
|
21
|
-
export const NG_TEMP_TOKEN_PATH = 'ngTempTokenPath';
|
|
22
|
-
const NG_TOKEN_PATH = 'ngTokenPath';
|
|
23
|
-
const NEW_LINE = /\n/gm;
|
|
24
|
-
const NO_NEW_LINE = 'ɵ';
|
|
25
|
-
export const SOURCE = '__source';
|
|
26
|
-
/**
|
|
27
|
-
* Current injector value used by `inject`.
|
|
28
|
-
* - `undefined`: it is an error to call `inject`
|
|
29
|
-
* - `null`: `inject` can be called but there is no injector (limp-mode).
|
|
30
|
-
* - Injector instance: Use the injector for resolution.
|
|
31
|
-
*/
|
|
32
|
-
let _currentInjector = undefined;
|
|
33
|
-
export function getCurrentInjector() {
|
|
34
|
-
return _currentInjector;
|
|
35
|
-
}
|
|
36
|
-
export function setCurrentInjector(injector) {
|
|
37
|
-
const former = _currentInjector;
|
|
38
|
-
_currentInjector = injector;
|
|
39
|
-
return former;
|
|
40
|
-
}
|
|
41
|
-
export function injectInjectorOnly(token, flags = InjectFlags.Default) {
|
|
42
|
-
if (_currentInjector === undefined) {
|
|
43
|
-
throw new RuntimeError(-203 /* RuntimeErrorCode.MISSING_INJECTION_CONTEXT */, null);
|
|
44
|
-
}
|
|
45
|
-
else if (_currentInjector === null) {
|
|
46
|
-
return injectRootLimpMode(token, undefined, flags);
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
const value = _currentInjector.get(token, flags & InjectFlags.Optional ? null : undefined, flags);
|
|
50
|
-
return value;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
export function ɵɵinject(token, flags = InjectFlags.Default) {
|
|
54
|
-
return (getInjectImplementation() || injectInjectorOnly)(resolveForwardRef(token), flags);
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Throws an error indicating that a factory function could not be generated by the compiler for a
|
|
58
|
-
* particular class.
|
|
59
|
-
*
|
|
60
|
-
* The name of the class is not mentioned here, but will be in the generated factory function name
|
|
61
|
-
* and thus in the stack trace.
|
|
62
|
-
*
|
|
63
|
-
* @codeGenApi
|
|
64
|
-
*/
|
|
65
|
-
export function ɵɵinvalidFactoryDep(index) {
|
|
66
|
-
throw new RuntimeError(202 /* RuntimeErrorCode.INVALID_FACTORY_DEPENDENCY */, null);
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* @param token A token that represents a static attribute on the host node that should be injected.
|
|
70
|
-
* @returns Value of the attribute if it exists.
|
|
71
|
-
* @throws If called outside of a supported context or the attribute does not exist.
|
|
72
|
-
*
|
|
73
|
-
* @publicApi
|
|
74
|
-
*/
|
|
75
|
-
/**
|
|
76
|
-
* @param token A token that represents a static attribute on the host node that should be injected.
|
|
77
|
-
* @returns Value of the attribute if it exists, otherwise `null`.
|
|
78
|
-
* @throws If called outside of a supported context.
|
|
79
|
-
*
|
|
80
|
-
* @publicApi
|
|
81
|
-
*/
|
|
82
|
-
/**
|
|
83
|
-
* @param token A token that represents a static attribute on the host node that should be injected.
|
|
84
|
-
* @returns Value of the attribute if it exists.
|
|
85
|
-
* @throws If called outside of a supported context or the attribute does not exist.
|
|
86
|
-
*
|
|
87
|
-
* @publicApi
|
|
88
|
-
*/
|
|
89
|
-
/**
|
|
90
|
-
* Injects a token from the currently active injector.
|
|
91
|
-
* `inject` is only supported in an [injection context](guide/di/dependency-injection-context). It
|
|
92
|
-
* can be used during:
|
|
93
|
-
* - Construction (via the `constructor`) of a class being instantiated by the DI system, such
|
|
94
|
-
* as an `@Injectable` or `@Component`.
|
|
95
|
-
* - In the initializer for fields of such classes.
|
|
96
|
-
* - In the factory function specified for `useFactory` of a `Provider` or an `@Injectable`.
|
|
97
|
-
* - In the `factory` function specified for an `InjectionToken`.
|
|
98
|
-
* - In a stackframe of a function call in a DI context
|
|
99
|
-
*
|
|
100
|
-
* @param token A token that represents a dependency that should be injected.
|
|
101
|
-
* @param flags Optional flags that control how injection is executed.
|
|
102
|
-
* The flags correspond to injection strategies that can be specified with
|
|
103
|
-
* parameter decorators `@Host`, `@Self`, `@SkipSelf`, and `@Optional`.
|
|
104
|
-
* @returns the injected value if operation is successful, `null` otherwise.
|
|
105
|
-
* @throws if called outside of a supported context.
|
|
106
|
-
*
|
|
107
|
-
* @usageNotes
|
|
108
|
-
* In practice the `inject()` calls are allowed in a constructor, a constructor parameter and a
|
|
109
|
-
* field initializer:
|
|
110
|
-
*
|
|
111
|
-
* ```typescript
|
|
112
|
-
* @Injectable({providedIn: 'root'})
|
|
113
|
-
* export class Car {
|
|
114
|
-
* radio: Radio|undefined;
|
|
115
|
-
* // OK: field initializer
|
|
116
|
-
* spareTyre = inject(Tyre);
|
|
117
|
-
*
|
|
118
|
-
* constructor() {
|
|
119
|
-
* // OK: constructor body
|
|
120
|
-
* this.radio = inject(Radio);
|
|
121
|
-
* }
|
|
122
|
-
* }
|
|
123
|
-
* ```
|
|
124
|
-
*
|
|
125
|
-
* It is also legal to call `inject` from a provider's factory:
|
|
126
|
-
*
|
|
127
|
-
* ```typescript
|
|
128
|
-
* providers: [
|
|
129
|
-
* {provide: Car, useFactory: () => {
|
|
130
|
-
* // OK: a class factory
|
|
131
|
-
* const engine = inject(Engine);
|
|
132
|
-
* return new Car(engine);
|
|
133
|
-
* }}
|
|
134
|
-
* ]
|
|
135
|
-
* ```
|
|
136
|
-
*
|
|
137
|
-
* Calls to the `inject()` function outside of the class creation context will result in error. Most
|
|
138
|
-
* notably, calls to `inject()` are disallowed after a class instance was created, in methods
|
|
139
|
-
* (including lifecycle hooks):
|
|
140
|
-
*
|
|
141
|
-
* ```typescript
|
|
142
|
-
* @Component({ ... })
|
|
143
|
-
* export class CarComponent {
|
|
144
|
-
* ngOnInit() {
|
|
145
|
-
* // ERROR: too late, the component instance was already created
|
|
146
|
-
* const engine = inject(Engine);
|
|
147
|
-
* engine.start();
|
|
148
|
-
* }
|
|
149
|
-
* }
|
|
150
|
-
* ```
|
|
151
|
-
*
|
|
152
|
-
* @publicApi
|
|
153
|
-
*/
|
|
154
|
-
export function inject(token, flags = InjectFlags.Default) {
|
|
155
|
-
// The `as any` here _shouldn't_ be necessary, but without it JSCompiler
|
|
156
|
-
// throws a disambiguation error due to the multiple signatures.
|
|
157
|
-
return ɵɵinject(token, convertToBitFlags(flags));
|
|
158
|
-
}
|
|
159
|
-
// Converts object-based DI flags (`InjectOptions`) to bit flags (`InjectFlags`).
|
|
160
|
-
export function convertToBitFlags(flags) {
|
|
161
|
-
if (typeof flags === 'undefined' || typeof flags === 'number') {
|
|
162
|
-
return flags;
|
|
163
|
-
}
|
|
164
|
-
// While TypeScript doesn't accept it without a cast, bitwise OR with false-y values in
|
|
165
|
-
// JavaScript is a no-op. We can use that for a very codesize-efficient conversion from
|
|
166
|
-
// `InjectOptions` to `InjectFlags`.
|
|
167
|
-
return (0 /* InternalInjectFlags.Default */ | // comment to force a line break in the formatter
|
|
168
|
-
(flags.optional && 8 /* InternalInjectFlags.Optional */) |
|
|
169
|
-
0 |
|
|
170
|
-
(flags.self && 2 /* InternalInjectFlags.Self */) |
|
|
171
|
-
(flags.skipSelf &&
|
|
172
|
-
4 /* InternalInjectFlags.SkipSelf */));
|
|
173
|
-
}
|
|
174
|
-
export function injectArgs(types) {
|
|
175
|
-
const args = [];
|
|
176
|
-
for (let i = 0; i < types.length; i++) {
|
|
177
|
-
const arg = resolveForwardRef(types[i]);
|
|
178
|
-
if (Array.isArray(arg)) {
|
|
179
|
-
if (arg.length === 0) {
|
|
180
|
-
throw new RuntimeError(900 /* RuntimeErrorCode.INVALID_DIFFER_INPUT */, null);
|
|
181
|
-
}
|
|
182
|
-
let type = undefined;
|
|
183
|
-
let flags = InjectFlags.Default;
|
|
184
|
-
for (let j = 0; j < arg.length; j++) {
|
|
185
|
-
const meta = arg[j];
|
|
186
|
-
const flag = getInjectFlag(meta);
|
|
187
|
-
if (typeof flag === 'number') {
|
|
188
|
-
// Special case when we handle @Inject decorator.
|
|
189
|
-
if (flag === -1 /* DecoratorFlags.Inject */) {
|
|
190
|
-
type = meta.token;
|
|
191
|
-
}
|
|
192
|
-
else {
|
|
193
|
-
flags |= flag;
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
else {
|
|
197
|
-
type = meta;
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
args.push(ɵɵinject(type, flags));
|
|
201
|
-
}
|
|
202
|
-
else {
|
|
203
|
-
args.push(ɵɵinject(arg));
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
return args;
|
|
207
|
-
}
|
|
208
|
-
/**
|
|
209
|
-
* Attaches a given InjectFlag to a given decorator using monkey-patching.
|
|
210
|
-
* Since DI decorators can be used in providers `deps` array (when provider is configured using
|
|
211
|
-
* `useFactory`) without initialization (e.g. `Host`) and as an instance (e.g. `new Host()`), we
|
|
212
|
-
* attach the flag to make it available both as a static property and as a field on decorator
|
|
213
|
-
* instance.
|
|
214
|
-
*
|
|
215
|
-
* @param decorator Provided DI decorator.
|
|
216
|
-
* @param flag InjectFlag that should be applied.
|
|
217
|
-
*/
|
|
218
|
-
export function attachInjectFlag(decorator, flag) {
|
|
219
|
-
decorator[DI_DECORATOR_FLAG] = flag;
|
|
220
|
-
decorator.prototype[DI_DECORATOR_FLAG] = flag;
|
|
221
|
-
return decorator;
|
|
222
|
-
}
|
|
223
|
-
/**
|
|
224
|
-
* Reads monkey-patched property that contains InjectFlag attached to a decorator.
|
|
225
|
-
*
|
|
226
|
-
* @param token Token that may contain monkey-patched DI flags property.
|
|
227
|
-
*/
|
|
228
|
-
export function getInjectFlag(token) {
|
|
229
|
-
return token[DI_DECORATOR_FLAG];
|
|
230
|
-
}
|
|
231
|
-
export function catchInjectorError(e, token, injectorErrorName, source) {
|
|
232
|
-
const tokenPath = e[NG_TEMP_TOKEN_PATH];
|
|
233
|
-
if (token[SOURCE]) {
|
|
234
|
-
tokenPath.unshift(token[SOURCE]);
|
|
235
|
-
}
|
|
236
|
-
e.message = formatError('\n' + e.message, tokenPath, injectorErrorName, source);
|
|
237
|
-
e[NG_TOKEN_PATH] = tokenPath;
|
|
238
|
-
e[NG_TEMP_TOKEN_PATH] = null;
|
|
239
|
-
throw e;
|
|
240
|
-
}
|
|
241
|
-
export function formatError(text, obj, injectorErrorName, source = null) {
|
|
242
|
-
text =
|
|
243
|
-
text && text.charAt(0) === '\n' && text.charAt(1) == NO_NEW_LINE
|
|
244
|
-
? text.slice(2)
|
|
245
|
-
: text;
|
|
246
|
-
let context = stringify(obj);
|
|
247
|
-
if (Array.isArray(obj)) {
|
|
248
|
-
context = obj.map(stringify).join(' -> ');
|
|
249
|
-
}
|
|
250
|
-
else if (typeof obj === 'object') {
|
|
251
|
-
let parts = [];
|
|
252
|
-
for (let key in obj) {
|
|
253
|
-
if (obj.hasOwnProperty(key)) {
|
|
254
|
-
let value = obj[key];
|
|
255
|
-
parts.push(key +
|
|
256
|
-
':' +
|
|
257
|
-
(typeof value === 'string'
|
|
258
|
-
? JSON.stringify(value)
|
|
259
|
-
: stringify(value)));
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
context = `{${parts.join(', ')}}`;
|
|
263
|
-
}
|
|
264
|
-
return `${injectorErrorName}${source ? '(' + source + ')' : ''}[${context}]: ${text.replace(NEW_LINE, '\n ')}`;
|
|
265
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license
|
|
3
|
-
* Copyright Google LLC All Rights Reserved.
|
|
4
|
-
*
|
|
5
|
-
* Use of this source code is governed by an MIT-style license that can be
|
|
6
|
-
* found in the LICENSE file at https://angular.io/license
|
|
7
|
-
*/
|
|
8
|
-
import { InjectionToken } from './injection_token';
|
|
9
|
-
/**
|
|
10
|
-
* An InjectionToken that gets the current `Injector` for `createInjector()`-style injectors.
|
|
11
|
-
*
|
|
12
|
-
* Requesting this token instead of `Injector` allows `StaticInjector` to be tree-shaken from a
|
|
13
|
-
* project.
|
|
14
|
-
*
|
|
15
|
-
* @publicApi
|
|
16
|
-
*/
|
|
17
|
-
export const INJECTOR = new InjectionToken('',
|
|
18
|
-
// Disable tslint because this is const enum which gets inlined not top level prop access.
|
|
19
|
-
// tslint:disable-next-line: no-toplevel-property-access
|
|
20
|
-
-1 /* InjectorMarkers.Injector */);
|