Skip to content

Commit d7df853

Browse files
committed
feat(Directive): convert properties to an array
fixes #2013 BREAKING CHANGE: Before @directive(properties: { 'sameName': 'sameName', 'directiveProp': 'elProp | pipe' }) After @directive(properties: [ 'sameName', 'directiveProp: elProp | pipe' ])
1 parent 0387221 commit d7df853

File tree

40 files changed

+182
-179
lines changed

40 files changed

+182
-179
lines changed

modules/angular2/docs/core/02_directives.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ Here is a trivial example of a tooltip decorator. The directive will log a toolt
6363
```
6464
@Directive({
6565
selector: '[tooltip]', | CSS Selector which triggers the decorator
66-
properties: { | List which properties need to be bound
67-
text: 'tooltip' | - DOM element tooltip property should be
68-
}, | mapped to the directive text property.
66+
properties: [ | List which properties need to be bound
67+
'text: tooltip' | - DOM element tooltip property should be
68+
], | mapped to the directive text property.
6969
hostListeners: { | List which events need to be mapped.
7070
mouseover: 'show' | - Invoke the show() method every time
7171
} | the mouseover event is fired.
@@ -108,10 +108,10 @@ Example of a component:
108108
```
109109
@Component({ | Component annotation
110110
selector: 'pane', | CSS selector on <pane> element
111-
properties: { | List which property need to be bound
112-
'title': 'title', | - title mapped to component title
113-
'open': 'open' | - open attribute mapped to component's open property
114-
}, |
111+
properties: [ | List which property need to be bound
112+
'title', | - title mapped to component title
113+
'open' | - open attribute mapped to component's open property
114+
], |
115115
}) |
116116
@View({ | View annotation
117117
templateUrl: 'pane.html' | - URL of template HTML
@@ -173,9 +173,9 @@ Directives that use a ViewContainer can control instantiation of child views whi
173173
```
174174
@Directive({
175175
selector: '[if]',
176-
properties: {
177-
'condition': 'if'
178-
}
176+
properties: [
177+
'condition: if'
178+
]
179179
})
180180
export class If {
181181
viewContainer: ViewContainerRef;

modules/angular2/src/core/annotations_impl/annotations.ts

Lines changed: 37 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ import {DEFAULT} from 'angular2/change_detection';
103103
*
104104
* @Directive({
105105
* selector: '[dependency]',
106-
* properties: {
107-
* 'id':'dependency'
108-
* }
106+
* properties: [
107+
* 'id: dependency'
108+
* ]
109109
* })
110110
* class Dependency {
111111
* id:string;
@@ -275,9 +275,9 @@ import {DEFAULT} from 'angular2/change_detection';
275275
* ```
276276
* @Directive({
277277
* selector: '[tooltip]',
278-
* properties: {
279-
* 'text': 'tooltip'
280-
* },
278+
* properties: [
279+
* 'text: tooltip'
280+
* ],
281281
* hostListeners: {
282282
* 'onmouseenter': 'onMouseEnter()',
283283
* 'onmouseleave': 'onMouseLeave()'
@@ -361,9 +361,7 @@ import {DEFAULT} from 'angular2/change_detection';
361361
* ```
362362
* @Directive({
363363
* selector: '[unless]',
364-
* properties: {
365-
* 'unless': 'unless'
366-
* }
364+
* properties: ['unless']
367365
* })
368366
* export class Unless {
369367
* viewContainer: ViewContainerRef;
@@ -453,52 +451,53 @@ export class Directive extends Injectable {
453451
* Enumerates the set of properties that accept data binding for a directive.
454452
*
455453
* The `properties` property defines a set of `directiveProperty` to `bindingProperty`
456-
* key-value pairs:
454+
* configuration:
457455
*
458456
* - `directiveProperty` specifies the component property where the value is written.
459457
* - `bindingProperty` specifies the DOM property where the value is read from.
460458
*
461459
* You can include a {@link Pipe} when specifying a `bindingProperty` to allow for data
462-
* transformation and structural
463-
* change detection of the value. These pipes will be evaluated in the context of this component.
464-
*
460+
* transformation and structural change detection of the value. These pipes will be evaluated in
461+
* the context of this component.
465462
*
466463
* ## Syntax
467464
*
465+
* There is no need to specify both `directiveProperty` and `bindingProperty` when they both have
466+
* the same value.
467+
*
468468
* ```
469469
* @Directive({
470-
* properties: {
471-
* 'directiveProperty1': 'bindingProperty1',
472-
* 'directiveProperty2': 'bindingProperty2 | pipe1 | ...',
470+
* properties: [
471+
* 'propertyName', // shorthand notation for 'propertyName: propertyName'
472+
* 'directiveProperty1: bindingProperty1',
473+
* 'directiveProperty2: bindingProperty2 | pipe1 | ...',
473474
* ...
474-
* }
475+
* ]
475476
* }
476477
* ```
477478
*
478479
*
479480
* ## Basic Property Binding
480481
*
481482
* We can easily build a simple `Tooltip` directive that exposes a `tooltip` property, which can
482-
* be used in templates
483-
* with standard Angular syntax. For example:
483+
* be used in templates with standard Angular syntax. For example:
484484
*
485485
* ```
486486
* @Directive({
487487
* selector: '[tooltip]',
488-
* properties: {
489-
* 'text': 'tooltip'
490-
* }
488+
* properties: [
489+
* 'text: tooltip'
490+
* ]
491491
* })
492492
* class Tooltip {
493-
* set text(text) {
494-
* // This will get called every time the 'tooltip' binding changes with the new value.
493+
* set text(value: string) {
494+
* // This will get called every time with the new value when the 'tooltip' property changes
495495
* }
496496
* }
497497
* ```
498498
*
499499
* We can then bind to the `tooltip' property as either an expression (`someExpression`) or as a
500-
* string literal, as
501-
* shown in the HTML template below:
500+
* string literal, as shown in the HTML template below:
502501
*
503502
* ```html
504503
* <div [tooltip]="someExpression">...</div>
@@ -508,27 +507,24 @@ export class Directive extends Injectable {
508507
* Whenever the `someExpression` expression changes, the `properties` declaration instructs
509508
* Angular to update the `Tooltip`'s `text` property.
510509
*
511-
*
512-
*
513510
* ## Bindings With Pipes
514511
*
515512
* You can also use pipes when writing binding definitions for a directive.
516513
*
517514
* For example, we could write a binding that updates the directive on structural changes, rather
518-
* than on reference
519-
* changes, as normally occurs in change detection.
515+
* than on reference changes, as normally occurs in change detection.
520516
*
521517
* See {@link Pipe} and {@link keyValDiff} documentation for more details.
522518
*
523519
* ```
524520
* @Directive({
525521
* selector: '[class-set]',
526-
* properties: {
527-
* 'classChanges': 'classSet | keyValDiff'
528-
* }
522+
* properties: [
523+
* 'classChanges: classSet | keyValDiff'
524+
* ]
529525
* })
530526
* class ClassSet {
531-
* set classChanges(changes:KeyValueChanges) {
527+
* set classChanges(changes: KeyValueChanges) {
532528
* // This will get called every time the `class-set` expressions changes its structure.
533529
* }
534530
* }
@@ -544,7 +540,7 @@ export class Directive extends Injectable {
544540
* keyValDiff`.
545541
*
546542
*/
547-
properties: StringMap<string, string>;
543+
properties: List<string>;
548544

549545
/**
550546
* Enumerates the set of emitted events.
@@ -756,7 +752,7 @@ export class Directive extends Injectable {
756752
hostActions, lifecycle, hostInjector, compileChildren = true,
757753
}: {
758754
selector?: string,
759-
properties?: any,
755+
properties?: List<string>,
760756
events?: List<string>,
761757
hostListeners?: StringMap<string, string>,
762758
hostProperties?: StringMap<string, string>,
@@ -981,7 +977,7 @@ export class Component extends Directive {
981977
hostActions, appInjector, lifecycle, hostInjector, viewInjector,
982978
changeDetection = DEFAULT, compileChildren = true}: {
983979
selector?: string,
984-
properties?: Object,
980+
properties?: List<string>,
985981
events?: List<string>,
986982
hostListeners?: Map<string, string>,
987983
hostProperties?: any,
@@ -1053,10 +1049,10 @@ export const onDestroy = CONST_EXPR(new LifecycleEvent("onDestroy"));
10531049
* ```
10541050
* @Directive({
10551051
* selector: '[class-set]',
1056-
* properties: {
1057-
* 'propA': 'propA'
1058-
* 'propB': 'propB'
1059-
* },
1052+
* properties: [
1053+
* 'propA',
1054+
* 'propB'
1055+
* ],
10601056
* lifecycle: [onChange]
10611057
* })
10621058
* class ClassSet {

modules/angular2/src/core/annotations_impl/visibility.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ export class Visibility extends DependencyAnnotation {
2121
* ```
2222
* @Directive({
2323
* selector: '[dependency]',
24-
* properties: {
25-
* 'id':'dependency'
26-
* }
24+
* properties: [
25+
* 'id: dependency'
26+
* ]
2727
* })
2828
* class Dependency {
2929
* id:string;
@@ -66,9 +66,9 @@ export var self = new Self();
6666
* ```
6767
* @Directive({
6868
* selector: '[dependency]',
69-
* properties: {
70-
* 'id':'dependency'
71-
* }
69+
* properties: [
70+
* 'id: dependency'
71+
* ]
7272
* })
7373
* class Dependency {
7474
* id:string;
@@ -118,9 +118,9 @@ export class Parent extends Visibility {
118118
* ```
119119
* @Directive({
120120
* selector: '[dependency]',
121-
* properties: {
122-
* 'id':'dependency'
123-
* }
121+
* properties: [
122+
* 'id: dependency'
123+
* ]
124124
* })
125125
* class Dependency {
126126
* id:string;
@@ -178,9 +178,9 @@ export class Ancestor extends Visibility {
178178
* ```
179179
* @Directive({
180180
* selector: '[dependency]',
181-
* properties: {
182-
* 'id':'dependency'
183-
* }
181+
* properties: [
182+
* 'id: dependency'
183+
* ]
184184
* })
185185
* class Dependency {
186186
* id:string;

modules/angular2/src/core/compiler/element_injector.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ export class DirectiveBinding extends ResolvedBinding {
300300
isPresent(ann.hostAttributes) ? MapWrapper.createFromStringMap(ann.hostAttributes) : null,
301301
hostActions: isPresent(ann.hostActions) ? MapWrapper.createFromStringMap(ann.hostActions) :
302302
null,
303-
properties: isPresent(ann.properties) ? MapWrapper.createFromStringMap(ann.properties) : null,
303+
properties: ann.properties,
304304
readAttributes: DirectiveBinding._readAttributes(deps),
305305

306306
callOnDestroy: hasLifecycleHook(onDestroy, rb.key.token, ann),

modules/angular2/src/directives/class.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {ElementRef} from 'angular2/core';
44
import {isPresent} from 'angular2/src/facade/lang';
55
import {DOM} from 'angular2/src/dom/dom_adapter';
66

7-
@Directive({selector: '[class]', properties: {'iterableChanges': 'class | keyValDiff'}})
7+
@Directive({selector: '[class]', properties: ['iterableChanges: class | keyValDiff']})
88
export class CSSClass {
99
_domEl;
1010
constructor(ngEl: ElementRef) { this._domEl = ngEl.domElement; }

modules/angular2/src/directives/ng_for.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import {ListWrapper} from 'angular2/src/facade/collection';
3636
* @exportedAs angular2/directives
3737
*/
3838
@Directive(
39-
{selector: '[ng-for][ng-for-of]', properties: {'iterableChanges': 'ngForOf | iterableDiff'}})
39+
{selector: '[ng-for][ng-for-of]', properties: ['iterableChanges: ngForOf | iterableDiff']})
4040
export class NgFor {
4141
viewContainer: ViewContainerRef;
4242
protoViewRef: ProtoViewRef;

modules/angular2/src/directives/ng_if.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import {isBlank} from 'angular2/src/facade/lang';
2727
*
2828
* @exportedAs angular2/directives
2929
*/
30-
@Directive({selector: '[ng-if]', properties: {'ngIf': 'ngIf'}})
30+
@Directive({selector: '[ng-if]', properties: ['ngIf']})
3131
export class NgIf {
3232
viewContainer: ViewContainerRef;
3333
protoViewRef: ProtoViewRef;

modules/angular2/src/directives/ng_switch.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export class SwitchView {
4444
*
4545
* @exportedAs angular2/directives
4646
*/
47-
@Directive({selector: '[ng-switch]', properties: {'ngSwitch': 'ngSwitch'}})
47+
@Directive({selector: '[ng-switch]', properties: ['ngSwitch']})
4848
export class NgSwitch {
4949
_switchValue: any;
5050
_useDefault: boolean;
@@ -153,7 +153,7 @@ export class NgSwitch {
153153
*
154154
* @exportedAs angular2/directives
155155
*/
156-
@Directive({selector: '[ng-switch-when]', properties: {'ngSwitchWhen': 'ngSwitchWhen'}})
156+
@Directive({selector: '[ng-switch-when]', properties: ['ngSwitchWhen']})
157157
export class NgSwitchWhen {
158158
_value: any;
159159
_switch: NgSwitch;

modules/angular2/src/forms/directives.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ function _lookupControl(groupDirective: ControlGroupDirective, controlOrName: an
7373
*
7474
* @exportedAs angular2/forms
7575
*/
76-
@Directive({selector: '[control-group]', properties: {'controlOrName': 'control-group'}})
76+
@Directive({selector: '[control-group]', properties: ['controlOrName: control-group']})
7777
export class ControlGroupDirective {
7878
_groupDirective: ControlGroupDirective;
7979
_directives: List<ControlDirective>;
@@ -133,7 +133,7 @@ export class ControlGroupDirective {
133133
*
134134
* @exportedAs angular2/forms
135135
*/
136-
@Directive({selector: '[control]', properties: {'controlOrName': 'control'}})
136+
@Directive({selector: '[control]', properties: ['controlOrName: control']})
137137
export class ControlDirective {
138138
_groupDirective: ControlGroupDirective;
139139

modules/angular2/src/render/api.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ export class DirectiveMetadata {
133133
hostProperties: Map<string, string>;
134134
hostAttributes: Map<string, string>;
135135
hostActions: Map<string, string>;
136-
properties: Map<string, string>;
136+
properties: List<string>;
137137
readAttributes: List<string>;
138138
type: number;
139139
callOnDestroy: boolean;
@@ -153,7 +153,7 @@ export class DirectiveMetadata {
153153
hostProperties?: Map<string, string>,
154154
hostAttributes?: Map<string, string>,
155155
hostActions?: Map<string, string>,
156-
properties?: Map<string, string>,
156+
properties?: List<string>,
157157
readAttributes?: List<string>,
158158
type?: number,
159159
callOnDestroy?: boolean,

0 commit comments

Comments
 (0)