refactor(core): rename precompile into entryComponents.

Part of #10043

BREAKING CHANGE:
- `@Component.precompile` was renamed to `@Component.entryComponents`
  (old property still works but is deprecated)
- `ANALYZE_FOR_PRECOMPILE` was renamed to `ANALYZE_FOR_ENTRY_COMPONENTS` (no deprecations)
This commit is contained in:
Tobias Bosch
2016-07-25 00:36:30 -07:00
parent 46b212706b
commit 6f4e49ed53
37 changed files with 296 additions and 294 deletions

View File

@ -0,0 +1,35 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {ANALYZE_FOR_ENTRY_COMPONENTS, Component, ComponentFactoryResolver, Inject, OpaqueToken} from '@angular/core';
import {BasicComp} from './basic';
@Component({selector: 'cmp-entryComponents', template: '', entryComponents: [BasicComp]})
export class CompWithEntryComponents {
constructor(public cfr: ComponentFactoryResolver) {}
}
export const SOME_TOKEN = new OpaqueToken('someToken');
export function provideValueWithEntryComponents(value: any) {
return [
{provide: SOME_TOKEN, useValue: value},
{provide: ANALYZE_FOR_ENTRY_COMPONENTS, useValue: value, multi: true},
];
}
@Component({
selector: 'comp-entryComponents-provider',
template: '',
providers: [provideValueWithEntryComponents([{a: 'b', component: BasicComp}])]
})
export class CompWithAnalyzeEntryComponentsProvider {
constructor(public cfr: ComponentFactoryResolver, @Inject(SOME_TOKEN) public providedValue: any) {
}
}

View File

