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
@ -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));
|
||||
}
|
||||
|
Reference in New Issue
Block a user