angular/packages/core/src/di/metadata.ts
Miško Hevery b7a6f52d59 perf: latest tsickle to tree shake: abstract class methods & interfaces (#18236)
In previous version of tsickle abstract class methods were materialized.
The change resulted in 6Kb savings in angular.io bundle.

This change also required the removal of `@private` and `@return` type
annotation as it is explicitly dissalowed by tsickle.

NOTE: removed casts in front of `makeDecorator` due to:
https://github.com/angular/devkit/issues/45

```
 14938 Jul 19 13:16 0.b19e913fbdd6507d346b.chunk.js
  1535 Jul 19 13:16 inline.d8e019ea3cfdd86c2bd0.bundle.js
589178 Jul 19 13:16 main.54c97bcb6f254776b678.bundle.js
 34333 Jul 19 13:16 polyfills.4a3c9ca9481d53803157.bundle.js

 14938 Jul 18 16:55 0.b19e913fbdd6507d346b.chunk.js
  1535 Jul 18 16:55 inline.0c83abb44fad9a2768a7.bundle.js
582786 Jul 18 16:55 main.ea290db71b051813e156.bundle.js
 34333 Jul 18 16:55 polyfills.4a3c9ca9481d53803157.bundle.js

main savings: 589178 - 582786 = 6,392
```

PR Close #18236
2017-07-21 16:35:37 -05:00

289 lines
5.7 KiB
TypeScript

/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {makeDecorator, makeParamDecorator} from '../util/decorators';
/**
* Type of the Inject decorator / constructor function.
*
* @stable
*/
export interface InjectDecorator {
/**
* @whatItDoes A parameter decorator that specifies a dependency.
* @howToUse
* ```
* @Injectable()
* class Car {
* constructor(@Inject("MyEngine") public engine:Engine) {}
* }
* ```
*
* @description
* For more details, see the {@linkDocs guide/dependency-injection "Dependency Injection Guide"}.
*
* ### Example
*
* {@example core/di/ts/metadata_spec.ts region='Inject'}
*
* When `@Inject()` is not present, {@link Injector} will use the type annotation of the
* parameter.
*
* ### Example
*
* {@example core/di/ts/metadata_spec.ts region='InjectWithoutDecorator'}
*
* @stable
*/
(token: any): any;
new (token: any): Inject;
}
/**
* Type of the Inject metadata.
*
* @stable
*/
export interface Inject { token: any; }
/**
* Inject decorator and metadata.
*
* @stable
* @Annotation
*/
export const Inject: InjectDecorator = makeParamDecorator('Inject', (token: any) => ({token}));
/**
* Type of the Optional decorator / constructor function.
*
* @stable
*/
export interface OptionalDecorator {
/**
* @whatItDoes A parameter metadata that marks a dependency as optional.
* {@link Injector} provides `null` if the dependency is not found.
* @howToUse
* ```
* @Injectable()
* class Car {
* constructor(@Optional() public engine:Engine) {}
* }
* ```
*
* @description
* For more details, see the {@linkDocs guide/dependency-injection "Dependency Injection Guide"}.
*
* ### Example
*
* {@example core/di/ts/metadata_spec.ts region='Optional'}
*
* @stable
*/
(): any;
new (): Optional;
}
/**
* Type of the Optional metadata.
*
* @stable
*/
export interface Optional {}
/**
* Optional decorator and metadata.
*
* @stable
* @Annotation
*/
export const Optional: OptionalDecorator = makeParamDecorator('Optional');
/**
* Type of the Injectable decorator / constructor function.
*
* @stable
*/
export interface InjectableDecorator {
/**
* @whatItDoes A marker metadata that marks a class as available to {@link Injector} for creation.
* @howToUse
* ```
* @Injectable()
* class Car {}
* ```
*
* @description
* For more details, see the {@linkDocs guide/dependency-injection "Dependency Injection Guide"}.
*
* ### Example
*
* {@example core/di/ts/metadata_spec.ts region='Injectable'}
*
* {@link Injector} will throw an error when trying to instantiate a class that
* does not have `@Injectable` marker, as shown in the example below.
*
* {@example core/di/ts/metadata_spec.ts region='InjectableThrows'}
*
* @stable
*/
(): any;
new (): Injectable;
}
/**
* Type of the Injectable metadata.
*
* @stable
*/
export interface Injectable {}
/**
* Injectable decorator and metadata.
*
* @stable
* @Annotation
*/
export const Injectable: InjectableDecorator = makeDecorator('Injectable');
/**
* Type of the Self decorator / constructor function.
*
* @stable
*/
export interface SelfDecorator {
/**
* @whatItDoes Specifies that an {@link Injector} should retrieve a dependency only from itself.
* @howToUse
* ```
* @Injectable()
* class Car {
* constructor(@Self() public engine:Engine) {}
* }
* ```
*
* @description
* For more details, see the {@linkDocs guide/dependency-injection "Dependency Injection Guide"}.
*
* ### Example
*
* {@example core/di/ts/metadata_spec.ts region='Self'}
*
* @stable
*/
(): any;
new (): Self;
}
/**
* Type of the Self metadata.
*
* @stable
*/
export interface Self {}
/**
* Self decorator and metadata.
*
* @stable
* @Annotation
*/
export const Self: SelfDecorator = makeParamDecorator('Self');
/**
* Type of the SkipSelf decorator / constructor function.
*
* @stable
*/
export interface SkipSelfDecorator {
/**
* @whatItDoes Specifies that the dependency resolution should start from the parent injector.
* @howToUse
* ```
* @Injectable()
* class Car {
* constructor(@SkipSelf() public engine:Engine) {}
* }
* ```
*
* @description
* For more details, see the {@linkDocs guide/dependency-injection "Dependency Injection Guide"}.
*
* ### Example
*
* {@example core/di/ts/metadata_spec.ts region='SkipSelf'}
*
* @stable
*/
(): any;
new (): SkipSelf;
}
/**
* Type of the SkipSelf metadata.
*
* @stable
*/
export interface SkipSelf {}
/**
* SkipSelf decorator and metadata.
*
* @stable
* @Annotation
*/
export const SkipSelf: SkipSelfDecorator = makeParamDecorator('SkipSelf');
/**
* Type of the Host decorator / constructor function.
*
* @stable
*/
export interface HostDecorator {
/**
* @whatItDoes Specifies that an injector should retrieve a dependency from any injector until
* reaching the host element of the current component.
* @howToUse
* ```
* @Injectable()
* class Car {
* constructor(@Host() public engine:Engine) {}
* }
* ```
*
* @description
* For more details, see the {@linkDocs guide/dependency-injection "Dependency Injection Guide"}.
*
* ### Example
*
* {@example core/di/ts/metadata_spec.ts region='Host'}
*
* @stable
*/
(): any;
new (): Host;
}
/**
* Type of the Host metadata.
*
* @stable
*/
export interface Host {}
/**
* Host decorator and metadata.
*
* @stable
* @Annotation
*/
export const Host: HostDecorator = makeParamDecorator('Host');