refactor(LifecycleEvent): change from onInit to Lifecycle.onInit
BREAKING CHANGE Closes #2928
This commit is contained in:
committed by
Tobias Bosch
parent
e1e7912ab2
commit
b73ba68215
@@ -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", () {
|
||||
|
||||
@@ -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() {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
+1
-5
@@ -8,11 +8,7 @@ import 'package:angular2/angular2.dart'
|
||||
Directive,
|
||||
View,
|
||||
NgElement,
|
||||
onChange,
|
||||
onDestroy,
|
||||
onInit,
|
||||
onCheck,
|
||||
onAllChangesDone;
|
||||
LifecycleEvent;
|
||||
|
||||
var _visited = false;
|
||||
void initReflector(reflector) {
|
||||
|
||||
+1
-5
@@ -8,11 +8,7 @@ import 'package:angular2/angular2.dart'
|
||||
Directive,
|
||||
View,
|
||||
NgElement,
|
||||
onChange,
|
||||
onDestroy,
|
||||
onInit,
|
||||
onCheck,
|
||||
onAllChangesDone;
|
||||
LifecycleEvent;
|
||||
|
||||
var _visited = false;
|
||||
void initReflector(reflector) {
|
||||
|
||||
+1
-5
@@ -8,11 +8,7 @@ import 'package:angular2/angular2.dart'
|
||||
Directive,
|
||||
View,
|
||||
NgElement,
|
||||
onChange,
|
||||
onDestroy,
|
||||
onInit,
|
||||
onCheck,
|
||||
onAllChangesDone;
|
||||
LifecycleEvent;
|
||||
|
||||
var _visited = false;
|
||||
void initReflector(reflector) {
|
||||
|
||||
+3
-6
@@ -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])
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user