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
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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(<any>type).prototype;
|
||||
var proto = (<any>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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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,
|
||||
|
||||
|
Reference in New Issue
Block a user