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

@ -5,6 +5,7 @@ module.exports = new Package('angular-v2-public-docs', [basePackage])
.config(function(readTypeScriptModules) {
readTypeScriptModules.sourceFiles = [
'angular2/lifecycle_hooks.ts',
'angular2/metadata.ts',
'angular2/change_detection.ts',
'angular2/core.ts',

View File

@ -15,3 +15,4 @@ export * from './forms';
export * from './render';
export * from './profile';
export {bootstrap} from 'angular2/src/core/application';
export * from './lifecycle_hooks';

View File

@ -7,3 +7,4 @@ export * from './forms';
export * from './render';
export * from './profile';
export {bootstrap} from 'angular2/src/core/application';
export * from './lifecycle_hooks';

View File

@ -0,0 +1,17 @@
/**
* @module
* @description
* Defines interfaces to be implemented by directives when they need to hook into the change
* detection mechanism.
*/
export {
AfterContentInit,
AfterContentChecked,
AfterViewInit,
AfterViewChecked,
OnChanges,
OnDestroy,
OnInit,
DoCheck
} from './src/core/compiler/interfaces';

View File

@ -1,4 +1,3 @@
library angular2.metadata;
export 'package:angular2/src/core/metadata.dart';
export 'package:angular2/src/core/compiler/interfaces.dart';

View File

@ -3,10 +3,9 @@
* @description
*
* Annotations provide the additional information that Angular requires in order to run your
* application. This module
* contains {@link ComponentMetadata}, {@link DirectiveMetadata}, and {@link ViewMetadata}
* annotations, as well as
* the {@link Host} annotation that is used by Angular to resolve dependencies.
* application. This module contains {@link ComponentMetadata}, {@link DirectiveMetadata}, and
* {@link ViewMetadata} annotations, as well as the {@link Host} annotation that is used by Angular
* to resolve dependencies.
*
*/
@ -48,17 +47,5 @@ export {
HostListenerMetadata
} from './src/core/metadata';
export {
// todo(vbe): LifecycleHook should not be exposed (fails test.typings)
LifecycleHook,
AfterContentInit,
AfterContentChecked,
AfterViewInit,
AfterViewChecked,
OnChanges,
OnDestroy,
OnInit,
DoCheck
} from './src/core/compiler/interfaces';
export {Class, ClassDefinition, TypeDecorator} from './src/core/util/decorators';

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
*
* ```

View File

@ -1,4 +1,5 @@
import {Directive, OnInit, OnDestroy} from 'angular2/metadata';
import {Directive} from 'angular2/metadata';
import {OnInit, OnDestroy} from 'angular2/lifecycle_hooks';
import {Inject, Host, SkipSelf, forwardRef, Binding} from 'angular2/di';
import {ListWrapper} from 'angular2/src/core/facade/collection';
import {CONST_EXPR} from 'angular2/src/core/facade/lang';

View File

@ -2,8 +2,9 @@ import {CONST_EXPR} from 'angular2/src/core/facade/lang';
import {EventEmitter, ObservableWrapper} from 'angular2/src/core/facade/async';
import {StringMap} from 'angular2/src/core/facade/collection';
import {Query, Directive, OnChanges, OnDestroy} from 'angular2/metadata';
import {Query, Directive} from 'angular2/metadata';
import {forwardRef, Host, SkipSelf, Binding, Inject, Optional} from 'angular2/di';
import {OnChanges, OnDestroy} from 'angular2/lifecycle_hooks';
import {ControlContainer} from './control_container';
import {NgControl} from './ng_control';

View File

@ -1,8 +1,9 @@
import {CONST_EXPR} from 'angular2/src/core/facade/lang';
import {EventEmitter, ObservableWrapper} from 'angular2/src/core/facade/async';
import {Query, Directive, OnChanges} from 'angular2/metadata';
import {Query, Directive} from 'angular2/metadata';
import {forwardRef, Binding, Inject, Optional} from 'angular2/di';
import {OnChanges} from 'angular2/lifecycle_hooks';
import {NgControl} from './ng_control';
import {Control} from '../model';

View File

@ -2,7 +2,8 @@ import {CONST_EXPR} from 'angular2/src/core/facade/lang';
import {ListWrapper} from 'angular2/src/core/facade/collection';
import {ObservableWrapper, EventEmitter} from 'angular2/src/core/facade/async';
import {Directive, OnChanges} from 'angular2/metadata';
import {Directive} from 'angular2/metadata';
import {OnChanges} from 'angular2/lifecycle_hooks';
import {forwardRef, Binding} from 'angular2/di';
import {NgControl} from './ng_control';
import {NgControlGroup} from './ng_control_group';

View File

@ -1,8 +1,9 @@
import {CONST_EXPR} from 'angular2/src/core/facade/lang';
import {EventEmitter, ObservableWrapper} from 'angular2/src/core/facade/async';
import {Query, Directive, OnChanges} from 'angular2/metadata';
import {Query, Directive} from 'angular2/metadata';
import {forwardRef, Binding, Inject, Optional} from 'angular2/di';
import {OnChanges} from 'angular2/lifecycle_hooks';
import {NgControl} from './ng_control';
import {Control} from '../model';

View File

@ -20,7 +20,8 @@ import {
import {Injector} from 'angular2/di';
import {NgIf} from 'angular2/directives';
import {Component, View, ViewMetadata, OnDestroy} from 'angular2/metadata';
import {Component, View, ViewMetadata} from 'angular2/metadata';
import {OnDestroy} from 'angular2/lifecycle_hooks';
import {DynamicComponentLoader} from 'angular2/src/core/compiler/dynamic_component_loader';
import {ElementRef} from 'angular2/src/core/compiler/element_ref';
import {DOCUMENT} from 'angular2/src/core/render/render';

View File

@ -35,9 +35,9 @@ import {
Query,
ViewQuery,
ComponentMetadata,
DirectiveMetadata,
OnDestroy
DirectiveMetadata
} from 'angular2/metadata';
import {OnDestroy} from 'angular2/lifecycle_hooks';
import {bind, Injector, Binding, Optional, Inject, Injectable, Self, SkipSelf, InjectMetadata, Host, HostMetadata, SkipSelfMetadata} from 'angular2/di';
import {ViewContainerRef} from 'angular2/src/core/compiler/view_container_ref';
import {TemplateRef} from 'angular2/src/core/compiler/template_ref';

View File

@ -13,11 +13,8 @@ import {
TestComponentBuilder
} from 'angular2/test_lib';
import {Directive, Component, View, ViewMetadata} from 'angular2/metadata';
import {
Directive,
Component,
View,
ViewMetadata,
OnChanges,
OnInit,
DoCheck,
@ -25,7 +22,7 @@ import {
AfterContentChecked,
AfterViewInit,
AfterViewChecked
} from 'angular2/metadata';
} from 'angular2/lifecycle_hooks';
export function main() {
describe('directive lifecycle integration spec', () => {

View File

@ -1,4 +1,5 @@
export * from '../metadata';
export * from '../lifecycle_hooks';
export * from '../change_detection';
export * from '../core';
export * from '../di';
@ -7,6 +8,6 @@ export * from '../forms';
export * from '../render';
export * from '../profile';
export * from '../src/web_workers/worker/application';
export * from "../src/web_workers/shared/client_message_broker";
export * from "../src/web_workers/shared/service_message_broker";
export * from "../src/web_workers/shared/serializer";
export * from '../src/web_workers/shared/client_message_broker';
export * from '../src/web_workers/shared/service_message_broker';
export * from '../src/web_workers/shared/serializer';

View File

@ -11,53 +11,53 @@ export 'class_matcher_base.dart' show ClassDescriptor;
/// covers all libraries which provide them.
const _ON_CHANGE_INTERFACES = const [
const ClassDescriptor('OnChanges', 'package:angular2/angular2.dart'),
const ClassDescriptor('OnChanges', 'package:angular2/metadata.dart'),
const ClassDescriptor('OnChanges', 'package:angular2/lifecycle_hooks.dart'),
const ClassDescriptor(
'OnChanges', 'package:angular2/src/core/compiler/interfaces.dart'),
];
const _ON_DESTROY_INTERFACES = const [
const ClassDescriptor('OnDestroy', 'package:angular2/angular2.dart'),
const ClassDescriptor('OnDestroy', 'package:angular2/metadata.dart'),
const ClassDescriptor('OnDestroy', 'package:angular2/lifecycle_hooks.dart'),
const ClassDescriptor(
'OnDestroy', 'package:angular2/src/core/compiler/interfaces.dart'),
];
const _DO_CHECK_INTERFACES = const [
const ClassDescriptor('DoCheck', 'package:angular2/angular2.dart'),
const ClassDescriptor('DoCheck', 'package:angular2/metadata.dart'),
const ClassDescriptor('DoCheck', 'package:angular2/lifecycle_hooks.dart'),
const ClassDescriptor(
'DoCheck', 'package:angular2/src/core/compiler/interfaces.dart'),
];
const _ON_INIT_INTERFACES = const [
const ClassDescriptor('OnInit', 'package:angular2/angular2.dart'),
const ClassDescriptor('OnInit', 'package:angular2/metadata.dart'),
const ClassDescriptor('OnInit', 'package:angular2/lifecycle_hooks.dart'),
const ClassDescriptor(
'OnInit', 'package:angular2/src/core/compiler/interfaces.dart'),
];
const _ON_AFTER_CONTENT_INIT_INTERFACES = const [
const ClassDescriptor('AfterContentInit', 'package:angular2/angular2.dart'),
const ClassDescriptor(
'AfterContentInit', 'package:angular2/metadata.dart'),
'AfterContentInit', 'package:angular2/lifecycle_hooks.dart'),
const ClassDescriptor(
'AfterContentInit', 'package:angular2/src/core/compiler/interfaces.dart')
];
const _ON_AFTER_CONTENT_CHECKED_INTERFACES = const [
const ClassDescriptor('AfterContentChecked', 'package:angular2/angular2.dart'),
const ClassDescriptor(
'AfterContentChecked', 'package:angular2/metadata.dart'),
'AfterContentChecked', 'package:angular2/lifecycle_hooks.dart'),
const ClassDescriptor(
'AfterContentChecked', 'package:angular2/src/core/compiler/interfaces.dart')
];
const _ON_AFTER_VIEW_INIT_INTERFACES = const [
const ClassDescriptor('AfterViewInit', 'package:angular2/angular2.dart'),
const ClassDescriptor(
'AfterViewInit', 'package:angular2/metadata.dart'),
'AfterViewInit', 'package:angular2/lifecycle_hooks.dart'),
const ClassDescriptor(
'AfterViewInit', 'package:angular2/src/core/compiler/interfaces.dart')
];
const _ON_AFTER_VIEW_CHECKED_INTERFACES = const [
const ClassDescriptor('AfterViewChecked', 'package:angular2/angular2.dart'),
const ClassDescriptor(
'AfterViewChecked', 'package:angular2/metadata.dart'),
'AfterViewChecked', 'package:angular2/lifecycle_hooks.dart'),
const ClassDescriptor(
'AfterViewChecked', 'package:angular2/src/core/compiler/interfaces.dart')
];