perf: switch angular to use StaticInjector instead of ReflectiveInjector
This change allows ReflectiveInjector to be tree shaken resulting in not needed Reflect polyfil and smaller bundles. Code savings for HelloWorld using Closure: Reflective: bundle.js: 105,864(34,190 gzip) Static: bundle.js: 154,889(33,555 gzip) 645( 2%) BREAKING CHANGE: `platformXXXX()` no longer accepts providers which depend on reflection. Specifically the method signature when from `Provider[]` to `StaticProvider[]`. Example: Before: ``` [ MyClass, {provide: ClassA, useClass: SubClassA} ] ``` After: ``` [ {provide: MyClass, deps: [Dep1,...]}, {provide: ClassA, useClass: SubClassA, deps: [Dep1,...]} ] ``` NOTE: This only applies to platform creation and providers for the JIT compiler. It does not apply to `@Compotent` or `@NgModule` provides declarations. Benchpress note: Previously Benchpress also supported reflective provides, which now require static providers. DEPRECATION: - `ReflectiveInjector` is now deprecated as it will be remove. Use `Injector.create` as a replacement. closes #18496
This commit is contained in:

committed by
Victor Berchet

parent
d9d00bd9b5
commit
fcadbf4bf6
@ -10,9 +10,9 @@ import {ɵAnimationEngine} from '@angular/animations/browser';
|
||||
import {PlatformLocation, ɵPLATFORM_SERVER_ID as PLATFORM_SERVER_ID} from '@angular/common';
|
||||
import {HttpClientModule} from '@angular/common/http';
|
||||
import {platformCoreDynamic} from '@angular/compiler';
|
||||
import {Injectable, InjectionToken, Injector, NgModule, NgZone, PLATFORM_ID, PLATFORM_INITIALIZER, PlatformRef, Provider, RendererFactory2, RootRenderer, Testability, createPlatformFactory, isDevMode, platformCore, ɵALLOW_MULTIPLE_PLATFORMS as ALLOW_MULTIPLE_PLATFORMS} from '@angular/core';
|
||||
import {Injectable, InjectionToken, Injector, NgModule, NgZone, Optional, PLATFORM_ID, PLATFORM_INITIALIZER, PlatformRef, Provider, RendererFactory2, RootRenderer, StaticProvider, Testability, createPlatformFactory, isDevMode, platformCore, ɵALLOW_MULTIPLE_PLATFORMS as ALLOW_MULTIPLE_PLATFORMS} from '@angular/core';
|
||||
import {HttpModule} from '@angular/http';
|
||||
import {BrowserModule, DOCUMENT, ɵSharedStylesHost as SharedStylesHost, ɵgetDOM as getDOM} from '@angular/platform-browser';
|
||||
import {BrowserModule, DOCUMENT, ɵSharedStylesHost as SharedStylesHost, ɵTRANSITION_ID, ɵgetDOM as getDOM} from '@angular/platform-browser';
|
||||
import {NoopAnimationsModule, ɵAnimationRendererFactory} from '@angular/platform-browser/animations';
|
||||
|
||||
import {SERVER_HTTP_PROVIDERS} from './http';
|
||||
@ -27,11 +27,15 @@ function notSupported(feature: string): Error {
|
||||
throw new Error(`platform-server does not support '${feature}'.`);
|
||||
}
|
||||
|
||||
export const INTERNAL_SERVER_PLATFORM_PROVIDERS: Array<any /*Type | Provider | any[]*/> = [
|
||||
export const INTERNAL_SERVER_PLATFORM_PROVIDERS: StaticProvider[] = [
|
||||
{provide: DOCUMENT, useFactory: _document, deps: [Injector]},
|
||||
{provide: PLATFORM_ID, useValue: PLATFORM_SERVER_ID},
|
||||
{provide: PLATFORM_INITIALIZER, useFactory: initParse5Adapter, multi: true, deps: [Injector]},
|
||||
{provide: PlatformLocation, useClass: ServerPlatformLocation}, PlatformState,
|
||||
{provide: PLATFORM_INITIALIZER, useFactory: initParse5Adapter, multi: true, deps: [Injector]}, {
|
||||
provide: PlatformLocation,
|
||||
useClass: ServerPlatformLocation,
|
||||
deps: [DOCUMENT, [Optional, INITIAL_CONFIG]]
|
||||
},
|
||||
{provide: PlatformState, deps: [DOCUMENT]},
|
||||
// Add special provider that allows multiple instances of platformServer* to be created.
|
||||
{provide: ALLOW_MULTIPLE_PLATFORMS, useValue: true}
|
||||
];
|
||||
|
@ -6,7 +6,7 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {ApplicationRef, NgModuleFactory, NgModuleRef, PlatformRef, Provider, Type} from '@angular/core';
|
||||
import {ApplicationRef, NgModuleFactory, NgModuleRef, PlatformRef, StaticProvider, Type} from '@angular/core';
|
||||
import {ɵTRANSITION_ID} from '@angular/platform-browser';
|
||||
import {filter} from 'rxjs/operator/filter';
|
||||
import {first} from 'rxjs/operator/first';
|
||||
@ -21,11 +21,11 @@ const parse5 = require('parse5');
|
||||
interface PlatformOptions {
|
||||
document?: string;
|
||||
url?: string;
|
||||
extraProviders?: Provider[];
|
||||
extraProviders?: StaticProvider[];
|
||||
}
|
||||
|
||||
function _getPlatform(
|
||||
platformFactory: (extraProviders: Provider[]) => PlatformRef,
|
||||
platformFactory: (extraProviders: StaticProvider[]) => PlatformRef,
|
||||
options: PlatformOptions): PlatformRef {
|
||||
const extraProviders = options.extraProviders ? options.extraProviders : [];
|
||||
return platformFactory([
|
||||
@ -67,8 +67,8 @@ the server-rendered app can be properly bootstrapped into a client app.`);
|
||||
* @experimental
|
||||
*/
|
||||
export function renderModule<T>(
|
||||
module: Type<T>,
|
||||
options: {document?: string, url?: string, extraProviders?: Provider[]}): Promise<string> {
|
||||
module: Type<T>, options: {document?: string, url?: string, extraProviders?: StaticProvider[]}):
|
||||
Promise<string> {
|
||||
const platform = _getPlatform(platformDynamicServer, options);
|
||||
return _render(platform, platform.bootstrapModule(module));
|
||||
}
|
||||
@ -84,7 +84,8 @@ export function renderModule<T>(
|
||||
*/
|
||||
export function renderModuleFactory<T>(
|
||||
moduleFactory: NgModuleFactory<T>,
|
||||
options: {document?: string, url?: string, extraProviders?: Provider[]}): Promise<string> {
|
||||
options: {document?: string, url?: string, extraProviders?: StaticProvider[]}):
|
||||
Promise<string> {
|
||||
const platform = _getPlatform(platformServer, options);
|
||||
return _render(platform, platform.bootstrapModuleFactory(moduleFactory));
|
||||
}
|
||||
|
@ -7,7 +7,7 @@
|
||||
*/
|
||||
|
||||
import {platformCoreDynamicTesting} from '@angular/compiler/testing';
|
||||
import {NgModule, PlatformRef, Provider, createPlatformFactory} from '@angular/core';
|
||||
import {NgModule, PlatformRef, StaticProvider, createPlatformFactory} from '@angular/core';
|
||||
import {BrowserDynamicTestingModule} from '@angular/platform-browser-dynamic/testing';
|
||||
import {NoopAnimationsModule} from '@angular/platform-browser/animations';
|
||||
import {ɵINTERNAL_SERVER_PLATFORM_PROVIDERS as INTERNAL_SERVER_PLATFORM_PROVIDERS, ɵSERVER_RENDER_PROVIDERS as SERVER_RENDER_PROVIDERS} from '@angular/platform-server';
|
||||
|
Reference in New Issue
Block a user