refactor(Lifecycle hooks): move the hooks to their own module (lifecycle_hooks)

BREAKING CHANGE

Lifecycle hooks now live in the `angular2/lifecycle_hooks` module.
They previously lived in the `metadata` module.
This commit is contained in:
Victor Berchet
2015-09-02 16:43:39 -07:00
parent ef88e0f804
commit 3d38ec8aac
23 changed files with 76 additions and 57 deletions

View File

@ -2,7 +2,7 @@ library angular2.src.core.compiler.directive_lifecycle_reflector;
import 'package:angular2/src/core/reflection/reflection.dart';
bool hasLifecycleHook(/*LifecycleHook*/ interface, type) {
bool hasLifecycleHook(interface, type) {
if (type is! Type) return false;
return reflector.interfaces(type).contains(interface);

View File

@ -1,7 +1,7 @@
import {Type} from 'angular2/src/core/facade/lang';
import * as Interfaces from './interfaces';
export function hasLifecycleHook(lcInterface: Interfaces.LifecycleHook, type): boolean {
export function hasLifecycleHook(lcInterface, type): boolean {
if (!(type instanceof Type)) return false;
var proto = (<any>type).prototype;

View File

@ -8,10 +8,7 @@ import {StringMap} from 'angular2/src/core/facade/collection';
* - `AfterContentInit`,
* - `AfterContentChecked`,
* - `OnDestroy` (at the very end before destruction)
*
* // todo(vicb): describe Dart & TS vs JS
*/
export interface LifecycleHook {}
/**
* Notify a directive when any of its bindings have changed.
@ -41,7 +38,7 @@ export interface LifecycleHook {}
* }
* ```
*/
export class OnChanges implements LifecycleHook {
export class OnChanges {
onChanges(changes: StringMap<string, any>): void {}
}
@ -63,7 +60,7 @@ export class OnChanges implements LifecycleHook {
* }
* ```
*/
export class OnInit implements LifecycleHook {
export class OnInit {
onInit(): void {}
}
@ -86,7 +83,7 @@ export class OnInit implements LifecycleHook {
* }
* ```
*/
export class DoCheck implements LifecycleHook {
export class DoCheck {
doCheck(): void {}
}
@ -104,7 +101,7 @@ export class DoCheck implements LifecycleHook {
* }
* ```
*/
export class OnDestroy implements LifecycleHook {
export class OnDestroy {
onDestroy(): void {}
}
@ -122,7 +119,7 @@ export class OnDestroy implements LifecycleHook {
* }
* ```
*/
export class AfterContentInit implements LifecycleHook {
export class AfterContentInit {
afterContentInit(): void {}
}
@ -140,7 +137,7 @@ export class AfterContentInit implements LifecycleHook {
* }
* ```
*/
export class AfterContentChecked implements LifecycleHook {
export class AfterContentChecked {
afterContentChecked(): void {}
}
@ -158,7 +155,7 @@ export class AfterContentChecked implements LifecycleHook {
* }
* ```
*/
export class AfterViewInit implements LifecycleHook {
export class AfterViewInit {
afterViewInit(): void {}
}
@ -176,6 +173,6 @@ export class AfterViewInit implements LifecycleHook {
* }
* ```
*/
export class AfterViewChecked implements LifecycleHook {
export class AfterViewChecked {
afterViewChecked(): void {}
}

View File

@ -1,5 +1,6 @@
import {isPresent, isString, StringWrapper, isBlank} from 'angular2/src/core/facade/lang';
import {Directive, DoCheck, OnDestroy} from 'angular2/metadata';
import {Directive} from 'angular2/metadata';
import {DoCheck, OnDestroy} from 'angular2/lifecycle_hooks';
import {ElementRef} from 'angular2/core';
import {Renderer} from 'angular2/src/core/render/api';
import {

View File

@ -1,4 +1,5 @@
import {Directive, DoCheck} from 'angular2/metadata';
import {Directive} from 'angular2/metadata';
import {DoCheck} from 'angular2/lifecycle_hooks';
import {ViewContainerRef, ViewRef, TemplateRef} from 'angular2/core';
import {ChangeDetectorRef, IterableDiffer, IterableDiffers} from 'angular2/change_detection';
import {isPresent, isBlank} from 'angular2/src/core/facade/lang';

View File

@ -1,4 +1,5 @@
import {Directive, DoCheck} from 'angular2/metadata';
import {Directive} from 'angular2/metadata';
import {DoCheck} from 'angular2/lifecycle_hooks';
import {ElementRef} from 'angular2/core';
import {KeyValueDiffer, KeyValueDiffers} from 'angular2/change_detection';
import {isPresent, isBlank, print} from 'angular2/src/core/facade/lang';

View File

@ -318,6 +318,10 @@ import {ChangeDetectionStrategy} from 'angular2/change_detection';
* the directive
* controller is correctly instantiated on the `<template>` element rather than the `<li>` element.
*
* ## Lifecycle hooks
*
* When the directive class implements some {@link angular2/lifecycle_hooks} the callbacks are
* called by the change detection at defined points in time during the life of the directive.
*
* ## Example
*
@ -734,6 +738,11 @@ export class DirectiveMetadata extends InjectableMetadata {
*
* For details on the `@View` annotation, see {@link ViewMetadata}.
*
* ## Lifecycle hooks
*
* When the component class implements some {@link angular2/lifecycle_hooks} the callbacks are
* called by the change detection at defined points in time during the life of the component.
*
* ## Example
*
* ```