refactor(Directive): drop moduleId
moduleId is only used by components to resolve urls. Directives have no templates and do not need moduleId. Closes #5873
This commit is contained in:
parent
1c779d8b9e
commit
5a04ffec3e
|
@ -32,12 +32,13 @@ export class RuntimeMetadataResolver {
|
|||
var meta = this._cache.get(directiveType);
|
||||
if (isBlank(meta)) {
|
||||
var dirMeta = this._directiveResolver.resolve(directiveType);
|
||||
var moduleUrl = calcModuleUrl(directiveType, dirMeta);
|
||||
var moduleUrl = null;
|
||||
var templateMeta = null;
|
||||
var changeDetectionStrategy = null;
|
||||
|
||||
if (dirMeta instanceof md.ComponentMetadata) {
|
||||
var cmpMeta = <md.ComponentMetadata>dirMeta;
|
||||
moduleUrl = calcModuleUrl(directiveType, cmpMeta);
|
||||
var viewMeta = this._viewResolver.resolve(directiveType);
|
||||
templateMeta = new cpl.CompileTemplateMetadata({
|
||||
encapsulation: viewMeta.encapsulation,
|
||||
|
@ -107,8 +108,8 @@ function isValidDirective(value: Type): boolean {
|
|||
return isPresent(value) && (value instanceof Type);
|
||||
}
|
||||
|
||||
function calcModuleUrl(type: Type, dirMeta: md.DirectiveMetadata): string {
|
||||
var moduleId = dirMeta.moduleId;
|
||||
function calcModuleUrl(type: Type, cmpMetadata: md.ComponentMetadata): string {
|
||||
var moduleId = cmpMetadata.moduleId;
|
||||
if (isPresent(moduleId)) {
|
||||
var scheme = getUrlScheme(moduleId);
|
||||
return isPresent(scheme) && scheme.length > 0 ? moduleId :
|
||||
|
|
|
@ -132,7 +132,6 @@ export class DirectiveResolver {
|
|||
outputs: mergedOutputs,
|
||||
host: mergedHost,
|
||||
exportAs: dm.exportAs,
|
||||
moduleId: dm.moduleId,
|
||||
queries: mergedQueries,
|
||||
providers: dm.providers
|
||||
});
|
||||
|
|
|
@ -27,7 +27,6 @@ class Directive extends DirectiveMetadata {
|
|||
List bindings,
|
||||
List providers,
|
||||
String exportAs,
|
||||
String moduleId,
|
||||
Map<String, dynamic> queries})
|
||||
: super(
|
||||
selector: selector,
|
||||
|
@ -39,7 +38,6 @@ class Directive extends DirectiveMetadata {
|
|||
bindings: bindings,
|
||||
providers: providers,
|
||||
exportAs: exportAs,
|
||||
moduleId: moduleId,
|
||||
queries: queries);
|
||||
}
|
||||
|
||||
|
|
|
@ -146,7 +146,6 @@ export interface DirectiveFactory {
|
|||
bindings?: any[],
|
||||
providers?: any[],
|
||||
exportAs?: string,
|
||||
moduleId?: string,
|
||||
queries?: {[key: string]: any}
|
||||
}): DirectiveDecorator;
|
||||
new (obj: {
|
||||
|
@ -159,7 +158,6 @@ export interface DirectiveFactory {
|
|||
bindings?: any[],
|
||||
providers?: any[],
|
||||
exportAs?: string,
|
||||
moduleId?: string,
|
||||
queries?: {[key: string]: any}
|
||||
}): DirectiveMetadata;
|
||||
}
|
||||
|
|
|
@ -696,26 +696,6 @@ export class DirectiveMetadata extends InjectableMetadata {
|
|||
*/
|
||||
exportAs: string;
|
||||
|
||||
/**
|
||||
* The module id of the module that contains the directive.
|
||||
* Needed to be able to resolve relative urls for templates and styles.
|
||||
* In Dart, this can be determined automatically and does not need to be set.
|
||||
* In CommonJS, this can always be set to `module.id`.
|
||||
*
|
||||
* ## Simple Example
|
||||
*
|
||||
* ```
|
||||
* @Directive({
|
||||
* selector: 'someDir',
|
||||
* moduleId: module.id
|
||||
* })
|
||||
* class SomeDir {
|
||||
* }
|
||||
*
|
||||
* ```
|
||||
*/
|
||||
moduleId: string;
|
||||
|
||||
// TODO: add an example after ContentChildren and ViewChildren are in master
|
||||
/**
|
||||
* Configures the queries that will be injected into the directive.
|
||||
|
@ -752,7 +732,7 @@ export class DirectiveMetadata extends InjectableMetadata {
|
|||
queries: {[key: string]: any};
|
||||
|
||||
constructor({selector, inputs, outputs, properties, events, host, bindings, providers, exportAs,
|
||||
moduleId, queries}: {
|
||||
queries}: {
|
||||
selector?: string,
|
||||
inputs?: string[],
|
||||
outputs?: string[],
|
||||
|
@ -762,7 +742,6 @@ export class DirectiveMetadata extends InjectableMetadata {
|
|||
providers?: any[],
|
||||
/** @deprecated */ bindings?: any[],
|
||||
exportAs?: string,
|
||||
moduleId?: string,
|
||||
queries?: {[key: string]: any}
|
||||
} = {}) {
|
||||
super();
|
||||
|
@ -773,7 +752,6 @@ export class DirectiveMetadata extends InjectableMetadata {
|
|||
this._events = events;
|
||||
this.host = host;
|
||||
this.exportAs = exportAs;
|
||||
this.moduleId = moduleId;
|
||||
this.queries = queries;
|
||||
this._providers = providers;
|
||||
this._bindings = bindings;
|
||||
|
@ -865,6 +843,26 @@ export class ComponentMetadata extends DirectiveMetadata {
|
|||
private _viewProviders: any[];
|
||||
private _viewBindings: any[];
|
||||
|
||||
/**
|
||||
* The module id of the module that contains the component.
|
||||
* Needed to be able to resolve relative urls for templates and styles.
|
||||
* In Dart, this can be determined automatically and does not need to be set.
|
||||
* In CommonJS, this can always be set to `module.id`.
|
||||
*
|
||||
* ## Simple Example
|
||||
*
|
||||
* ```
|
||||
* @Directive({
|
||||
* selector: 'someDir',
|
||||
* moduleId: module.id
|
||||
* })
|
||||
* class SomeDir {
|
||||
* }
|
||||
*
|
||||
* ```
|
||||
*/
|
||||
moduleId: string;
|
||||
|
||||
templateUrl: string;
|
||||
|
||||
template: string;
|
||||
|
@ -913,7 +911,6 @@ export class ComponentMetadata extends DirectiveMetadata {
|
|||
events: events,
|
||||
host: host,
|
||||
exportAs: exportAs,
|
||||
moduleId: moduleId,
|
||||
bindings: bindings,
|
||||
providers: providers,
|
||||
queries: queries
|
||||
|
@ -929,6 +926,7 @@ export class ComponentMetadata extends DirectiveMetadata {
|
|||
this.directives = directives;
|
||||
this.pipes = pipes;
|
||||
this.encapsulation = encapsulation;
|
||||
this.moduleId = moduleId;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -47,7 +47,6 @@ export class MockDirectiveResolver extends DirectiveResolver {
|
|||
host: dm.host,
|
||||
providers: providers,
|
||||
exportAs: dm.exportAs,
|
||||
moduleId: dm.moduleId,
|
||||
queries: dm.queries
|
||||
});
|
||||
}
|
||||
|
|
|
@ -70,10 +70,10 @@ export function main() {
|
|||
|
||||
it('should use the moduleUrl from the reflector if none is given',
|
||||
inject([RuntimeMetadataResolver], (resolver: RuntimeMetadataResolver) => {
|
||||
var value: string = resolver.getMetadata(DirectiveWithoutModuleId).type.moduleUrl;
|
||||
var value: string = resolver.getMetadata(ComponentWithoutModuleId).type.moduleUrl;
|
||||
var expectedEndValue =
|
||||
IS_DART ? 'base/dist/dart/angular2/test/compiler/runtime_metadata_spec.dart' : './';
|
||||
expect((<any>value).endsWith(expectedEndValue)).toBe(true);
|
||||
expect(value.endsWith(expectedEndValue)).toBe(true);
|
||||
}));
|
||||
});
|
||||
|
||||
|
@ -82,7 +82,7 @@ export function main() {
|
|||
it('should return the directive metadatas',
|
||||
inject([RuntimeMetadataResolver], (resolver: RuntimeMetadataResolver) => {
|
||||
expect(resolver.getViewDirectivesMetadata(ComponentWithEverything))
|
||||
.toEqual([resolver.getMetadata(DirectiveWithoutModuleId)]);
|
||||
.toEqual([resolver.getMetadata(SomeDirective)]);
|
||||
}));
|
||||
|
||||
describe("platform directives", () => {
|
||||
|
@ -91,10 +91,7 @@ export function main() {
|
|||
it('should include platform directives when available',
|
||||
inject([RuntimeMetadataResolver], (resolver: RuntimeMetadataResolver) => {
|
||||
expect(resolver.getViewDirectivesMetadata(ComponentWithEverything))
|
||||
.toEqual([
|
||||
resolver.getMetadata(ADirective),
|
||||
resolver.getMetadata(DirectiveWithoutModuleId)
|
||||
]);
|
||||
.toEqual([resolver.getMetadata(ADirective), resolver.getMetadata(SomeDirective)]);
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
@ -102,14 +99,16 @@ export function main() {
|
|||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Directive({selector: 'a-directive'})
|
||||
class ADirective {
|
||||
}
|
||||
|
||||
@Directive({selector: 'someSelector'})
|
||||
class DirectiveWithoutModuleId {
|
||||
class SomeDirective {
|
||||
}
|
||||
|
||||
@Component({selector: 'someComponent', template: ''})
|
||||
class ComponentWithoutModuleId {
|
||||
}
|
||||
|
||||
@Component({
|
||||
|
@ -131,7 +130,7 @@ class DirectiveWithoutModuleId {
|
|||
encapsulation: ViewEncapsulation.Emulated,
|
||||
styles: ['someStyle'],
|
||||
styleUrls: ['someStyleUrl'],
|
||||
directives: [DirectiveWithoutModuleId]
|
||||
directives: [SomeDirective]
|
||||
})
|
||||
class ComponentWithEverything implements OnChanges,
|
||||
OnInit, DoCheck, OnDestroy, AfterContentInit, AfterContentChecked, AfterViewInit,
|
||||
|
|
|
@ -321,7 +321,7 @@ class CompWithEmbeddedTemplate {
|
|||
}
|
||||
|
||||
|
||||
@Directive({selector: 'plain', moduleId: THIS_MODULE_ID})
|
||||
@Directive({selector: 'plain'})
|
||||
@View({template: ''})
|
||||
class NonComponent {
|
||||
}
|
||||
|
|
|
@ -923,7 +923,6 @@ var NG_CORE = [
|
|||
'Directive.events',
|
||||
'Directive.exportAs',
|
||||
'Directive.host',
|
||||
'Directive.moduleId',
|
||||
'Directive.inputs',
|
||||
'Directive.properties',
|
||||
'Directive.queries',
|
||||
|
@ -935,7 +934,6 @@ var NG_CORE = [
|
|||
'DirectiveMetadata.events',
|
||||
'DirectiveMetadata.exportAs',
|
||||
'DirectiveMetadata.host',
|
||||
'DirectiveMetadata.moduleId',
|
||||
'DirectiveMetadata.inputs',
|
||||
'DirectiveMetadata.properties',
|
||||
'DirectiveMetadata.queries',
|
||||
|
|
Loading…
Reference in New Issue