From b73ba682150a1ad77ca85bf7bd7d40339eae3fb0 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Sat, 4 Jul 2015 15:04:50 +0200 Subject: [PATCH] refactor(LifecycleEvent): change from onInit to Lifecycle.onInit BREAKING CHANGE Closes #2928 --- modules/angular2/annotations.ts | 7 +- .../src/core/annotations/annotations.ts | 7 +- .../src/core/annotations_impl/annotations.ts | 254 +++++++++--------- .../directive_lifecycle_reflector.dart | 10 +- .../compiler/directive_lifecycle_reflector.ts | 18 +- .../src/core/compiler/element_injector.ts | 20 +- modules/angular2/src/directives/class.ts | 5 +- modules/angular2/src/directives/ng_for.ts | 12 +- modules/angular2/src/directives/ng_style.ts | 8 +- .../src/forms/directives/ng_control_group.ts | 6 +- .../src/forms/directives/ng_control_name.ts | 7 +- .../src/forms/directives/ng_form_control.ts | 5 +- .../src/forms/directives/ng_form_model.ts | 4 +- .../angular2/src/forms/directives/ng_model.ts | 5 +- .../select_control_value_accessor.ts | 3 +- .../common/directive_metadata_reader.dart | 2 +- .../compiler/directive_lifecycle_spec.dart | 10 +- .../core/compiler/directive_lifecycle_spec.ts | 26 +- .../compiler/dynamic_component_loader_spec.ts | 4 +- .../core/compiler/element_injector_spec.ts | 4 +- .../core/compiler/integration_dart_spec.dart | 2 +- .../directive_lifecycle_integration_spec.ts | 17 +- .../changeDetection.ng_deps.dart | 6 +- .../directive_export_as.ng_deps.dart | 6 +- .../events.ng_deps.dart | 6 +- .../lifecycle.ng_deps.dart | 9 +- .../src/components/button/button.ts | 4 +- .../src/components/grid_list/grid_list.ts | 6 +- .../src/components/input/input.ts | 4 +- .../progress-linear/progress_linear.ts | 4 +- .../src/components/radio/radio_button.ts | 14 +- 31 files changed, 245 insertions(+), 250 deletions(-) diff --git a/modules/angular2/annotations.ts b/modules/angular2/annotations.ts index ffa5d5663e..9f12b64e12 100644 --- a/modules/angular2/annotations.ts +++ b/modules/angular2/annotations.ts @@ -13,12 +13,7 @@ export { ComponentAnnotation, DirectiveAnnotation, - LifecycleEvent, - onDestroy, - onChange, - onCheck, - onInit, - onAllChangesDone + LifecycleEvent } from './src/core/annotations/annotations'; export {ViewAnnotation} from 'angular2/src/core/annotations/view'; diff --git a/modules/angular2/src/core/annotations/annotations.ts b/modules/angular2/src/core/annotations/annotations.ts index 443b173071..97833ac6d0 100644 --- a/modules/angular2/src/core/annotations/annotations.ts +++ b/modules/angular2/src/core/annotations/annotations.ts @@ -6,10 +6,5 @@ export { Component as ComponentAnnotation, Directive as DirectiveAnnotation, - LifecycleEvent, - onDestroy, - onChange, - onCheck, - onInit, - onAllChangesDone + LifecycleEvent } from '../annotations_impl/annotations'; diff --git a/modules/angular2/src/core/annotations_impl/annotations.ts b/modules/angular2/src/core/annotations_impl/annotations.ts index 3408a7e555..ab45048618 100644 --- a/modules/angular2/src/core/annotations_impl/annotations.ts +++ b/modules/angular2/src/core/annotations_impl/annotations.ts @@ -933,130 +933,132 @@ export class Component extends Directive { * - `onCheck`, * - `onAllChangesDone` */ -@CONST() -export class LifecycleEvent { - constructor(public name: string) {} +export enum LifecycleEvent { + /** + * Notify a directive whenever a {@link View} that contains it is destroyed. + * + * ## Example + * + * ``` + * @Directive({ + * ..., + * lifecycle: [LifecycleEvent.onDestroy] + * }) + * class ClassSet { + * onDestroy() { + * // invoked to notify directive of the containing view destruction. + * } + * } + * ``` + * @exportedAs angular2/annotations + */ + onDestroy, + + + /** + * Notify a directive when any of its bindings have changed. + * + * This method is called right after the directive's bindings have been checked, + * and before any of its children's bindings have been checked. + * + * It is invoked only if at least one of the directive's bindings has changed. + * + * ## Example: + * + * ``` + * @Directive({ + * selector: '[class-set]', + * properties: [ + * 'propA', + * 'propB' + * ], + * lifecycle: [LifecycleEvent.onChange] + * }) + * class ClassSet { + * propA; + * propB; + * onChange(changes:{[idx: string, PropertyUpdate]}) { + * // This will get called after any of the properties have been updated. + * if (changes['propA']) { + * // if propA was updated + * } + * if (changes['propA']) { + * // if propB was updated + * } + * } + * } + * ``` + * @exportedAs angular2/annotations + */ + onChange, + + /** + * Notify a directive when it has been checked. + * + * This method is called right after the directive's bindings have been checked, + * and before any of its children's bindings have been checked. + * + * It is invoked every time even when none of the directive's bindings has changed. + * + * ## Example: + * + * ``` + * @Directive({ + * selector: '[class-set]', + * lifecycle: [LifecycleEvent.onCheck] + * }) + * class ClassSet { + * onCheck() { + * } + * } + * ``` + * @exportedAs angular2/annotations + */ + onCheck, + + /** + * Notify a directive when it has been checked the first itme. + * + * This method is called right after the directive's bindings have been checked, + * and before any of its children's bindings have been checked. + * + * It is invoked only once. + * + * ## Example: + * + * ``` + * @Directive({ + * selector: '[class-set]', + * lifecycle: [LifecycleEvent.onInit] + * }) + * class ClassSet { + * onInit() { + * } + * } + * ``` + * @exportedAs angular2/annotations + */ + onInit, + + /** + * Notify a directive when the bindings of all its children have been checked (whether they have + * changed or not). + * + * ## Example: + * + * ``` + * @Directive({ + * selector: '[class-set]', + * lifecycle: [LifecycleEvent.onAllChangesDone] + * }) + * class ClassSet { + * + * onAllChangesDone() { + * } + * + * } + * ``` + * @exportedAs angular2/annotations + */ + onAllChangesDone } - -/** - * Notify a directive whenever a {@link View} that contains it is destroyed. - * - * ## Example - * - * ``` - * @Directive({ - * ..., - * lifecycle: [onDestroy] - * }) - * class ClassSet { - * onDestroy() { - * // invoked to notify directive of the containing view destruction. - * } - * } - * ``` - */ -export const onDestroy: LifecycleEvent = CONST_EXPR(new LifecycleEvent("onDestroy")); - - -/** - * Notify a directive when any of its bindings have changed. - * - * This method is called right after the directive's bindings have been checked, - * and before any of its children's bindings have been checked. - * - * It is invoked only if at least one of the directive's bindings has changed. - * - * ## Example: - * - * ``` - * @Directive({ - * selector: '[class-set]', - * properties: [ - * 'propA', - * 'propB' - * ], - * lifecycle: [onChange] - * }) - * class ClassSet { - * propA; - * propB; - * onChange(changes:{[idx: string, PropertyUpdate]}) { - * // This will get called after any of the properties have been updated. - * if (changes['propA']) { - * // if propA was updated - * } - * if (changes['propA']) { - * // if propB was updated - * } - * } - * } - * ``` - */ -export const onChange: LifecycleEvent = CONST_EXPR(new LifecycleEvent("onChange")); - -/** - * Notify a directive when it has been checked. - * - * This method is called right after the directive's bindings have been checked, - * and before any of its children's bindings have been checked. - * - * It is invoked every time even when none of the directive's bindings has changed. - * - * ## Example: - * - * ``` - * @Directive({ - * selector: '[class-set]', - * lifecycle: [onCheck] - * }) - * class ClassSet { - * onCheck() { - * } - * } - * ``` - */ -export const onCheck: LifecycleEvent = CONST_EXPR(new LifecycleEvent("onCheck")); - -/** - * Notify a directive when it has been checked the first itme. - * - * This method is called right after the directive's bindings have been checked, - * and before any of its children's bindings have been checked. - * - * It is invoked only once. - * - * ## Example: - * - * ``` - * @Directive({ - * selector: '[class-set]', - * lifecycle: [onInit] - * }) - * class ClassSet { - * onInit() { - * } - * } - * ``` - */ -export const onInit: LifecycleEvent = CONST_EXPR(new LifecycleEvent("onInit")); - -/** - * Notify a directive when the bindings of all its children have been checked (whether they have - * changed or not). - * - * ## Example: - * - * ``` - * @Directive({ - * selector: '[class-set]', - * lifecycle: [onAllChangesDone] - * }) - * class ClassSet { - * - * onAllChangesDone() { - * } - * - * } - * ``` - */ -export const onAllChangesDone: LifecycleEvent = CONST_EXPR(new LifecycleEvent("onAllChangesDone")); diff --git a/modules/angular2/src/core/compiler/directive_lifecycle_reflector.dart b/modules/angular2/src/core/compiler/directive_lifecycle_reflector.dart index c035e996d5..e3a558060b 100644 --- a/modules/angular2/src/core/compiler/directive_lifecycle_reflector.dart +++ b/modules/angular2/src/core/compiler/directive_lifecycle_reflector.dart @@ -11,15 +11,15 @@ bool hasLifecycleHook(LifecycleEvent e, type, Directive annotation) { final List interfaces = reflector.interfaces(type); var interface; - if (e == onChange) { + if (e == LifecycleEvent.onChange) { interface = OnChange; - } else if (e == onDestroy) { + } else if (e == LifecycleEvent.onDestroy) { interface = OnDestroy; - } else if (e == onAllChangesDone) { + } else if (e == LifecycleEvent.onAllChangesDone) { interface = OnAllChangesDone; - } else if (e == onCheck) { + } else if (e == LifecycleEvent.onCheck) { interface = OnCheck; - } else if (e == onInit) { + } else if (e == LifecycleEvent.onInit) { interface = OnInit; } diff --git a/modules/angular2/src/core/compiler/directive_lifecycle_reflector.ts b/modules/angular2/src/core/compiler/directive_lifecycle_reflector.ts index f58af0c12a..c545f5040a 100644 --- a/modules/angular2/src/core/compiler/directive_lifecycle_reflector.ts +++ b/modules/angular2/src/core/compiler/directive_lifecycle_reflector.ts @@ -6,6 +6,20 @@ export function hasLifecycleHook(e: LifecycleEvent, type, annotation: Directive) return annotation.lifecycle.indexOf(e) !== -1; } else { if (!(type instanceof Type)) return false; - return e.name in(type).prototype; + var proto = (type).prototype; + switch (e) { + case LifecycleEvent.onAllChangesDone: + return !!proto.onAllChangesDone; + case LifecycleEvent.onChange: + return !!proto.onChange; + case LifecycleEvent.onCheck: + return !!proto.onCheck; + case LifecycleEvent.onDestroy: + return !!proto.onDestroy; + case LifecycleEvent.onInit: + return !!proto.onInit; + default: + return false; + } } -} \ No newline at end of file +} diff --git a/modules/angular2/src/core/compiler/element_injector.ts b/modules/angular2/src/core/compiler/element_injector.ts index 59b092d57c..47a8da9a9c 100644 --- a/modules/angular2/src/core/compiler/element_injector.ts +++ b/modules/angular2/src/core/compiler/element_injector.ts @@ -41,15 +41,7 @@ import * as avmModule from './view_manager'; import {ViewContainerRef} from './view_container_ref'; import {ElementRef} from './element_ref'; import {ProtoViewRef, ViewRef} from './view_ref'; -import { - Directive, - Component, - onChange, - onDestroy, - onCheck, - onInit, - onAllChangesDone -} from 'angular2/src/core/annotations_impl/annotations'; +import {Directive, Component, LifecycleEvent} from 'angular2/src/core/annotations_impl/annotations'; import {hasLifecycleHook} from './directive_lifecycle_reflector'; import {ChangeDetector, ChangeDetectorRef, Pipes} from 'angular2/change_detection'; import {QueryList} from './query_list'; @@ -253,11 +245,11 @@ export class DirectiveBinding extends ResolvedBinding { properties: ann.properties, readAttributes: DirectiveBinding._readAttributes(deps), - callOnDestroy: hasLifecycleHook(onDestroy, rb.key.token, ann), - callOnChange: hasLifecycleHook(onChange, rb.key.token, ann), - callOnCheck: hasLifecycleHook(onCheck, rb.key.token, ann), - callOnInit: hasLifecycleHook(onInit, rb.key.token, ann), - callOnAllChangesDone: hasLifecycleHook(onAllChangesDone, rb.key.token, ann), + callOnDestroy: hasLifecycleHook(LifecycleEvent.onDestroy, rb.key.token, ann), + callOnChange: hasLifecycleHook(LifecycleEvent.onChange, rb.key.token, ann), + callOnCheck: hasLifecycleHook(LifecycleEvent.onCheck, rb.key.token, ann), + callOnInit: hasLifecycleHook(LifecycleEvent.onInit, rb.key.token, ann), + callOnAllChangesDone: hasLifecycleHook(LifecycleEvent.onAllChangesDone, rb.key.token, ann), changeDetection: ann instanceof Component ? ann.changeDetection : null, diff --git a/modules/angular2/src/directives/class.ts b/modules/angular2/src/directives/class.ts index e1cd948b9a..f55ec06ec4 100644 --- a/modules/angular2/src/directives/class.ts +++ b/modules/angular2/src/directives/class.ts @@ -1,4 +1,4 @@ -import {Directive, onCheck} from 'angular2/annotations'; +import {Directive, LifecycleEvent} from 'angular2/annotations'; import {ElementRef} from 'angular2/core'; import {Pipes} from 'angular2/src/change_detection/pipes/pipes'; import {Pipe} from 'angular2/src/change_detection/pipes/pipe'; @@ -28,7 +28,8 @@ import {ListWrapper, StringMapWrapper, isListLikeIterable} from 'angular2/src/fa * * ``` */ -@Directive({selector: '[class]', lifecycle: [onCheck], properties: ['rawClass: class']}) +@Directive( + {selector: '[class]', lifecycle: [LifecycleEvent.onCheck], properties: ['rawClass: class']}) export class CSSClass { _pipe: Pipe; _rawClass; diff --git a/modules/angular2/src/directives/ng_for.ts b/modules/angular2/src/directives/ng_for.ts index aa108e0cac..3e1a4492de 100644 --- a/modules/angular2/src/directives/ng_for.ts +++ b/modules/angular2/src/directives/ng_for.ts @@ -1,5 +1,12 @@ import {Directive} from 'angular2/annotations'; -import {ViewContainerRef, ViewRef, ProtoViewRef, Pipes, onCheck, Pipe} from 'angular2/angular2'; +import { + ViewContainerRef, + ViewRef, + ProtoViewRef, + Pipes, + LifecycleEvent, + Pipe +} from 'angular2/angular2'; import {isPresent, isBlank} from 'angular2/src/facade/lang'; /** @@ -32,7 +39,8 @@ import {isPresent, isBlank} from 'angular2/src/facade/lang'; * - `
  • ...
  • ` * - `` */ -@Directive({selector: '[ng-for][ng-for-of]', properties: ['ngForOf'], lifecycle: [onCheck]}) +@Directive( + {selector: '[ng-for][ng-for-of]', properties: ['ngForOf'], lifecycle: [LifecycleEvent.onCheck]}) export class NgFor { _ngForOf: any; _pipe: Pipe; diff --git a/modules/angular2/src/directives/ng_style.ts b/modules/angular2/src/directives/ng_style.ts index 733b82ac4e..f1a60df0f9 100644 --- a/modules/angular2/src/directives/ng_style.ts +++ b/modules/angular2/src/directives/ng_style.ts @@ -1,4 +1,4 @@ -import {Directive, onCheck} from 'angular2/annotations'; +import {Directive, LifecycleEvent} from 'angular2/annotations'; import {ElementRef} from 'angular2/core'; import {Pipe} from 'angular2/src/change_detection/pipes/pipe'; import {Pipes} from 'angular2/src/change_detection/pipes/pipes'; @@ -27,7 +27,11 @@ import {Renderer} from 'angular2/src/render/api'; * - `
    ` * - `
    ` */ -@Directive({selector: '[ng-style]', lifecycle: [onCheck], properties: ['rawStyle: ng-style']}) +@Directive({ + selector: '[ng-style]', + lifecycle: [LifecycleEvent.onCheck], + properties: ['rawStyle: ng-style'] +}) export class NgStyle { _pipe: Pipe; _rawStyle; diff --git a/modules/angular2/src/forms/directives/ng_control_group.ts b/modules/angular2/src/forms/directives/ng_control_group.ts index fee6fe2101..6ee7f10c30 100644 --- a/modules/angular2/src/forms/directives/ng_control_group.ts +++ b/modules/angular2/src/forms/directives/ng_control_group.ts @@ -1,4 +1,4 @@ -import {Directive, onDestroy, onInit} from 'angular2/annotations'; +import {Directive, LifecycleEvent} from 'angular2/angular2'; import {Inject, Ancestor, forwardRef, Binding} from 'angular2/di'; import {List, ListWrapper} from 'angular2/src/facade/collection'; import {CONST_EXPR} from 'angular2/src/facade/lang'; @@ -52,7 +52,7 @@ const controlGroupBinding = selector: '[ng-control-group]', hostInjector: [controlGroupBinding], properties: ['name: ng-control-group'], - lifecycle: [onInit, onDestroy], + lifecycle: [LifecycleEvent.onInit, LifecycleEvent.onDestroy], exportAs: 'form' }) export class NgControlGroup extends ControlContainer { @@ -71,4 +71,4 @@ export class NgControlGroup extends ControlContainer { get path(): List { return controlPath(this.name, this._parent); } get formDirective(): Form { return this._parent.formDirective; } -} \ No newline at end of file +} diff --git a/modules/angular2/src/forms/directives/ng_control_name.ts b/modules/angular2/src/forms/directives/ng_control_name.ts index 2999664504..e0d085ee55 100644 --- a/modules/angular2/src/forms/directives/ng_control_name.ts +++ b/modules/angular2/src/forms/directives/ng_control_name.ts @@ -2,8 +2,7 @@ import {CONST_EXPR} from 'angular2/src/facade/lang'; import {EventEmitter, ObservableWrapper} from 'angular2/src/facade/async'; import {List, StringMapWrapper, StringMap} from 'angular2/src/facade/collection'; -import {Directive, Query, onDestroy, onChange} from 'angular2/annotations'; -import {QueryList} from 'angular2/core'; +import {Directive, LifecycleEvent, Query, QueryList} from 'angular2/angular2'; import {forwardRef, Ancestor, Binding, Inject} from 'angular2/di'; import {ControlContainer} from './control_container'; @@ -76,7 +75,7 @@ const controlNameBinding = hostInjector: [controlNameBinding], properties: ['name: ngControl', 'model: ngModel'], events: ['update: ngModel'], - lifecycle: [onDestroy, onChange], + lifecycle: [LifecycleEvent.onDestroy, LifecycleEvent.onChange], exportAs: 'form' }) export class NgControlName extends NgControl { @@ -115,4 +114,4 @@ export class NgControlName extends NgControl { get control(): Control { return this.formDirective.getControl(this); } get validator(): Function { return composeNgValidator(this.ngValidators); } -} \ No newline at end of file +} diff --git a/modules/angular2/src/forms/directives/ng_form_control.ts b/modules/angular2/src/forms/directives/ng_form_control.ts index 2689f18a17..82364a7262 100644 --- a/modules/angular2/src/forms/directives/ng_form_control.ts +++ b/modules/angular2/src/forms/directives/ng_form_control.ts @@ -2,8 +2,7 @@ import {CONST_EXPR} from 'angular2/src/facade/lang'; import {StringMapWrapper} from 'angular2/src/facade/collection'; import {EventEmitter, ObservableWrapper} from 'angular2/src/facade/async'; -import {Directive, Query, onChange} from 'angular2/annotations'; -import {QueryList} from 'angular2/core'; +import {Directive, LifecycleEvent, Query, QueryList} from 'angular2/angular2'; import {forwardRef, Ancestor, Binding} from 'angular2/di'; import {NgControl} from './ng_control'; @@ -64,7 +63,7 @@ const formControlBinding = hostInjector: [formControlBinding], properties: ['form: ngFormControl', 'model: ngModel'], events: ['update: ngModel'], - lifecycle: [onChange], + lifecycle: [LifecycleEvent.onChange], exportAs: 'form' }) export class NgFormControl extends NgControl { diff --git a/modules/angular2/src/forms/directives/ng_form_model.ts b/modules/angular2/src/forms/directives/ng_form_model.ts index 6b289d37e9..8abfcbfcfa 100644 --- a/modules/angular2/src/forms/directives/ng_form_model.ts +++ b/modules/angular2/src/forms/directives/ng_form_model.ts @@ -2,7 +2,7 @@ import {CONST_EXPR} from 'angular2/src/facade/lang'; import {List, ListWrapper} from 'angular2/src/facade/collection'; import {ObservableWrapper, EventEmitter} from 'angular2/src/facade/async'; -import {Directive, onChange} from 'angular2/annotations'; +import {Directive, LifecycleEvent} from 'angular2/angular2'; import {forwardRef, Binding} from 'angular2/di'; import {NgControl} from './ng_control'; import {NgControlGroup} from './ng_control_group'; @@ -84,7 +84,7 @@ const formDirectiveBinding = selector: '[ng-form-model]', hostInjector: [formDirectiveBinding], properties: ['form: ng-form-model'], - lifecycle: [onChange], + lifecycle: [LifecycleEvent.onChange], host: { '(submit)': 'onSubmit()', }, diff --git a/modules/angular2/src/forms/directives/ng_model.ts b/modules/angular2/src/forms/directives/ng_model.ts index 814412adba..4cadab3282 100644 --- a/modules/angular2/src/forms/directives/ng_model.ts +++ b/modules/angular2/src/forms/directives/ng_model.ts @@ -2,8 +2,7 @@ import {CONST_EXPR} from 'angular2/src/facade/lang'; import {EventEmitter, ObservableWrapper} from 'angular2/src/facade/async'; import {StringMapWrapper} from 'angular2/src/facade/collection'; -import {Directive, Query, onChange} from 'angular2/annotations'; -import {QueryList} from 'angular2/core'; +import {Directive, LifecycleEvent, QueryList, Query} from 'angular2/angular2'; import {forwardRef, Ancestor, Binding} from 'angular2/di'; import {NgControl} from './ng_control'; @@ -34,7 +33,7 @@ const formControlBinding = CONST_EXPR(new Binding(NgControl, {toAlias: forwardRe hostInjector: [formControlBinding], properties: ['model: ngModel'], events: ['update: ngModel'], - lifecycle: [onChange], + lifecycle: [LifecycleEvent.onChange], exportAs: 'form' }) export class NgModel extends NgControl { diff --git a/modules/angular2/src/forms/directives/select_control_value_accessor.ts b/modules/angular2/src/forms/directives/select_control_value_accessor.ts index db0e39c661..d6eac0e031 100644 --- a/modules/angular2/src/forms/directives/select_control_value_accessor.ts +++ b/modules/angular2/src/forms/directives/select_control_value_accessor.ts @@ -1,6 +1,5 @@ import {Renderer} from 'angular2/render'; -import {ElementRef, QueryList} from 'angular2/core'; -import {Directive, Query, onDestroy, onChange} from 'angular2/annotations'; +import {ElementRef, QueryList, Directive, Query} from 'angular2/angular2'; import {NgControl} from './ng_control'; import {ControlValueAccessor} from './control_value_accessor'; diff --git a/modules/angular2/src/transform/common/directive_metadata_reader.dart b/modules/angular2/src/transform/common/directive_metadata_reader.dart index 071168ade7..7d948bc59d 100644 --- a/modules/angular2/src/transform/common/directive_metadata_reader.dart +++ b/modules/angular2/src/transform/common/directive_metadata_reader.dart @@ -261,7 +261,7 @@ class _DirectiveMetadataVisitor extends Object '$lifecycleValue'); } ListLiteral l = lifecycleValue; - var lifecycleEvents = l.elements.map((s) => s.toSource()); + var lifecycleEvents = l.elements.map((s) => s.toSource().split('.').last); _callOnDestroy = lifecycleEvents.contains("onDestroy"); _callOnChange = lifecycleEvents.contains("onChange"); _callOnCheck = lifecycleEvents.contains("onCheck"); diff --git a/modules/angular2/test/core/compiler/directive_lifecycle_spec.dart b/modules/angular2/test/core/compiler/directive_lifecycle_spec.dart index 29219250f7..ffcfe14f96 100644 --- a/modules/angular2/test/core/compiler/directive_lifecycle_spec.dart +++ b/modules/angular2/test/core/compiler/directive_lifecycle_spec.dart @@ -19,7 +19,7 @@ main() { it("should be true when the lifecycle includes onChange", () { expect(metadata(DirectiveNoHooks, - new Directive(lifecycle: [onChange])).callOnChange).toBe(true); + new Directive(lifecycle: [LifecycleEvent.onChange])).callOnChange).toBe(true); }); it("should be false otherwise", () { @@ -41,7 +41,7 @@ main() { it("should be true when the lifecycle includes onDestroy", () { expect(metadata(DirectiveNoHooks, - new Directive(lifecycle: [onDestroy])).callOnDestroy).toBe(true); + new Directive(lifecycle: [LifecycleEvent.onDestroy])).callOnDestroy).toBe(true); }); it("should be false otherwise", () { @@ -59,7 +59,7 @@ main() { it("should be true when the lifecycle includes onCheck", () { expect(metadata(DirectiveNoHooks, - new Directive(lifecycle: [onCheck])).callOnCheck).toBe(true); + new Directive(lifecycle: [LifecycleEvent.onCheck])).callOnCheck).toBe(true); }); it("should be false otherwise", () { @@ -77,7 +77,7 @@ main() { it("should be true when the lifecycle includes onInit", () { expect(metadata(DirectiveNoHooks, - new Directive(lifecycle: [onInit])).callOnInit).toBe(true); + new Directive(lifecycle: [LifecycleEvent.onInit])).callOnInit).toBe(true); }); it("should be false otherwise", () { @@ -94,7 +94,7 @@ main() { it("should be true when the lifecycle includes onAllChangesDone", () { expect(metadata(DirectiveNoHooks, new Directive( - lifecycle: [onAllChangesDone])).callOnAllChangesDone).toBe(true); + lifecycle: [LifecycleEvent.onAllChangesDone])).callOnAllChangesDone).toBe(true); }); it("should be false otherwise", () { diff --git a/modules/angular2/test/core/compiler/directive_lifecycle_spec.ts b/modules/angular2/test/core/compiler/directive_lifecycle_spec.ts index 8e5bc5f739..2b0d387b53 100644 --- a/modules/angular2/test/core/compiler/directive_lifecycle_spec.ts +++ b/modules/angular2/test/core/compiler/directive_lifecycle_spec.ts @@ -14,14 +14,7 @@ import { proxy } from 'angular2/test_lib'; -import { - Directive, - onChange, - onDestroy, - onCheck, - onInit, - onAllChangesDone -} from 'angular2/src/core/annotations_impl/annotations'; +import {Directive, LifecycleEvent} from 'angular2/src/core/annotations_impl/annotations'; import {DirectiveBinding} from 'angular2/src/core/compiler/element_injector'; export function main() { @@ -37,7 +30,8 @@ export function main() { }); it("should be true when the lifecycle includes onChange", () => { - expect(metadata(DirectiveNoHooks, new Directive({lifecycle: [onChange]})).callOnChange) + expect(metadata(DirectiveNoHooks, new Directive({lifecycle: [LifecycleEvent.onChange]})) + .callOnChange) .toBe(true); }); @@ -57,7 +51,8 @@ export function main() { }); it("should be true when the lifecycle includes onDestroy", () => { - expect(metadata(DirectiveNoHooks, new Directive({lifecycle: [onDestroy]})).callOnDestroy) + expect(metadata(DirectiveNoHooks, new Directive({lifecycle: [LifecycleEvent.onDestroy]})) + .callOnDestroy) .toBe(true); }); @@ -72,7 +67,8 @@ export function main() { }); it("should be true when the lifecycle includes onDestroy", () => { - expect(metadata(DirectiveNoHooks, new Directive({lifecycle: [onInit]})).callOnInit) + expect(metadata(DirectiveNoHooks, new Directive({lifecycle: [LifecycleEvent.onInit]})) + .callOnInit) .toBe(true); }); @@ -86,7 +82,8 @@ export function main() { }); it("should be true when the lifecycle includes onCheck", () => { - expect(metadata(DirectiveNoHooks, new Directive({lifecycle: [onCheck]})).callOnCheck) + expect(metadata(DirectiveNoHooks, new Directive({lifecycle: [LifecycleEvent.onCheck]})) + .callOnCheck) .toBe(true); }); @@ -102,7 +99,8 @@ export function main() { }); it("should be true when the lifecycle includes onAllChangesDone", () => { - expect(metadata(DirectiveNoHooks, new Directive({lifecycle: [onAllChangesDone]})) + expect(metadata(DirectiveNoHooks, + new Directive({lifecycle: [LifecycleEvent.onAllChangesDone]})) .callOnAllChangesDone) .toBe(true); }); @@ -135,4 +133,4 @@ class DirectiveWithOnDestroyMethod { class DirectiveWithOnAllChangesDoneMethod { onAllChangesDone() {} -} \ No newline at end of file +} diff --git a/modules/angular2/test/core/compiler/dynamic_component_loader_spec.ts b/modules/angular2/test/core/compiler/dynamic_component_loader_spec.ts index 038e717fbb..7c2b503161 100644 --- a/modules/angular2/test/core/compiler/dynamic_component_loader_spec.ts +++ b/modules/angular2/test/core/compiler/dynamic_component_loader_spec.ts @@ -21,7 +21,7 @@ import { import {Injector} from 'angular2/di'; import {NgIf} from 'angular2/directives'; -import {Component, View, onDestroy} from 'angular2/annotations'; +import {Component, View, LifecycleEvent} from 'angular2/annotations'; import * as viewAnn from 'angular2/src/core/annotations_impl/view'; import {DynamicComponentLoader} from 'angular2/src/core/compiler/dynamic_component_loader'; import {ElementRef} from 'angular2/src/core/compiler/element_ref'; @@ -267,7 +267,7 @@ class DynamicallyCreatedComponentService {} @Component({ selector: 'hello-cmp', viewInjector: [DynamicallyCreatedComponentService], - lifecycle: [onDestroy] + lifecycle: [LifecycleEvent.onDestroy] }) @View({template: "{{greeting}}"}) class DynamicallyCreatedCmp { diff --git a/modules/angular2/test/core/compiler/element_injector_spec.ts b/modules/angular2/test/core/compiler/element_injector_spec.ts index 93f100e14a..53c26b2343 100644 --- a/modules/angular2/test/core/compiler/element_injector_spec.ts +++ b/modules/angular2/test/core/compiler/element_injector_spec.ts @@ -38,7 +38,7 @@ import { Query, Component, Directive, - onDestroy + LifecycleEvent } from 'angular2/annotations'; import {bind, Injector, Binding, Optional, Inject, Injectable, Self, Parent, Ancestor, Unbounded, InjectMetadata, ParentMetadata} from 'angular2/di'; import {AppProtoView, AppView} from 'angular2/src/core/compiler/view'; @@ -831,7 +831,7 @@ export function main() { it("should call onDestroy on directives subscribed to this event", () => { var inj = injector(ListWrapper.concat( [DirectiveBinding.createFromType(DirectiveWithDestroy, - new dirAnn.Directive({lifecycle: [onDestroy]}))], + new dirAnn.Directive({lifecycle: [LifecycleEvent.onDestroy]}))], extraBindings)); var destroy = inj.get(DirectiveWithDestroy); inj.dehydrate(); diff --git a/modules/angular2/test/core/compiler/integration_dart_spec.dart b/modules/angular2/test/core/compiler/integration_dart_spec.dart index 068a9186eb..fdc214fd7d 100644 --- a/modules/angular2/test/core/compiler/integration_dart_spec.dart +++ b/modules/angular2/test/core/compiler/integration_dart_spec.dart @@ -195,7 +195,7 @@ class NoPropertyAccess { @Component(selector: 'on-change', // TODO: needed because of https://github.com/angular/angular/issues/2120 - lifecycle: const [onChange], properties: const ['prop']) + lifecycle: const [LifecycleEvent.onChange], properties: const ['prop']) @View(template: '') class OnChangeComponent implements OnChange { Map changes; diff --git a/modules/angular2/test/core/directive_lifecycle_integration_spec.ts b/modules/angular2/test/core/directive_lifecycle_integration_spec.ts index 252ab5bc0a..622fd88009 100644 --- a/modules/angular2/test/core/directive_lifecycle_integration_spec.ts +++ b/modules/angular2/test/core/directive_lifecycle_integration_spec.ts @@ -14,15 +14,7 @@ import { } from 'angular2/test_lib'; import {ListWrapper} from 'angular2/src/facade/collection'; -import { - Directive, - Component, - View, - onCheck, - onInit, - onChange, - onAllChangesDone -} from 'angular2/angular2'; +import {Directive, Component, View, LifecycleEvent} from 'angular2/angular2'; import * as viewAnn from 'angular2/src/core/annotations_impl/view'; export function main() { @@ -62,7 +54,12 @@ export function main() { @Directive({ selector: "[lifecycle]", properties: ['field'], - lifecycle: [onChange, onCheck, onInit, onAllChangesDone] + lifecycle: [ + LifecycleEvent.onChange, + LifecycleEvent.onCheck, + LifecycleEvent.onInit, + LifecycleEvent.onAllChangesDone + ] }) class LifecycleDir { field; diff --git a/modules/angular2/test/transform/directive_metadata_extractor/directive_metadata_files/changeDetection.ng_deps.dart b/modules/angular2/test/transform/directive_metadata_extractor/directive_metadata_files/changeDetection.ng_deps.dart index fca8e31f23..f6fa1925a1 100644 --- a/modules/angular2/test/transform/directive_metadata_extractor/directive_metadata_files/changeDetection.ng_deps.dart +++ b/modules/angular2/test/transform/directive_metadata_extractor/directive_metadata_files/changeDetection.ng_deps.dart @@ -8,11 +8,7 @@ import 'package:angular2/angular2.dart' Directive, View, NgElement, - onChange, - onDestroy, - onInit, - onCheck, - onAllChangesDone; + LifecycleEvent; var _visited = false; void initReflector(reflector) { diff --git a/modules/angular2/test/transform/directive_metadata_extractor/directive_metadata_files/directive_export_as.ng_deps.dart b/modules/angular2/test/transform/directive_metadata_extractor/directive_metadata_files/directive_export_as.ng_deps.dart index 8c414c9998..bedeff7381 100644 --- a/modules/angular2/test/transform/directive_metadata_extractor/directive_metadata_files/directive_export_as.ng_deps.dart +++ b/modules/angular2/test/transform/directive_metadata_extractor/directive_metadata_files/directive_export_as.ng_deps.dart @@ -8,11 +8,7 @@ import 'package:angular2/angular2.dart' Directive, View, NgElement, - onChange, - onDestroy, - onInit, - onCheck, - onAllChangesDone; + LifecycleEvent; var _visited = false; void initReflector(reflector) { diff --git a/modules/angular2/test/transform/directive_metadata_extractor/directive_metadata_files/events.ng_deps.dart b/modules/angular2/test/transform/directive_metadata_extractor/directive_metadata_files/events.ng_deps.dart index 9227814796..689f71830c 100644 --- a/modules/angular2/test/transform/directive_metadata_extractor/directive_metadata_files/events.ng_deps.dart +++ b/modules/angular2/test/transform/directive_metadata_extractor/directive_metadata_files/events.ng_deps.dart @@ -8,11 +8,7 @@ import 'package:angular2/angular2.dart' Directive, View, NgElement, - onChange, - onDestroy, - onInit, - onCheck, - onAllChangesDone; + LifecycleEvent; var _visited = false; void initReflector(reflector) { diff --git a/modules/angular2/test/transform/directive_metadata_extractor/directive_metadata_files/lifecycle.ng_deps.dart b/modules/angular2/test/transform/directive_metadata_extractor/directive_metadata_files/lifecycle.ng_deps.dart index 1c38c2774d..287cee4f9f 100644 --- a/modules/angular2/test/transform/directive_metadata_extractor/directive_metadata_files/lifecycle.ng_deps.dart +++ b/modules/angular2/test/transform/directive_metadata_extractor/directive_metadata_files/lifecycle.ng_deps.dart @@ -8,11 +8,7 @@ import 'package:angular2/angular2.dart' Directive, View, NgElement, - onChange, - onDestroy, - onInit, - onCheck, - onAllChangesDone; + LifecycleEvent; var _visited = false; void initReflector(reflector) { @@ -24,7 +20,8 @@ void initReflector(reflector) { 'parameters': const [const []], 'annotations': const [ const Component( - lifecycle: [onChange, onDestroy, onInit, onCheck, onAllChangesDone]) + lifecycle: [LifecycleEvent.onChange, LifecycleEvent.onDestroy, LifecycleEvent.onInit, + LifecycleEvent.onCheck, LifecycleEvent.onAllChangesDone]) ] }); } diff --git a/modules/angular2_material/src/components/button/button.ts b/modules/angular2_material/src/components/button/button.ts index e86cbe18bd..370b74a3fe 100644 --- a/modules/angular2_material/src/components/button/button.ts +++ b/modules/angular2_material/src/components/button/button.ts @@ -1,4 +1,4 @@ -import {Component, View, onChange} from 'angular2/angular2'; +import {Component, View, LifecycleEvent} from 'angular2/angular2'; import {isPresent} from 'angular2/src/facade/lang'; @@ -13,7 +13,7 @@ export class MdButton { selector: '[md-button][href]', properties: ['disabled'], host: {'(click)': 'onClick($event)', '[tabIndex]': 'tabIndex'}, - lifecycle: [onChange] + lifecycle: [LifecycleEvent.onChange] }) @View({templateUrl: 'angular2_material/src/components/button/button.html'}) export class MdAnchor { diff --git a/modules/angular2_material/src/components/grid_list/grid_list.ts b/modules/angular2_material/src/components/grid_list/grid_list.ts index 6d369f6316..fd1a2bf384 100644 --- a/modules/angular2_material/src/components/grid_list/grid_list.ts +++ b/modules/angular2_material/src/components/grid_list/grid_list.ts @@ -1,4 +1,4 @@ -import {Component, View, Parent, onDestroy, onChange, onAllChangesDone} from 'angular2/angular2'; +import {Component, View, Parent, LifecycleEvent} from 'angular2/angular2'; import {ListWrapper} from 'angular2/src/facade/collection'; import {StringWrapper, isPresent, isString, NumberWrapper} from 'angular2/src/facade/lang'; @@ -14,7 +14,7 @@ import {Math} from 'angular2/src/facade/math'; @Component({ selector: 'md-grid-list', properties: ['cols', 'rowHeight', 'gutterSize'], - lifecycle: [onAllChangesDone] + lifecycle: [LifecycleEvent.onAllChangesDone] }) @View({templateUrl: 'angular2_material/src/components/grid_list/grid_list.html'}) export class MdGridList { @@ -221,7 +221,7 @@ export class MdGridList { '[style.paddingTop]': 'stylePaddingTop', '[attr.role]': '"listitem"' }, - lifecycle: [onDestroy, onChange] + lifecycle: [LifecycleEvent.onDestroy, LifecycleEvent.onChange] }) @View({templateUrl: 'angular2_material/src/components/grid_list/grid_tile.html'}) export class MdGridTile { diff --git a/modules/angular2_material/src/components/input/input.ts b/modules/angular2_material/src/components/input/input.ts index 9e33c8a2a5..638b3eff35 100644 --- a/modules/angular2_material/src/components/input/input.ts +++ b/modules/angular2_material/src/components/input/input.ts @@ -1,4 +1,4 @@ -import {Directive, onAllChangesDone, Attribute, Parent} from 'angular2/angular2'; +import {Directive, LifecycleEvent, Attribute, Parent} from 'angular2/angular2'; import {ObservableWrapper, EventEmitter} from 'angular2/src/facade/async'; @@ -9,7 +9,7 @@ import {ObservableWrapper, EventEmitter} from 'angular2/src/facade/async'; @Directive({ selector: 'md-input-container', - lifecycle: [onAllChangesDone], + lifecycle: [LifecycleEvent.onAllChangesDone], host: {'[class.md-input-has-value]': 'inputHasValue', '[class.md-input-focused]': 'inputHasFocus'} }) diff --git a/modules/angular2_material/src/components/progress-linear/progress_linear.ts b/modules/angular2_material/src/components/progress-linear/progress_linear.ts index 8b75893872..532e52b579 100644 --- a/modules/angular2_material/src/components/progress-linear/progress_linear.ts +++ b/modules/angular2_material/src/components/progress-linear/progress_linear.ts @@ -1,11 +1,11 @@ -import {Component, onChange, View, Attribute} from 'angular2/angular2'; +import {Component, LifecycleEvent, View, Attribute} from 'angular2/angular2'; import {isPresent, isBlank} from 'angular2/src/facade/lang'; import {Math} from 'angular2/src/facade/math'; @Component({ selector: 'md-progress-linear', - lifecycle: [onChange], + lifecycle: [LifecycleEvent.onChange], properties: ['value', 'bufferValue'], host: { '[attr.role]': '"progressbar"', diff --git a/modules/angular2_material/src/components/radio/radio_button.ts b/modules/angular2_material/src/components/radio/radio_button.ts index cc7646269d..d9ebb551c0 100644 --- a/modules/angular2_material/src/components/radio/radio_button.ts +++ b/modules/angular2_material/src/components/radio/radio_button.ts @@ -1,4 +1,12 @@ -import {Component, View, onChange, Parent, Ancestor, Attribute, Optional} from 'angular2/angular2'; +import { + Component, + View, + LifecycleEvent, + Parent, + Ancestor, + Attribute, + Optional +} from 'angular2/angular2'; import {isPresent, StringWrapper, NumberWrapper} from 'angular2/src/facade/lang'; import {ObservableWrapper, EventEmitter} from 'angular2/src/facade/async'; @@ -24,7 +32,7 @@ var _uniqueIdCounter: number = 0; @Component({ selector: 'md-radio-group', - lifecycle: [onChange], + lifecycle: [LifecycleEvent.onChange], events: ['change'], properties: ['disabled', 'value'], host: { @@ -179,7 +187,7 @@ export class MdRadioGroup { @Component({ selector: 'md-radio-button', - lifecycle: [onChange], + lifecycle: [LifecycleEvent.onChange], properties: ['id', 'name', 'value', 'checked', 'disabled'], host: { '(keydown)': 'onKeydown($event)',