@ -12,23 +12,24 @@ import {BrowserModule} from '@angular/platform-browser';
import {AnimateCmp} from './animate';
import {BasicComp} from './basic';
import {CompWithAnalyzeEntryComponentsProvider, CompWithEntryComponents} from './entry_components';
import {CompWithProviders, CompWithReferences} from './features';
import {CompUsingRootModuleDirectiveAndPipe, SomeDirectiveInRootModule, SomeLibModule, SomePipeInRootModule, SomeService} from './module_fixtures';
import {CompWithAnalyzePrecompileProvider, CompWithPrecompile} from './precompile';
import {ProjectingComp} from './projection';
import {CompWithChildQuery, CompWithDirectiveChild} from './queries';
@NgModule({
declarations: [
SomeDirectiveInRootModule, SomePipeInRootModule, AnimateCmp, BasicComp, CompWithPrecompile,
CompWithAnalyzePrecompileProvider, ProjectingComp, CompWithChildQuery, CompWithDirectiveChild,
CompUsingRootModuleDirectiveAndPipe, CompWithProviders, CompWithReferences
SomeDirectiveInRootModule, SomePipeInRootModule, AnimateCmp, BasicComp, CompWithEntryComponents,
CompWithAnalyzeEntryComponentsProvider, ProjectingComp, CompWithChildQuery,
CompWithDirectiveChild, CompUsingRootModuleDirectiveAndPipe, CompWithProviders,
CompWithReferences
],
imports: [BrowserModule, FormsModule, SomeLibModule],
providers: [SomeService],
precompile: [
AnimateCmp, BasicComp, CompWithPrecompile, CompWithAnalyzePrecompileProvider, ProjectingComp,
CompWithChildQuery, CompUsingRootModuleDirectiveAndPipe
entryComponents: [
AnimateCmp, BasicComp, CompWithEntryComponents, CompWithAnalyzeEntryComponentsProvider,
ProjectingComp, CompWithChildQuery, CompUsingRootModuleDirectiveAndPipe
]
})
export class MainModule {

View File

@ -7,7 +7,7 @@
*/
import {LowerCasePipe, NgIf} from '@angular/common';
import {ANALYZE_FOR_PRECOMPILE, Component, ComponentFactoryResolver, Directive, Inject, Injectable, Input, NgModule, OpaqueToken, Pipe} from '@angular/core';
import {ANALYZE_FOR_ENTRY_COMPONENTS, Component, ComponentFactoryResolver, Directive, Inject, Injectable, Input, NgModule, OpaqueToken, Pipe} from '@angular/core';
import {BrowserModule} from '@angular/platform-browser';
@Injectable()
@ -51,19 +51,19 @@ export class CompUsingLibModuleDirectiveAndPipe {
export const SOME_TOKEN = new OpaqueToken('someToken');
export function provideValueWithPrecompile(value: any) {
export function provideValueWithEntryComponents(value: any) {
return [
{provide: SOME_TOKEN, useValue: value},
{provide: ANALYZE_FOR_PRECOMPILE, useValue: value, multi: true},
{provide: ANALYZE_FOR_ENTRY_COMPONENTS, useValue: value, multi: true},
];
}
@NgModule({
declarations: [SomeDirectiveInLibModule, SomePipeInLibModule, CompUsingLibModuleDirectiveAndPipe],
precompile: [CompUsingLibModuleDirectiveAndPipe],
entryComponents: [CompUsingLibModuleDirectiveAndPipe],
providers: [
ServiceUsingLibModule,
provideValueWithPrecompile([{a: 'b', component: CompUsingLibModuleDirectiveAndPipe}])
provideValueWithEntryComponents([{a: 'b', component: CompUsingLibModuleDirectiveAndPipe}])
],
})
export class SomeLibModule {

View File

@ -1,35 +0,0 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {ANALYZE_FOR_PRECOMPILE, Component, ComponentFactoryResolver, Inject, OpaqueToken} from '@angular/core';
import {BasicComp} from './basic';
@Component({selector: 'cmp-precompile', template: '', precompile: [BasicComp]})
export class CompWithPrecompile {
constructor(public cfr: ComponentFactoryResolver) {}
}
export const SOME_TOKEN = new OpaqueToken('someToken');
export function provideValueWithPrecompile(value: any) {
return [
{provide: SOME_TOKEN, useValue: value},
{provide: ANALYZE_FOR_PRECOMPILE, useValue: value, multi: true},
];
}
@Component({
selector: 'comp-precompile-provider',
template: '',
providers: [provideValueWithPrecompile([{a: 'b', component: BasicComp}])]
})
export class CompWithAnalyzePrecompileProvider {
constructor(public cfr: ComponentFactoryResolver, @Inject(SOME_TOKEN) public providedValue: any) {
}
}

View File

@ -9,23 +9,24 @@
import './init';
import {BasicComp} from '../src/basic';
import {CompWithAnalyzePrecompileProvider, CompWithPrecompile} from '../src/precompile';
import {CompWithAnalyzeEntryComponentsProvider, CompWithEntryComponents} from '../src/entry_components';
import {createComponent} from './util';
describe('content projection', () => {
it('should support precompile in components', () => {
var compFixture = createComponent(CompWithPrecompile);
it('should support entryComponents in components', () => {
var compFixture = createComponent(CompWithEntryComponents);
var cf = compFixture.componentInstance.cfr.resolveComponentFactory(BasicComp);
expect(cf.componentType).toBe(BasicComp);
});
it('should support precompile via the ANALYZE_FOR_PRECOMPILE provider and function providers in components',
it('should support entryComponents via the ANALYZE_FOR_ENTRY_COMPONENTS provider and function providers in components',
() => {
const compFixture = createComponent(CompWithAnalyzePrecompileProvider);
const compFixture = createComponent(CompWithAnalyzeEntryComponentsProvider);
const cf = compFixture.componentInstance.cfr.resolveComponentFactory(BasicComp);
expect(cf.componentType).toBe(BasicComp);
// check that the function call that created the provider for ANALYZE_FOR_PRECOMPILE worked.
// check that the function call that created the provider for ANALYZE_FOR_ENTRY_COMPONENTS
// worked.
expect(compFixture.componentInstance.providedValue).toEqual([
{a: 'b', component: BasicComp}
]);

View File

@ -20,7 +20,7 @@ describe('NgModule', () => {
expect(moduleRef.injector.get(SomeService) instanceof SomeService).toBe(true);
});
it('should support precompile components', () => {
it('should support entryComponents components', () => {
const moduleRef = createModule();
const cf = moduleRef.componentFactoryResolver.resolveComponentFactory(
CompUsingRootModuleDirectiveAndPipe);
@ -29,13 +29,14 @@ describe('NgModule', () => {
expect(compRef.instance instanceof CompUsingRootModuleDirectiveAndPipe).toBe(true);
});
it('should support precompile via the ANALYZE_FOR_PRECOMPILE provider and function providers in components',
it('should support entryComponents via the ANALYZE_FOR_ENTRY_COMPONENTS provider and function providers in components',
() => {
const moduleRef = createModule();
const cf = moduleRef.componentFactoryResolver.resolveComponentFactory(
CompUsingRootModuleDirectiveAndPipe);
expect(cf.componentType).toBe(CompUsingRootModuleDirectiveAndPipe);
// check that the function call that created the provider for ANALYZE_FOR_PRECOMPILE worked.
// check that the function call that created the provider for ANALYZE_FOR_ENTRY_COMPONENTS
// worked.
expect(moduleRef.injector.get(SOME_TOKEN)).toEqual([
{a: 'b', component: CompUsingLibModuleDirectiveAndPipe}
]);