diff --git a/modules/angular2/annotations.ts b/modules/angular2/annotations.ts index c860652295..fab6758bfc 100644 --- a/modules/angular2/annotations.ts +++ b/modules/angular2/annotations.ts @@ -13,7 +13,6 @@ export { ComponentAnnotation, - ComponentArgs, DirectiveAnnotation, LifecycleEvent, onDestroy, @@ -23,7 +22,7 @@ export { onAllChangesDone } from './src/core/annotations/annotations'; -export {ViewAnnotation, ViewArgs} from 'angular2/src/core/annotations/view'; +export {ViewAnnotation} from 'angular2/src/core/annotations/view'; export {QueryAnnotation, AttributeAnnotation} from 'angular2/src/core/annotations/di'; export { diff --git a/modules/angular2/src/core/annotations/decorators.ts b/modules/angular2/src/core/annotations/decorators.ts index 7b6d6934bb..6af0b1f620 100644 --- a/modules/angular2/src/core/annotations/decorators.ts +++ b/modules/angular2/src/core/annotations/decorators.ts @@ -1,10 +1,5 @@ -import { - ComponentAnnotation, - DirectiveAnnotation, - ComponentArgs, - DirectiveArgs -} from './annotations'; -import {ViewAnnotation, ViewArgs} from './view'; +import {ComponentAnnotation, DirectiveAnnotation, LifecycleEvent} from './annotations'; +import {ViewAnnotation} from './view'; import {AttributeAnnotation, QueryAnnotation} from './di'; import { makeDecorator, @@ -31,7 +26,14 @@ export interface ComponentDecorator extends TypeDecorator { /** * Chain {@link View} annotation. */ - View(obj: ViewArgs): ViewDecorator; + View(obj: { + templateUrl?: string, + template?: string, + directives?: List>, + renderer?: string, + styles?: List, + styleUrls?: List, + }): ViewDecorator; } /** @@ -43,7 +45,14 @@ export interface ViewDecorator extends TypeDecorator { /** * Chain {@link View} annotation. */ - View(obj: ViewArgs): ViewDecorator + View(obj: { + templateUrl?: string, + template?: string, + directives?: List>, + renderer?: string, + styles?: List, + styleUrls?: List, + }): ViewDecorator } /** @@ -87,8 +96,16 @@ export interface ViewDecorator extends TypeDecorator { * ``` */ export interface DirectiveFactory { - (obj: DirectiveArgs): DirectiveDecorator; - new (obj: DirectiveAnnotation): DirectiveAnnotation; + (obj: { + selector?: string, properties?: List, events?: List, + host?: StringMap, lifecycle?: List, + hostInjector?: List, exportAs?: string, compileChildren?: boolean; + }): DirectiveDecorator; + new (obj: { + selector?: string, properties?: List, events?: List, + host?: StringMap, lifecycle?: List, + hostInjector?: List, exportAs?: string, compileChildren?: boolean; + }): DirectiveAnnotation; } /** @@ -135,8 +152,30 @@ export interface DirectiveFactory { * ``` */ export interface ComponentFactory { - (obj: ComponentArgs): ComponentDecorator; - new (obj: ComponentAnnotation): ComponentAnnotation; + (obj: { + selector?: string, + properties?: List, + events?: List, + host?: StringMap, + lifecycle?: List, + hostInjector?: List, + exportAs?: string, + compileChildren?: boolean, + viewInjector?: List, + changeDetection?: string, + }): ComponentDecorator; + new (obj: { + selector?: string, + properties?: List, + events?: List, + host?: StringMap, + lifecycle?: List, + hostInjector?: List, + exportAs?: string, + compileChildren?: boolean, + viewInjector?: List, + changeDetection?: string, + }): ComponentAnnotation; } /** @@ -183,8 +222,22 @@ export interface ComponentFactory { * ``` */ export interface ViewFactory { - (obj: ViewArgs): ViewDecorator; - new (obj: ViewArgs): ViewAnnotation; + (obj: { + templateUrl?: string, + template?: string, + directives?: List>, + renderer?: string, + styles?: List, + styleUrls?: List, + }): ViewDecorator; + new (obj: { + templateUrl?: string, + template?: string, + directives?: List>, + renderer?: string, + styles?: List, + styleUrls?: List, + }): ViewAnnotation; } /** diff --git a/modules/angular2/src/core/annotations/view.ts b/modules/angular2/src/core/annotations/view.ts index 39e2ae0ac6..edb8902a3b 100644 --- a/modules/angular2/src/core/annotations/view.ts +++ b/modules/angular2/src/core/annotations/view.ts @@ -1 +1 @@ -export {View as ViewAnnotation, ViewArgs} from '../annotations_impl/view'; +export {View as ViewAnnotation} from '../annotations_impl/view'; diff --git a/modules/angular2/src/core/annotations_impl/annotations.ts b/modules/angular2/src/core/annotations_impl/annotations.ts index 90e3e1369c..b67a5ef020 100644 --- a/modules/angular2/src/core/annotations_impl/annotations.ts +++ b/modules/angular2/src/core/annotations_impl/annotations.ts @@ -408,33 +408,6 @@ import {DEFAULT} from 'angular2/change_detection'; */ @CONST() export class Directive extends Injectable { - selector: string; - properties: List; - events: List; - host: StringMap; - lifecycle: List; - // TODO(vsavkin): This would better fall under the Macro directive concept. - compileChildren: boolean; - hostInjector: List; - exportAs: string; - - constructor({ - selector, properties, events, host, lifecycle, hostInjector, exportAs, - compileChildren = true, - }: DirectiveArgs = {}) { - super(self); - this.selector = selector; - this.properties = properties; - this.events = events; - this.host = host; - this.exportAs = exportAs; - this.lifecycle = lifecycle; - this.compileChildren = compileChildren; - this.hostInjector = hostInjector; - } -} - -export interface DirectiveArgs { /** * The CSS selector that triggers the instantiation of a directive. * @@ -467,7 +440,7 @@ export interface DirectiveArgs { * The directive would only be instantiated on the `` element. * */ - selector?: string; + selector: string; /** * Enumerates the set of properties that accept data binding for a directive. @@ -562,7 +535,7 @@ export interface DirectiveArgs { * keyValDiff`. * */ - properties?: List; + properties: List; /** * Enumerates the set of emitted events. @@ -607,7 +580,7 @@ export interface DirectiveArgs { * ``` * */ - events?: List; + events: List; /** * Specifiy the events, actions, properties and attributes related to the host element. @@ -734,14 +707,20 @@ export interface DirectiveArgs { * * In this example calling focus on InputDirective will result in calling focus on the input. */ - host?: StringMap; + host: StringMap; /** * Specifies which lifecycle should be notified to the directive. * * See {@link LifecycleEvent} for details. */ - lifecycle?: List; + lifecycle: List; + + /** + * If set to false the compiler does not compile the children of this directive. + */ + // TODO(vsavkin): This would better fall under the Macro directive concept. + compileChildren: boolean; /** * Defines the set of injectable objects that are visible to a Directive and its light dom @@ -773,7 +752,7 @@ export interface DirectiveArgs { * } * ``` */ - hostInjector?: List; + hostInjector: List; /** * Defines the name that can be used in the template to assign this directive to a variable. @@ -800,15 +779,33 @@ export interface DirectiveArgs { * * ``` */ - exportAs?: string; + exportAs: string; - /** - * If set to false the compiler does not compile the children of this directive. - */ - compileChildren?: boolean; + constructor({ + selector, properties, events, host, lifecycle, hostInjector, exportAs, + compileChildren = true, + }: { + selector?: string, + properties?: List, + events?: List, + host?: StringMap, + lifecycle?: List, + hostInjector?: List, + exportAs?: string, + compileChildren?: boolean, + } = {}) { + super(self); + this.selector = selector; + this.properties = properties; + this.events = events; + this.host = host; + this.exportAs = exportAs; + this.lifecycle = lifecycle; + this.compileChildren = compileChildren; + this.hostInjector = hostInjector; + } } - /** * Declare reusable UI building blocks for an application. * @@ -849,28 +846,19 @@ export interface DirectiveArgs { */ @CONST() export class Component extends Directive { + /** + * Defines the used change detection strategy. + * + * When a component is instantiated, Angular creates a change detector, which is responsible for + * propagating + * the component's bindings. + * + * The `changeDetection` property defines, whether the change detection will be checked every time + * or only when the component + * tells it to do so. + */ changeDetection: string; - viewInjector: List; - constructor({selector, properties, events, host, exportAs, lifecycle, hostInjector, viewInjector, - changeDetection = DEFAULT, compileChildren = true}: ComponentArgs = {}) { - super({ - selector: selector, - properties: properties, - events: events, - host: host, - exportAs: exportAs, - hostInjector: hostInjector, - lifecycle: lifecycle, - compileChildren: compileChildren - }); - - this.changeDetection = changeDetection; - this.viewInjector = viewInjector; - } -} - -export interface ComponentArgs extends DirectiveArgs { /** * Defines the set of injectable objects that are visible to its view dom children. * @@ -911,20 +899,35 @@ export interface ComponentArgs extends DirectiveArgs { * * ``` */ - viewInjector?: List; + viewInjector: List; - /** - * Defines the used change detection strategy. - * - * When a component is instantiated, Angular creates a change detector, which is responsible for - * propagating - * the component's bindings. - * - * The `changeDetection` property defines, whether the change detection will be checked every time - * or only when the component - * tells it to do so. - */ - changeDetection?: string; + constructor({selector, properties, events, host, exportAs, lifecycle, hostInjector, viewInjector, + changeDetection = DEFAULT, compileChildren = true}: { + selector?: string, + properties?: List, + events?: List, + host?: StringMap, + lifecycle?: List, + hostInjector?: List, + exportAs?: string, + compileChildren?: boolean, + viewInjector?: List, + changeDetection?: string, + } = {}) { + super({ + selector: selector, + properties: properties, + events: events, + host: host, + exportAs: exportAs, + hostInjector: hostInjector, + lifecycle: lifecycle, + compileChildren: compileChildren + }); + + this.changeDetection = changeDetection; + this.viewInjector = viewInjector; + } } /** diff --git a/modules/angular2/src/core/annotations_impl/view.ts b/modules/angular2/src/core/annotations_impl/view.ts index 3831b1093f..ea9311ab78 100644 --- a/modules/angular2/src/core/annotations_impl/view.ts +++ b/modules/angular2/src/core/annotations_impl/view.ts @@ -35,39 +35,29 @@ import {ABSTRACT, CONST, Type} from 'angular2/src/facade/lang'; */ @CONST() export class View { - templateUrl: string; - template: string; - styleUrls: List; - styles: List; - // TODO(tbosch): use Type | Binding | List when Dart supports union types, - // as otherwise we would need to import Binding type and Dart would warn - // for an unused import. - directives: List>; - renderer: string; - - constructor({templateUrl, template, directives, renderer, styles, styleUrls}: ViewArgs = {}) { - this.templateUrl = templateUrl; - this.template = template; - this.styleUrls = styleUrls; - this.styles = styles; - this.directives = directives; - this.renderer = renderer; - } -} -export interface ViewArgs { - /** - * Specifies a template URL for an angular component. - * - * NOTE: either `templateUrl` or `template` should be used, but not both. - */ - templateUrl?: string; - /** * Specifies an inline template for an angular component. * * NOTE: either `templateUrl` or `template` should be used, but not both. */ - template?: string; + templateUrl: string; + + /** + * Specifies a template URL for an angular component. + * + * NOTE: either `templateUrl` or `template` should be used, but not both. + */ + template: string; + + /** + * Specifies stylesheet URLs for an angular component. + */ + styleUrls: List; + + /** + * Specifies an inline stylesheet for an angular component. + */ + styles: List; /** * Specifies a list of directives that can be used within a template. @@ -91,22 +81,31 @@ export interface ViewArgs { * } * ``` */ - directives?: List>; + // TODO(tbosch): use Type | Binding | List when Dart supports union types, + // as otherwise we would need to import Binding type and Dart would warn + // for an unused import. + directives: List>; /** * Specify a custom renderer for this View. * If this is set, neither `template`, `templateUrl`, `styles`, `styleUrls` nor `directives` are * used. */ - renderer?: string; + renderer: string; - /** - * Specifies an inline stylesheet for an angular component. - */ - styles?: List; - - /** - * Specifies stylesheet URLs for an angular component. - */ - styleUrls?: List; + constructor({templateUrl, template, directives, renderer, styles, styleUrls}: { + templateUrl?: string, + template?: string, + directives?: List>, + renderer?: string, + styles?: List, + styleUrls?: List, + } = {}) { + this.templateUrl = templateUrl; + this.template = template; + this.styleUrls = styleUrls; + this.styles = styles; + this.directives = directives; + this.renderer = renderer; + } }