perf(core): Make PlatformLocation tree-shakable (#32154)

Convert `PlatformLocation` into a tree-shakable provider.

PR Close #32154
This commit is contained in:
Misko Hevery
2019-08-22 19:24:00 -07:00
parent 77c382ccba
commit 1537791f06
29 changed files with 307 additions and 297 deletions

View File

@ -6,9 +6,8 @@
* found in the LICENSE file at https://angular.io/license
*/
import {DOCUMENT} from '@angular/common';
import {DOCUMENT, ɵBrowserPlatformLocation as BrowserPlatformLocation} from '@angular/common';
import {Injector, NgZone, PLATFORM_INITIALIZER, StaticProvider} from '@angular/core';
import {ɵBrowserPlatformLocation as BrowserPlatformLocation} from '@angular/platform-browser';
import {MessageBus} from '../shared/message_bus';
import {Serializer} from '../shared/serializer';

View File

@ -6,9 +6,8 @@
* found in the LICENSE file at https://angular.io/license
*/
import {LocationChangeListener} from '@angular/common';
import {LocationChangeListener, ɵBrowserPlatformLocation as BrowserPlatformLocation} from '@angular/common';
import {EventEmitter, Injectable} from '@angular/core';
import {ɵBrowserPlatformLocation as BrowserPlatformLocation} from '@angular/platform-browser';
import {MessageBus} from '../shared/message_bus';
import {ROUTER_CHANNEL} from '../shared/messaging_api';
import {LocationType, Serializer, SerializerTypes} from '../shared/serializer';

View File

@ -7,7 +7,7 @@
*/
import {LOCATION_INITIALIZED, PlatformLocation} from '@angular/common';
import {APP_INITIALIZER, InjectionToken, NgZone} from '@angular/core';
import {APP_INITIALIZER, NgZone, StaticProvider} from '@angular/core';
import {WebWorkerPlatformLocation} from './platform_location';
@ -19,8 +19,8 @@ import {WebWorkerPlatformLocation} from './platform_location';
* @publicApi
* @deprecated platform-webworker is deprecated in Angular and will be removed in version 10
*/
export const WORKER_APP_LOCATION_PROVIDERS = [
{provide: PlatformLocation, useClass: WebWorkerPlatformLocation}, {
export const WORKER_APP_LOCATION_PROVIDERS: StaticProvider[] = [
{ provide: PlatformLocation, useClass: WebWorkerPlatformLocation} as any as StaticProvider, {
provide: APP_INITIALIZER,
useFactory: appInitFnFactory,
multi: true,

View File

@ -7,7 +7,7 @@
*/
import {CommonModule, DOCUMENT, ViewportScroller, ɵNullViewportScroller as NullViewportScroller, ɵPLATFORM_WORKER_APP_ID as PLATFORM_WORKER_APP_ID} from '@angular/common';
import {APP_INITIALIZER, ApplicationModule, ErrorHandler, NgModule, NgZone, PLATFORM_ID, PlatformRef, RendererFactory2, RootRenderer, StaticProvider, createPlatformFactory, platformCore, ɵAPP_ROOT as APP_ROOT} from '@angular/core';
import {APP_INITIALIZER, ApplicationModule, ErrorHandler, NgModule, NgZone, PLATFORM_ID, PlatformRef, RendererFactory2, StaticProvider, createPlatformFactory, platformCore, ɵINJECTOR_SCOPE as INJECTOR_SCOPE} from '@angular/core';
import {ɵBROWSER_SANITIZATION_PROVIDERS as BROWSER_SANITIZATION_PROVIDERS} from '@angular/platform-browser';
import {ON_WEB_WORKER} from './web_workers/shared/api';
@ -20,14 +20,13 @@ import {ServiceMessageBrokerFactory} from './web_workers/shared/service_message_
import {WebWorkerRendererFactory2} from './web_workers/worker/renderer';
import {WorkerDomAdapter} from './web_workers/worker/worker_adapter';
/**
* @publicApi
* @deprecated platform-webworker is deprecated in Angular and will be removed in version 10
*/
export const platformWorkerApp = createPlatformFactory(
platformCore, 'workerApp', [{provide: PLATFORM_ID, useValue: PLATFORM_WORKER_APP_ID}]);
export const platformWorkerApp: (extraProviders?: StaticProvider[] | undefined) => PlatformRef =
createPlatformFactory(
platformCore, 'workerApp', [{provide: PLATFORM_ID, useValue: PLATFORM_WORKER_APP_ID}]);
export function errorHandler(): ErrorHandler {
return new ErrorHandler();
@ -62,7 +61,7 @@ export function setupWebWorker(): void {
@NgModule({
providers: [
BROWSER_SANITIZATION_PROVIDERS,
{provide: APP_ROOT, useValue: true},
{provide: INJECTOR_SCOPE, useValue: 'root'},
Serializer,
{provide: DOCUMENT, useValue: null},
ClientMessageBrokerFactory,