refactor(core): simplify decorators
Every decorator now is made of the following: - a function that can be used as a decorator or as a constructor. This function also can be used for `instanceof` checks. - a type for this function (callable and newable) - a type that describes the shape of the data that the user needs to pass to the decorator as well as the instance of the metadata The docs for decorators live at the followig places so that IDEs can discover them correctly: - General description of the decorator is placed on the `...Decorator` interface on the callable function definition - Property descriptions are placed on the interface that describes the metadata produces by the decorator
This commit is contained in:
@ -63,20 +63,23 @@ export class DirectiveResolver {
|
||||
inputs.push(propName);
|
||||
}
|
||||
} else if (a instanceof OutputMetadata) {
|
||||
if (isPresent(a.bindingPropertyName)) {
|
||||
outputs.push(`${propName}: ${a.bindingPropertyName}`);
|
||||
const output: OutputMetadata = a;
|
||||
if (isPresent(output.bindingPropertyName)) {
|
||||
outputs.push(`${propName}: ${output.bindingPropertyName}`);
|
||||
} else {
|
||||
outputs.push(propName);
|
||||
}
|
||||
} else if (a instanceof HostBindingMetadata) {
|
||||
if (isPresent(a.hostPropertyName)) {
|
||||
host[`[${a.hostPropertyName}]`] = propName;
|
||||
const hostBinding: HostBindingMetadata = a;
|
||||
if (isPresent(hostBinding.hostPropertyName)) {
|
||||
host[`[${hostBinding.hostPropertyName}]`] = propName;
|
||||
} else {
|
||||
host[`[${propName}]`] = propName;
|
||||
}
|
||||
} else if (a instanceof HostListenerMetadata) {
|
||||
var args = isPresent(a.args) ? (<any[]>a.args).join(', ') : '';
|
||||
host[`(${a.eventName})`] = `${propName}(${args})`;
|
||||
const hostListener: HostListenerMetadata = a;
|
||||
var args = isPresent(hostListener.args) ? (<any[]>hostListener.args).join(', ') : '';
|
||||
host[`(${hostListener.eventName})`] = `${propName}(${args})`;
|
||||
} else if (a instanceof QueryMetadata) {
|
||||
queries[propName] = a;
|
||||
}
|
||||
|
@ -6,14 +6,14 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {AnimationAnimateMetadata, AnimationEntryMetadata, AnimationGroupMetadata, AnimationKeyframesSequenceMetadata, AnimationMetadata, AnimationStateDeclarationMetadata, AnimationStateMetadata, AnimationStateTransitionMetadata, AnimationStyleMetadata, AnimationWithStepsMetadata, AttributeMetadata, ChangeDetectionStrategy, ComponentMetadata, HostMetadata, InjectMetadata, Injectable, ModuleWithProviders, OptionalMetadata, Provider, QueryMetadata, SchemaMetadata, SelfMetadata, SkipSelfMetadata, Type, ViewQueryMetadata, resolveForwardRef} from '@angular/core';
|
||||
import {AnimationAnimateMetadata, AnimationEntryMetadata, AnimationGroupMetadata, AnimationKeyframesSequenceMetadata, AnimationMetadata, AnimationStateDeclarationMetadata, AnimationStateMetadata, AnimationStateTransitionMetadata, AnimationStyleMetadata, AnimationWithStepsMetadata, AttributeMetadata, ChangeDetectionStrategy, ComponentMetadata, HostMetadata, InjectMetadata, Injectable, ModuleWithProviders, OptionalMetadata, Provider, QueryMetadata, SchemaMetadata, SelfMetadata, SkipSelfMetadata, Type, resolveForwardRef} from '@angular/core';
|
||||
|
||||
import {StringMapWrapper} from '../src/facade/collection';
|
||||
|
||||
import {assertArrayOfStrings, assertInterpolationSymbols} from './assertions';
|
||||
import * as cpl from './compile_metadata';
|
||||
import {DirectiveResolver} from './directive_resolver';
|
||||
import {isArray, isBlank, isPresent, isString, stringify} from './facade/lang';
|
||||
import {StringWrapper, isArray, isBlank, isPresent, isString, stringify} from './facade/lang';
|
||||
import {Identifiers, resolveIdentifierToken} from './identifiers';
|
||||
import {hasLifecycleHook} from './lifecycle_reflector';
|
||||
import {NgModuleResolver} from './ng_module_resolver';
|
||||
@ -484,7 +484,7 @@ export class CompileMetadataResolver {
|
||||
let isSkipSelf = false;
|
||||
let isOptional = false;
|
||||
let query: QueryMetadata = null;
|
||||
let viewQuery: ViewQueryMetadata = null;
|
||||
let viewQuery: QueryMetadata = null;
|
||||
var token: any = null;
|
||||
if (isArray(param)) {
|
||||
(<any[]>param).forEach((paramEntry) => {
|
||||
@ -664,11 +664,16 @@ export class CompileMetadataResolver {
|
||||
return res;
|
||||
}
|
||||
|
||||
private _queryVarBindings(selector: any): string[] {
|
||||
return StringWrapper.split(selector, /\s*,\s*/g);
|
||||
}
|
||||
|
||||
|
||||
getQueryMetadata(q: QueryMetadata, propertyName: string, typeOrFunc: Type<any>|Function):
|
||||
cpl.CompileQueryMetadata {
|
||||
var selectors: cpl.CompileTokenMetadata[];
|
||||
if (q.isVarBindingQuery) {
|
||||
selectors = q.varBindings.map(varName => this.getTokenMetadata(varName));
|
||||
if (isString(q.selector)) {
|
||||
selectors = this._queryVarBindings(q.selector).map(varName => this.getTokenMetadata(varName));
|
||||
} else {
|
||||
if (!isPresent(q.selector)) {
|
||||
throw new Error(
|
||||
|
Reference in New Issue
Block a user