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, ChangeDetectorRef, ComponentFactory, ComponentRef, EventEmitter, Injector, OnChanges, ReflectiveInjector, SimpleChange, SimpleChanges, Type} from '@angular/core';
|
||||
import {ApplicationRef, ChangeDetectorRef, ComponentFactory, ComponentRef, EventEmitter, Injector, OnChanges, SimpleChange, SimpleChanges, Type} from '@angular/core';
|
||||
|
||||
import * as angular from './angular1';
|
||||
import {PropertyBinding} from './component_info';
|
||||
@ -57,8 +57,8 @@ export class DowngradeComponentAdapter {
|
||||
}
|
||||
|
||||
createComponent(projectableNodes: Node[][]) {
|
||||
const childInjector = ReflectiveInjector.resolveAndCreate(
|
||||
[{provide: $SCOPE, useValue: this.componentScope}], this.parentInjector);
|
||||
const childInjector =
|
||||
Injector.create([{provide: $SCOPE, useValue: this.componentScope}], this.parentInjector);
|
||||
|
||||
this.componentRef =
|
||||
this.componentFactory.create(childInjector, projectableNodes, this.element[0]);
|
||||
|
@ -6,7 +6,7 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {Compiler, CompilerOptions, Directive, Injector, NgModule, NgModuleRef, NgZone, Provider, Testability, Type} from '@angular/core';
|
||||
import {Compiler, CompilerOptions, Directive, Injector, NgModule, NgModuleRef, NgZone, StaticProvider, Testability, Type} from '@angular/core';
|
||||
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
|
||||
|
||||
import * as angular from '../common/angular1';
|
||||
@ -110,7 +110,7 @@ export class UpgradeAdapter {
|
||||
* @internal
|
||||
*/
|
||||
private ng1ComponentsToBeUpgraded: {[name: string]: UpgradeNg1ComponentAdapterBuilder} = {};
|
||||
private upgradedProviders: Provider[] = [];
|
||||
private upgradedProviders: StaticProvider[] = [];
|
||||
private ngZone: NgZone;
|
||||
private ng1Module: angular.IModule;
|
||||
private moduleRef: NgModuleRef<any>|null = null;
|
||||
|
@ -43,7 +43,7 @@ export const angular1Providers = [
|
||||
// > Metadata collected contains an error that will be reported at runtime:
|
||||
// > Function calls are not supported.
|
||||
// > Consider replacing the function or lambda with a reference to an exported function
|
||||
{provide: '$injector', useFactory: injectorFactory},
|
||||
{provide: '$injector', useFactory: injectorFactory, deps: []},
|
||||
{provide: '$rootScope', useFactory: rootScopeFactory, deps: ['$injector']},
|
||||
{provide: '$compile', useFactory: compileFactory, deps: ['$injector']},
|
||||
{provide: '$parse', useFactory: parseFactory, deps: ['$injector']}
|
||||
|
@ -6,7 +6,7 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {Injector, NgModuleFactory, NgModuleRef, Provider} from '@angular/core';
|
||||
import {Injector, NgModuleFactory, NgModuleRef, StaticProvider} from '@angular/core';
|
||||
import {platformBrowser} from '@angular/platform-browser';
|
||||
|
||||
import * as angular from '../common/angular1';
|
||||
@ -20,11 +20,11 @@ import {NgAdapterInjector} from './util';
|
||||
/** @experimental */
|
||||
export function downgradeModule<T>(
|
||||
moduleFactoryOrBootstrapFn: NgModuleFactory<T>|
|
||||
((extraProviders: Provider[]) => Promise<NgModuleRef<T>>)): string {
|
||||
((extraProviders: StaticProvider[]) => Promise<NgModuleRef<T>>)): string {
|
||||
const LAZY_MODULE_NAME = UPGRADE_MODULE_NAME + '.lazy';
|
||||
const bootstrapFn = isFunction(moduleFactoryOrBootstrapFn) ?
|
||||
moduleFactoryOrBootstrapFn :
|
||||
(extraProviders: Provider[]) =>
|
||||
(extraProviders: StaticProvider[]) =>
|
||||
platformBrowser(extraProviders).bootstrapModuleFactory(moduleFactoryOrBootstrapFn);
|
||||
|
||||
let injector: Injector;
|
||||
|
Reference in New Issue
Block a user