Revert "refactor(core): tree-shake application_module providers (#23477)"

This reverts commit eb031c6ff1.

The change is breaking targets in g3 see cl/194336387.
This commit is contained in:
Igor Minar 2018-04-26 14:08:13 -07:00
parent 1a44a0b4a8
commit 5b96078624
8 changed files with 20 additions and 61 deletions

View File

@ -8,9 +8,7 @@
import {isPromise} from '../src/util/lang';
import {Inject, Injectable, InjectionToken, Optional, inject} from './di';
import {defineInjectable} from './di/defs';
import {Inject, Injectable, InjectionToken, Optional} from './di';
/**
@ -24,22 +22,8 @@ export const APP_INITIALIZER = new InjectionToken<Array<() => void>>('Applicatio
*
* @experimental
*/
@Injectable()
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 reject: Function;
private initialized = false;

View File

@ -6,11 +6,13 @@
* 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 {IterableDiffers, KeyValueDiffers, defaultIterableDiffers, defaultKeyValueDiffers} from './change_detection/change_detection';
import {Inject, Optional, SkipSelf} from './di/metadata';
import {APP_ROOT} from './di/scope';
import {LOCALE_ID} from './i18n/tokens';
import {Compiler} from './linker/compiler';
import {NgModule} from './metadata';
export function _iterableDiffersFactory() {
@ -26,14 +28,17 @@ export function _localeFactory(locale?: string): string {
}
/**
* This module includes the providers of @angular/core that are needed
* to bootstrap components via `ApplicationRef`.
*
* @experimental
*/
@NgModule({
providers: [
ApplicationRef,
ApplicationInitStatus,
Compiler,
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: KeyValueDiffers, useFactory: _keyValueDiffersFactory},
{
@ -44,4 +49,6 @@ export function _localeFactory(locale?: string): string {
]
})
export class ApplicationModule {
// Inject ApplicationRef to make it eager...
constructor(appRef: ApplicationRef) {}
}

View File

@ -16,8 +16,7 @@ import {isPromise} from '../src/util/lang';
import {ApplicationInitStatus} from './application_init';
import {APP_BOOTSTRAP_LISTENER, PLATFORM_INITIALIZER} from './application_tokens';
import {Console} from './console';
import {Injectable, InjectionToken, Injector, StaticProvider, inject} from './di';
import {defineInjectable} from './di/defs';
import {Injectable, InjectionToken, Injector, StaticProvider} from './di';
import {CompilerFactory, CompilerOptions} from './linker/compiler';
import {ComponentFactory, ComponentRef} from './linker/component_factory';
import {ComponentFactoryBoundToModule, ComponentFactoryResolver} from './linker/component_factory_resolver';
@ -362,26 +361,8 @@ function optionsReducer<T extends Object>(dst: any, objs: T | T[]): T {
*
*
*/
@Injectable()
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 */
static _tickScope: WtfScopeFn = wtfCreateScope('ApplicationRef#tick()');
private _bootstrapListeners: ((compRef: ComponentRef<any>) => void)[] = [];

View File

@ -6,8 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import {Injectable, InjectionToken, StaticProvider, inject} from '../di';
import {defineInjectable} from '../di/defs';
import {Injectable, InjectionToken, StaticProvider} from '../di';
import {MissingTranslationStrategy} from '../i18n/tokens';
import {ViewEncapsulation} from '../metadata';
import {Type} from '../type';
@ -16,7 +15,6 @@ import {ComponentFactory} from './component_factory';
import {NgModuleFactory} from './ng_module_factory';
/**
* Combination of NgModuleFactory and ComponentFactorys.
*
@ -43,17 +41,8 @@ function _throwError() {
* of components.
*
*/
@Injectable()
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
* in `entryComponents` have to be inlined.

View File

@ -188,9 +188,6 @@
{
"name": "APP_BOOTSTRAP_LISTENER"
},
{
"name": "APP_INITIALIZER"
},
{
"name": "APP_ROOT"
},

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import {Inject, Injectable, Optional} from '@angular/core';
import {ApplicationRef, Inject, Injectable, Optional} from '@angular/core';
import {DOCUMENT, ɵDomAdapter as DomAdapter, ɵSharedStylesHost as SharedStylesHost, ɵTRANSITION_ID, ɵgetDOM as getDOM} from '@angular/platform-browser';
@Injectable()

View File

@ -5,7 +5,7 @@
* 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 {Compiler, Component, ComponentFactory, ComponentRef, Injector, NgModule, Testability, TestabilityRegistry} from '@angular/core';
import {ApplicationRef, Compiler, Component, ComponentFactory, ComponentRef, Injector, NgModule, Testability, TestabilityRegistry} from '@angular/core';
import {TestBed, getTestBed, inject} from '@angular/core/testing';
import * as angular from '@angular/upgrade/src/common/angular1';
import {DowngradeComponentAdapter, groupNodesBySelector} from '@angular/upgrade/src/common/downgrade_component_adapter';

View File

@ -35,6 +35,7 @@ export declare class ApplicationInitStatus {
/** @experimental */
export declare class ApplicationModule {
constructor(appRef: ApplicationRef);
}
export declare class ApplicationRef {