refactor(core): tree-shake application_module providers (#23477)
PR Close #23477
This commit is contained in:
parent
b4c252bcc5
commit
eb031c6ff1
|
@ -8,7 +8,9 @@
|
||||||
|
|
||||||
import {isPromise} from '../src/util/lang';
|
import {isPromise} from '../src/util/lang';
|
||||||
|
|
||||||
import {Inject, Injectable, InjectionToken, Optional} from './di';
|
import {Inject, Injectable, InjectionToken, Optional, inject} from './di';
|
||||||
|
import {defineInjectable} from './di/defs';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -22,8 +24,22 @@ export const APP_INITIALIZER = new InjectionToken<Array<() => void>>('Applicatio
|
||||||
*
|
*
|
||||||
* @experimental
|
* @experimental
|
||||||
*/
|
*/
|
||||||
@Injectable()
|
|
||||||
export class ApplicationInitStatus {
|
export class ApplicationInitStatus {
|
||||||
|
// `ngInjectableDef` is required in core-level code because it sits behind
|
||||||
|
// the injector and any code the loads it inside may run into a dependency
|
||||||
|
// loop (because Injectable is also in core. Do not use the code below
|
||||||
|
// (use @Injectable({ providedIn, factory })) instead...
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
* @nocollapse
|
||||||
|
*/
|
||||||
|
static ngInjectableDef = defineInjectable({
|
||||||
|
providedIn: 'root',
|
||||||
|
factory: function ApplicationInitStatus_Factory() {
|
||||||
|
return new ApplicationInitStatus(inject(APP_INITIALIZER));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
private resolve: Function;
|
private resolve: Function;
|
||||||
private reject: Function;
|
private reject: Function;
|
||||||
private initialized = false;
|
private initialized = false;
|
||||||
|
|
|
@ -6,13 +6,11 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {ApplicationInitStatus} from './application_init';
|
|
||||||
import {ApplicationRef} from './application_ref';
|
|
||||||
import {APP_ID_RANDOM_PROVIDER} from './application_tokens';
|
import {APP_ID_RANDOM_PROVIDER} from './application_tokens';
|
||||||
import {IterableDiffers, KeyValueDiffers, defaultIterableDiffers, defaultKeyValueDiffers} from './change_detection/change_detection';
|
import {IterableDiffers, KeyValueDiffers, defaultIterableDiffers, defaultKeyValueDiffers} from './change_detection/change_detection';
|
||||||
import {Inject, Optional, SkipSelf} from './di/metadata';
|
import {Inject, Optional, SkipSelf} from './di/metadata';
|
||||||
|
import {APP_ROOT} from './di/scope';
|
||||||
import {LOCALE_ID} from './i18n/tokens';
|
import {LOCALE_ID} from './i18n/tokens';
|
||||||
import {Compiler} from './linker/compiler';
|
|
||||||
import {NgModule} from './metadata';
|
import {NgModule} from './metadata';
|
||||||
|
|
||||||
export function _iterableDiffersFactory() {
|
export function _iterableDiffersFactory() {
|
||||||
|
@ -28,17 +26,14 @@ export function _localeFactory(locale?: string): string {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This module includes the providers of @angular/core that are needed
|
|
||||||
* to bootstrap components via `ApplicationRef`.
|
|
||||||
*
|
|
||||||
* @experimental
|
* @experimental
|
||||||
*/
|
*/
|
||||||
@NgModule({
|
@NgModule({
|
||||||
providers: [
|
providers: [
|
||||||
ApplicationRef,
|
|
||||||
ApplicationInitStatus,
|
|
||||||
Compiler,
|
|
||||||
APP_ID_RANDOM_PROVIDER,
|
APP_ID_RANDOM_PROVIDER,
|
||||||
|
// wen-workers need this value to be here since WorkerApp is defined
|
||||||
|
// ontop of this application
|
||||||
|
{provide: APP_ROOT, useValue: true},
|
||||||
{provide: IterableDiffers, useFactory: _iterableDiffersFactory},
|
{provide: IterableDiffers, useFactory: _iterableDiffersFactory},
|
||||||
{provide: KeyValueDiffers, useFactory: _keyValueDiffersFactory},
|
{provide: KeyValueDiffers, useFactory: _keyValueDiffersFactory},
|
||||||
{
|
{
|
||||||
|
@ -49,6 +44,4 @@ export function _localeFactory(locale?: string): string {
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
export class ApplicationModule {
|
export class ApplicationModule {
|
||||||
// Inject ApplicationRef to make it eager...
|
|
||||||
constructor(appRef: ApplicationRef) {}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,8 @@ import {isPromise} from '../src/util/lang';
|
||||||
import {ApplicationInitStatus} from './application_init';
|
import {ApplicationInitStatus} from './application_init';
|
||||||
import {APP_BOOTSTRAP_LISTENER, PLATFORM_INITIALIZER} from './application_tokens';
|
import {APP_BOOTSTRAP_LISTENER, PLATFORM_INITIALIZER} from './application_tokens';
|
||||||
import {Console} from './console';
|
import {Console} from './console';
|
||||||
import {Injectable, InjectionToken, Injector, StaticProvider} from './di';
|
import {Injectable, InjectionToken, Injector, StaticProvider, inject} from './di';
|
||||||
|
import {defineInjectable} from './di/defs';
|
||||||
import {CompilerFactory, CompilerOptions} from './linker/compiler';
|
import {CompilerFactory, CompilerOptions} from './linker/compiler';
|
||||||
import {ComponentFactory, ComponentRef} from './linker/component_factory';
|
import {ComponentFactory, ComponentRef} from './linker/component_factory';
|
||||||
import {ComponentFactoryBoundToModule, ComponentFactoryResolver} from './linker/component_factory_resolver';
|
import {ComponentFactoryBoundToModule, ComponentFactoryResolver} from './linker/component_factory_resolver';
|
||||||
|
@ -361,8 +362,26 @@ function optionsReducer<T extends Object>(dst: any, objs: T | T[]): T {
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@Injectable()
|
|
||||||
export class ApplicationRef {
|
export class ApplicationRef {
|
||||||
|
// `ngInjectableDef` is required in core-level code because it sits behind
|
||||||
|
// the injector and any code the loads it inside may run into a dependency
|
||||||
|
// loop (because Injectable is also in core. Do not use the code below
|
||||||
|
// (use @Injectable({ providedIn, factory })) instead...
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
* @nocollapse
|
||||||
|
*/
|
||||||
|
static ngInjectableDef = defineInjectable({
|
||||||
|
providedIn: 'root',
|
||||||
|
factory: function ApplicationRef_Factory() {
|
||||||
|
// Type as any is used here due to a type-related bug in injector with abstract classes
|
||||||
|
// (#23528)
|
||||||
|
return new ApplicationRef(
|
||||||
|
inject(NgZone), inject(Console), inject(Injector as any), inject(ErrorHandler),
|
||||||
|
inject(ComponentFactoryResolver as any), inject(ApplicationInitStatus));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
/** @internal */
|
/** @internal */
|
||||||
static _tickScope: WtfScopeFn = wtfCreateScope('ApplicationRef#tick()');
|
static _tickScope: WtfScopeFn = wtfCreateScope('ApplicationRef#tick()');
|
||||||
private _bootstrapListeners: ((compRef: ComponentRef<any>) => void)[] = [];
|
private _bootstrapListeners: ((compRef: ComponentRef<any>) => void)[] = [];
|
||||||
|
|
|
@ -6,7 +6,8 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {Injectable, InjectionToken, StaticProvider} from '../di';
|
import {Injectable, InjectionToken, StaticProvider, inject} from '../di';
|
||||||
|
import {defineInjectable} from '../di/defs';
|
||||||
import {MissingTranslationStrategy} from '../i18n/tokens';
|
import {MissingTranslationStrategy} from '../i18n/tokens';
|
||||||
import {ViewEncapsulation} from '../metadata';
|
import {ViewEncapsulation} from '../metadata';
|
||||||
import {Type} from '../type';
|
import {Type} from '../type';
|
||||||
|
@ -15,6 +16,7 @@ import {ComponentFactory} from './component_factory';
|
||||||
import {NgModuleFactory} from './ng_module_factory';
|
import {NgModuleFactory} from './ng_module_factory';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Combination of NgModuleFactory and ComponentFactorys.
|
* Combination of NgModuleFactory and ComponentFactorys.
|
||||||
*
|
*
|
||||||
|
@ -41,8 +43,17 @@ function _throwError() {
|
||||||
* of components.
|
* of components.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@Injectable()
|
|
||||||
export class Compiler {
|
export class Compiler {
|
||||||
|
// `ngInjectableDef` is required in core-level code because it sits behind
|
||||||
|
// the injector and any code the loads it inside may run into a dependency
|
||||||
|
// loop (because Injectable is also in core. Do not use the code below
|
||||||
|
// (use @Injectable({ providedIn, factory })) instead...
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
* @nocollapse
|
||||||
|
*/
|
||||||
|
static ngInjectableDef = defineInjectable({providedIn: 'root', factory: () => new Compiler()});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compiles the given NgModule and all of its components. All templates of the components listed
|
* Compiles the given NgModule and all of its components. All templates of the components listed
|
||||||
* in `entryComponents` have to be inlined.
|
* in `entryComponents` have to be inlined.
|
||||||
|
|
|
@ -188,6 +188,9 @@
|
||||||
{
|
{
|
||||||
"name": "APP_BOOTSTRAP_LISTENER"
|
"name": "APP_BOOTSTRAP_LISTENER"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "APP_INITIALIZER"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "APP_ROOT"
|
"name": "APP_ROOT"
|
||||||
},
|
},
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {ApplicationRef, Inject, Injectable, Optional} from '@angular/core';
|
import {Inject, Injectable, Optional} from '@angular/core';
|
||||||
import {DOCUMENT, ɵDomAdapter as DomAdapter, ɵSharedStylesHost as SharedStylesHost, ɵTRANSITION_ID, ɵgetDOM as getDOM} from '@angular/platform-browser';
|
import {DOCUMENT, ɵDomAdapter as DomAdapter, ɵSharedStylesHost as SharedStylesHost, ɵTRANSITION_ID, ɵgetDOM as getDOM} from '@angular/platform-browser';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
* Use of this source code is governed by an MIT-style license that can be
|
* 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
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
import {ApplicationRef, Compiler, Component, ComponentFactory, ComponentRef, Injector, NgModule, Testability, TestabilityRegistry} from '@angular/core';
|
import {Compiler, Component, ComponentFactory, ComponentRef, Injector, NgModule, Testability, TestabilityRegistry} from '@angular/core';
|
||||||
import {TestBed, getTestBed, inject} from '@angular/core/testing';
|
import {TestBed, getTestBed, inject} from '@angular/core/testing';
|
||||||
import * as angular from '@angular/upgrade/src/common/angular1';
|
import * as angular from '@angular/upgrade/src/common/angular1';
|
||||||
import {DowngradeComponentAdapter, groupNodesBySelector} from '@angular/upgrade/src/common/downgrade_component_adapter';
|
import {DowngradeComponentAdapter, groupNodesBySelector} from '@angular/upgrade/src/common/downgrade_component_adapter';
|
||||||
|
|
|
@ -35,7 +35,6 @@ export declare class ApplicationInitStatus {
|
||||||
|
|
||||||
/** @experimental */
|
/** @experimental */
|
||||||
export declare class ApplicationModule {
|
export declare class ApplicationModule {
|
||||||
constructor(appRef: ApplicationRef);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export declare class ApplicationRef {
|
export declare class ApplicationRef {
|
||||||
|
|
Loading…
Reference in New Issue