refactor(LifecycleEvent): change from onInit to Lifecycle.onInit

BREAKING CHANGE

Closes #2928
This commit is contained in:
Misko Hevery
2015-07-04 15:04:50 +02:00
committed by Tobias Bosch
parent e1e7912ab2
commit b73ba68215
31 changed files with 245 additions and 250 deletions

View File

@ -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", () {

View File

@ -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() {}
}
}

View File

@ -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 {

View File

@ -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();

View File

@ -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;