diff --git a/goldens/size-tracking/aio-payloads.json b/goldens/size-tracking/aio-payloads.json index 96cfbaaf1021..502f3d0583b2 100755 --- a/goldens/size-tracking/aio-payloads.json +++ b/goldens/size-tracking/aio-payloads.json @@ -15,7 +15,7 @@ "master": { "uncompressed": { "runtime": 4343, - "main": 451244, + "main": 450840, "polyfills": 37297, "styles": 70379, "light-theme": 77582, diff --git a/goldens/size-tracking/integration-payloads.json b/goldens/size-tracking/integration-payloads.json index e4c2eee5906c..a1209e46be23 100644 --- a/goldens/size-tracking/integration-payloads.json +++ b/goldens/size-tracking/integration-payloads.json @@ -3,7 +3,7 @@ "master": { "uncompressed": { "runtime": 1083, - "main": 127944, + "main": 126218, "polyfills": 37226 } } @@ -24,7 +24,7 @@ "master": { "uncompressed": { "runtime": 1105, - "main": 133608, + "main": 131882, "polyfills": 37248 } } @@ -33,7 +33,7 @@ "master": { "uncompressed": { "runtime": 929, - "main": 126275, + "main": 124544, "polyfills": 37933 } } @@ -42,7 +42,7 @@ "master": { "uncompressed": { "runtime": 2835, - "main": 231989, + "main": 231381, "polyfills": 37244, "src_app_lazy_lazy_module_ts": 795 } @@ -52,7 +52,7 @@ "master": { "uncompressed": { "runtime": 1063, - "main": 159637, + "main": 158556, "polyfills": 36975 } } @@ -61,7 +61,7 @@ "master": { "uncompressed": { "runtime": 1070, - "main": 159755, + "main": 158300, "polyfills": 37242 } } diff --git a/packages/core/src/application_init.ts b/packages/core/src/application_init.ts index b9a46d6f75fc..418de8832f18 100644 --- a/packages/core/src/application_init.ts +++ b/packages/core/src/application_init.ts @@ -7,6 +7,7 @@ */ import {Observable} from 'rxjs'; + import {Inject, Injectable, InjectionToken, Optional} from './di'; import {isObservable, isPromise} from './util/lang'; import {noop} from './util/noop'; @@ -91,7 +92,7 @@ export const APP_INITIALIZER = * * @publicApi */ -@Injectable() +@Injectable({providedIn: 'root'}) export class ApplicationInitStatus { private resolve = noop; private reject = noop; diff --git a/packages/core/src/application_module.ts b/packages/core/src/application_module.ts index ec6abbbb067b..e8b1c21f628f 100644 --- a/packages/core/src/application_module.ts +++ b/packages/core/src/application_module.ts @@ -6,110 +6,17 @@ * found in the LICENSE file at https://angular.io/license */ -import {APP_INITIALIZER, ApplicationInitStatus} from './application_init'; import {ApplicationRef} from './application_ref'; -import {APP_ID_RANDOM_PROVIDER} from './application_tokens'; -import {Injector, StaticProvider} from './di'; -import {Inject, Optional, SkipSelf} from './di/metadata'; -import {ErrorHandler} from './error_handler'; -import {DEFAULT_LOCALE_ID, USD_CURRENCY_CODE} from './i18n/localization'; -import {DEFAULT_CURRENCY_CODE, LOCALE_ID} from './i18n/tokens'; -import {ComponentFactoryResolver} from './linker'; -import {Compiler} from './linker/compiler'; import {NgModule} from './metadata'; -import {SCHEDULER} from './render3/component_ref'; -import {NgZone} from './zone'; -declare const $localize: {locale?: string}; - -export function _localeFactory(locale?: string): string { - return locale || getGlobalLocale(); -} /** - * Work out the locale from the potential global properties. - * - * * Closure Compiler: use `goog.getLocale()`. - * * Ivy enabled: use `$localize.locale` - */ -export function getGlobalLocale(): string { - if (typeof ngI18nClosureMode !== 'undefined' && ngI18nClosureMode && - typeof goog !== 'undefined' && goog.getLocale() !== 'en') { - // * The default `goog.getLocale()` value is `en`, while Angular used `en-US`. - // * In order to preserve backwards compatibility, we use Angular default value over - // Closure Compiler's one. - return goog.getLocale(); - } else { - // KEEP `typeof $localize !== 'undefined' && $localize.locale` IN SYNC WITH THE LOCALIZE - // COMPILE-TIME INLINER. - // - // * During compile time inlining of translations the expression will be replaced - // with a string literal that is the current locale. Other forms of this expression are not - // guaranteed to be replaced. - // - // * During runtime translation evaluation, the developer is required to set `$localize.locale` - // if required, or just to provide their own `LOCALE_ID` provider. - return (typeof $localize !== 'undefined' && $localize.locale) || DEFAULT_LOCALE_ID; - } -} - -/** - * A built-in [dependency injection token](guide/glossary#di-token) - * that is used to configure the root injector for bootstrapping. - */ -export const APPLICATION_MODULE_PROVIDERS: StaticProvider[] = [ - { - provide: ApplicationRef, - useClass: ApplicationRef, - deps: [NgZone, Injector, ErrorHandler, ComponentFactoryResolver, ApplicationInitStatus] - }, - {provide: SCHEDULER, deps: [NgZone], useFactory: zoneSchedulerFactory}, - { - provide: ApplicationInitStatus, - useClass: ApplicationInitStatus, - deps: [[new Optional(), APP_INITIALIZER]] - }, - {provide: Compiler, useClass: Compiler, deps: []}, - APP_ID_RANDOM_PROVIDER, - { - provide: LOCALE_ID, - useFactory: _localeFactory, - deps: [[new Inject(LOCALE_ID), new Optional(), new SkipSelf()]] - }, - {provide: DEFAULT_CURRENCY_CODE, useValue: USD_CURRENCY_CODE}, -]; - -/** - * Schedule work at next available slot. - * - * In Ivy this is just `requestAnimationFrame`. For compatibility reasons when bootstrapped - * using `platformRef.bootstrap` we need to use `NgZone.onStable` as the scheduling mechanism. - * This overrides the scheduling mechanism in Ivy to `NgZone.onStable`. - * - * @param ngZone NgZone to use for scheduling. - */ -export function zoneSchedulerFactory(ngZone: NgZone): (fn: () => void) => void { - let queue: (() => void)[] = []; - ngZone.onStable.subscribe(() => { - while (queue.length) { - queue.pop()!(); - } - }); - return function(fn: () => void) { - queue.push(fn); - }; -} - -/** - * Configures the root injector for an app with - * providers of `@angular/core` dependencies that `ApplicationRef` needs - * to bootstrap components. - * * Re-exported by `BrowserModule`, which is included automatically in the root - * `AppModule` when you create a new app with the CLI `new` command. + * `AppModule` when you create a new app with the CLI `new` command. Eagerly injects + * `ApplicationRef` to instantiate it. * * @publicApi */ -@NgModule({providers: APPLICATION_MODULE_PROVIDERS}) +@NgModule() export class ApplicationModule { // Inject ApplicationRef to make it eager... constructor(appRef: ApplicationRef) {} diff --git a/packages/core/src/application_ref.ts b/packages/core/src/application_ref.ts index a32adb13b327..7b4d19e8a824 100644 --- a/packages/core/src/application_ref.ts +++ b/packages/core/src/application_ref.ts @@ -564,7 +564,7 @@ function optionsReducer(dst: any, objs: T|T[]): T { * * @publicApi */ -@Injectable() +@Injectable({providedIn: 'root'}) export class ApplicationRef { /** @internal */ private _bootstrapListeners: ((compRef: ComponentRef) => void)[] = []; diff --git a/packages/core/src/application_tokens.ts b/packages/core/src/application_tokens.ts index 659fa27efe47..f3cd917b6628 100644 --- a/packages/core/src/application_tokens.ts +++ b/packages/core/src/application_tokens.ts @@ -21,7 +21,10 @@ import {ComponentRef} from './linker/component_factory'; * * @publicApi */ -export const APP_ID = new InjectionToken('AppId'); +export const APP_ID = new InjectionToken('AppId', { + providedIn: 'root', + factory: _appIdRandomProviderFactory, +}); export function _appIdRandomProviderFactory() { return `${_randomChar()}${_randomChar()}${_randomChar()}`; diff --git a/packages/core/src/i18n/tokens.ts b/packages/core/src/i18n/tokens.ts index 3edce10b30c1..5a898a475833 100644 --- a/packages/core/src/i18n/tokens.ts +++ b/packages/core/src/i18n/tokens.ts @@ -7,6 +7,39 @@ */ import {InjectionToken} from '../di/injection_token'; +import {inject} from '../di/injector_compatibility'; +import {InjectFlags} from '../di/interface/injector'; + +import {DEFAULT_LOCALE_ID, USD_CURRENCY_CODE} from './localization'; + +declare const $localize: {locale?: string}; + +/** + * Work out the locale from the potential global properties. + * + * * Closure Compiler: use `goog.getLocale()`. + * * Ivy enabled: use `$localize.locale` + */ +export function getGlobalLocale(): string { + if (typeof ngI18nClosureMode !== 'undefined' && ngI18nClosureMode && + typeof goog !== 'undefined' && goog.getLocale() !== 'en') { + // * The default `goog.getLocale()` value is `en`, while Angular used `en-US`. + // * In order to preserve backwards compatibility, we use Angular default value over + // Closure Compiler's one. + return goog.getLocale(); + } else { + // KEEP `typeof $localize !== 'undefined' && $localize.locale` IN SYNC WITH THE LOCALIZE + // COMPILE-TIME INLINER. + // + // * During compile time inlining of translations the expression will be replaced + // with a string literal that is the current locale. Other forms of this expression are not + // guaranteed to be replaced. + // + // * During runtime translation evaluation, the developer is required to set `$localize.locale` + // if required, or just to provide their own `LOCALE_ID` provider. + return (typeof $localize !== 'undefined' && $localize.locale) || DEFAULT_LOCALE_ID; + } +} /** * Provide this token to set the locale of your application. @@ -30,7 +63,11 @@ import {InjectionToken} from '../di/injection_token'; * * @publicApi */ -export const LOCALE_ID = new InjectionToken('LocaleId'); +export const LOCALE_ID: InjectionToken = new InjectionToken('LocaleId', { + providedIn: 'root', + factory: () => + inject(LOCALE_ID, InjectFlags.Optional | InjectFlags.SkipSelf) || getGlobalLocale(), +}); /** * Provide this token to set the default currency code your application uses for @@ -70,7 +107,10 @@ export const LOCALE_ID = new InjectionToken('LocaleId'); * * @publicApi */ -export const DEFAULT_CURRENCY_CODE = new InjectionToken('DefaultCurrencyCode'); +export const DEFAULT_CURRENCY_CODE = new InjectionToken('DefaultCurrencyCode', { + providedIn: 'root', + factory: () => USD_CURRENCY_CODE, +}); /** * Use this token at bootstrap to provide the content of your translation file (`xtb`, diff --git a/packages/core/src/linker/compiler.ts b/packages/core/src/linker/compiler.ts index 0fb22a1c75dd..74377a0f6b8c 100644 --- a/packages/core/src/linker/compiler.ts +++ b/packages/core/src/linker/compiler.ts @@ -52,7 +52,7 @@ export class ModuleWithComponentFactories { * See [JIT API changes due to ViewEngine deprecation](guide/deprecations#jit-api-changes) for * additional context. */ -@Injectable() +@Injectable({providedIn: 'root'}) export class Compiler { /** * Compiles the given NgModule and all of its components. All templates of the components listed diff --git a/packages/core/src/render3/component_ref.ts b/packages/core/src/render3/component_ref.ts index 131303d61cae..69540a69aee0 100644 --- a/packages/core/src/render3/component_ref.ts +++ b/packages/core/src/render3/component_ref.ts @@ -7,7 +7,6 @@ */ import {ChangeDetectorRef as ViewEngine_ChangeDetectorRef} from '../change_detection/change_detector_ref'; -import {InjectionToken} from '../di/injection_token'; import {Injector} from '../di/injector'; import {InjectFlags} from '../di/interface/injector'; import {ProviderToken} from '../di/provider_token'; @@ -36,7 +35,6 @@ import {createElementNode, writeDirectClass} from './node_manipulation'; import {extractAttrsAndClassesFromSelector, stringifyCSSSelectorList} from './node_selector_matcher'; import {enterView, leaveView} from './state'; import {setUpAttributes} from './util/attrs_utils'; -import {defaultScheduler} from './util/misc_utils'; import {getTNode} from './util/view_utils'; import {RootViewRef, ViewRef} from './view_ref'; @@ -71,15 +69,6 @@ function getNamespace(elementName: string): string|null { return name === 'svg' ? SVG_NAMESPACE : (name === 'math' ? MATH_ML_NAMESPACE : null); } -/** - * A change detection scheduler token for {@link RootContext}. This token is the default value used - * for the default `RootContext` found in the {@link ROOT_CONTEXT} token. - */ -export const SCHEDULER = new InjectionToken<((fn: () => void) => void)>('SCHEDULER_TOKEN', { - providedIn: 'root', - factory: () => defaultScheduler, -}); - function createChainedInjector(rootViewInjector: Injector, moduleInjector: Injector): Injector { return { get: (token: ProviderToken, notFoundValue?: T, flags?: InjectFlags): T => { diff --git a/packages/core/test/bundling/animations/bundle.golden_symbols.json b/packages/core/test/bundling/animations/bundle.golden_symbols.json index 10a6c69df169..5bc7481a5bba 100644 --- a/packages/core/test/bundling/animations/bundle.golden_symbols.json +++ b/packages/core/test/bundling/animations/bundle.golden_symbols.json @@ -5,18 +5,12 @@ { "name": "ANIMATION_MODULE_TYPE" }, - { - "name": "APPLICATION_MODULE_PROVIDERS" - }, { "name": "APP_BOOTSTRAP_LISTENER" }, { "name": "APP_ID" }, - { - "name": "APP_ID_RANDOM_PROVIDER" - }, { "name": "APP_INITIALIZER" }, @@ -122,9 +116,6 @@ { "name": "CommonModule" }, - { - "name": "Compiler" - }, { "name": "ComponentFactory" }, @@ -152,9 +143,6 @@ { "name": "DASH_CASE_REGEXP" }, - { - "name": "DEFAULT_CURRENCY_CODE" - }, { "name": "DEFAULT_NOOP_PREVIOUS_NODE" }, @@ -236,9 +224,6 @@ { "name": "INJECTOR_SCOPE" }, - { - "name": "Inject" - }, { "name": "InjectFlags" }, @@ -347,9 +332,6 @@ { "name": "NgLocalization" }, - { - "name": "NgModuleFactory2" - }, { "name": "NgModuleRef" }, @@ -380,9 +362,6 @@ { "name": "Observable" }, - { - "name": "Optional" - }, { "name": "PARAM_REGEX" }, @@ -422,9 +401,6 @@ { "name": "RuntimeError" }, - { - "name": "SCHEDULER" - }, { "name": "SELF_TOKEN_REGEX" }, @@ -452,9 +428,6 @@ { "name": "SimpleOuterSubscriber" }, - { - "name": "SkipSelf" - }, { "name": "SpecialCasedStyles" }, @@ -626,9 +599,6 @@ { "name": "applyView" }, - { - "name": "attachInjectFlag" - }, { "name": "attachPatchData" }, @@ -677,6 +647,9 @@ { "name": "collectNativeNodes" }, + { + "name": "compileNgModuleFactory" + }, { "name": "computeStaticStyling" }, @@ -971,6 +944,9 @@ { "name": "initTNodeFlags" }, + { + "name": "inject" + }, { "name": "injectArgs" }, @@ -1121,9 +1097,6 @@ { "name": "makeLambdaFromStates" }, - { - "name": "makeParamDecorator" - }, { "name": "makeRecord" }, diff --git a/packages/core/test/bundling/forms_reactive/bundle.golden_symbols.json b/packages/core/test/bundling/forms_reactive/bundle.golden_symbols.json index 6908726d4206..3e8d39dac393 100644 --- a/packages/core/test/bundling/forms_reactive/bundle.golden_symbols.json +++ b/packages/core/test/bundling/forms_reactive/bundle.golden_symbols.json @@ -2,18 +2,12 @@ { "name": "ALLOW_MULTIPLE_PLATFORMS" }, - { - "name": "APPLICATION_MODULE_PROVIDERS" - }, { "name": "APP_BOOTSTRAP_LISTENER" }, { "name": "APP_ID" }, - { - "name": "APP_ID_RANDOM_PROVIDER" - }, { "name": "APP_INITIALIZER" }, @@ -86,9 +80,6 @@ { "name": "CommonModule" }, - { - "name": "Compiler" - }, { "name": "ComponentFactory" }, @@ -116,9 +107,6 @@ { "name": "ControlContainer" }, - { - "name": "DEFAULT_CURRENCY_CODE" - }, { "name": "DEFAULT_VALUE_ACCESSOR" }, @@ -215,9 +203,6 @@ { "name": "INJECTOR_SCOPE" }, - { - "name": "Inject" - }, { "name": "InjectFlags" }, @@ -437,9 +422,6 @@ { "name": "RuntimeError" }, - { - "name": "SCHEDULER" - }, { "name": "SERVER_TRANSITION_PROVIDERS" }, @@ -1064,6 +1046,9 @@ { "name": "initTNodeFlags" }, + { + "name": "inject" + }, { "name": "injectArgs" }, diff --git a/packages/core/test/bundling/forms_template_driven/bundle.golden_symbols.json b/packages/core/test/bundling/forms_template_driven/bundle.golden_symbols.json index 09efe4baa58b..6244536b5df9 100644 --- a/packages/core/test/bundling/forms_template_driven/bundle.golden_symbols.json +++ b/packages/core/test/bundling/forms_template_driven/bundle.golden_symbols.json @@ -2,18 +2,12 @@ { "name": "ALLOW_MULTIPLE_PLATFORMS" }, - { - "name": "APPLICATION_MODULE_PROVIDERS" - }, { "name": "APP_BOOTSTRAP_LISTENER" }, { "name": "APP_ID" }, - { - "name": "APP_ID_RANDOM_PROVIDER" - }, { "name": "APP_INITIALIZER" }, @@ -92,9 +86,6 @@ { "name": "CommonModule" }, - { - "name": "Compiler" - }, { "name": "ComponentFactory" }, @@ -122,9 +113,6 @@ { "name": "ControlContainer" }, - { - "name": "DEFAULT_CURRENCY_CODE" - }, { "name": "DEFAULT_VALUE_ACCESSOR" }, @@ -206,9 +194,6 @@ { "name": "INJECTOR_SCOPE" }, - { - "name": "Inject" - }, { "name": "InjectFlags" }, @@ -431,9 +416,6 @@ { "name": "RuntimeError" }, - { - "name": "SCHEDULER" - }, { "name": "SERVER_TRANSITION_PROVIDERS" }, @@ -1034,6 +1016,9 @@ { "name": "initTNodeFlags" }, + { + "name": "inject" + }, { "name": "injectArgs" }, diff --git a/packages/core/test/bundling/router/bundle.golden_symbols.json b/packages/core/test/bundling/router/bundle.golden_symbols.json index 7778ed0cfe5b..d039fb765ed9 100644 --- a/packages/core/test/bundling/router/bundle.golden_symbols.json +++ b/packages/core/test/bundling/router/bundle.golden_symbols.json @@ -5,9 +5,6 @@ { "name": "ANALYZE_FOR_ENTRY_COMPONENTS" }, - { - "name": "APPLICATION_MODULE_PROVIDERS" - }, { "name": "APP_BASE_HREF" }, @@ -17,9 +14,6 @@ { "name": "APP_ID" }, - { - "name": "APP_ID_RANDOM_PROVIDER" - }, { "name": "APP_INITIALIZER" }, @@ -137,9 +131,6 @@ { "name": "DATA_URL_PATTERN" }, - { - "name": "DEFAULT_CURRENCY_CODE" - }, { "name": "DEFAULT_SERIALIZER" }, @@ -578,9 +569,6 @@ { "name": "SAFE_URL_PATTERN" }, - { - "name": "SCHEDULER" - }, { "name": "SEGMENT_RE" }, @@ -1358,6 +1346,9 @@ { "name": "initTNodeFlags" }, + { + "name": "inject" + }, { "name": "injectArgs" },