Skip to content

Commit 3d38ec8

Browse files
committed
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.
1 parent ef88e0f commit 3d38ec8

File tree

23 files changed

+76
-57
lines changed

23 files changed

+76
-57
lines changed

docs/public-docs-package/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module.exports = new Package('angular-v2-public-docs', [basePackage])
55

66
.config(function(readTypeScriptModules) {
77
readTypeScriptModules.sourceFiles = [
8+
'angular2/lifecycle_hooks.ts',
89
'angular2/metadata.ts',
910
'angular2/change_detection.ts',
1011
'angular2/core.ts',

modules/angular2/angular2.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ export * from './forms';
1515
export * from './render';
1616
export * from './profile';
1717
export {bootstrap} from 'angular2/src/core/application';
18+
export * from './lifecycle_hooks';

modules/angular2/angular2_exports.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ export * from './forms';
77
export * from './render';
88
export * from './profile';
99
export {bootstrap} from 'angular2/src/core/application';
10+
export * from './lifecycle_hooks';
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* @module
3+
* @description
4+
* Defines interfaces to be implemented by directives when they need to hook into the change
5+
* detection mechanism.
6+
*/
7+
8+
export {
9+
AfterContentInit,
10+
AfterContentChecked,
11+
AfterViewInit,
12+
AfterViewChecked,
13+
OnChanges,
14+
OnDestroy,
15+
OnInit,
16+
DoCheck
17+
} from './src/core/compiler/interfaces';

modules/angular2/metadata.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
library angular2.metadata;
22

33
export 'package:angular2/src/core/metadata.dart';
4-
export 'package:angular2/src/core/compiler/interfaces.dart';

modules/angular2/metadata.ts

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
* @description
44
*
55
* Annotations provide the additional information that Angular requires in order to run your
6-
* application. This module
7-
* contains {@link ComponentMetadata}, {@link DirectiveMetadata}, and {@link ViewMetadata}
8-
* annotations, as well as
9-
* the {@link Host} annotation that is used by Angular to resolve dependencies.
6+
* application. This module contains {@link ComponentMetadata}, {@link DirectiveMetadata}, and
7+
* {@link ViewMetadata} annotations, as well as the {@link Host} annotation that is used by Angular
8+
* to resolve dependencies.
109
*
1110
*/
1211

@@ -48,17 +47,5 @@ export {
4847
HostListenerMetadata
4948
} from './src/core/metadata';
5049

51-
export {
52-
// todo(vbe): LifecycleHook should not be exposed (fails test.typings)
53-
LifecycleHook,
54-
AfterContentInit,
55-
AfterContentChecked,
56-
AfterViewInit,
57-
AfterViewChecked,
58-
OnChanges,
59-
OnDestroy,
60-
OnInit,
61-
DoCheck
62-
} from './src/core/compiler/interfaces';
6350

6451
export {Class, ClassDefinition, TypeDecorator} from './src/core/util/decorators';

modules/angular2/src/core/compiler/directive_lifecycle_reflector.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ library angular2.src.core.compiler.directive_lifecycle_reflector;
22

33
import 'package:angular2/src/core/reflection/reflection.dart';
44

5-
bool hasLifecycleHook(/*LifecycleHook*/ interface, type) {
5+
bool hasLifecycleHook(interface, type) {
66
if (type is! Type) return false;
77

88
return reflector.interfaces(type).contains(interface);

modules/angular2/src/core/compiler/directive_lifecycle_reflector.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {Type} from 'angular2/src/core/facade/lang';
22
import * as Interfaces from './interfaces';
33

4-
export function hasLifecycleHook(lcInterface: Interfaces.LifecycleHook, type): boolean {
4+
export function hasLifecycleHook(lcInterface, type): boolean {
55
if (!(type instanceof Type)) return false;
66

77
var proto = (<any>type).prototype;

modules/angular2/src/core/compiler/interfaces.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@ import {StringMap} from 'angular2/src/core/facade/collection';
88
* - `AfterContentInit`,
99
* - `AfterContentChecked`,
1010
* - `OnDestroy` (at the very end before destruction)
11-
*
12-
* // todo(vicb): describe Dart & TS vs JS
1311
*/
14-
export interface LifecycleHook {}
1512

1613
/**
1714
* Notify a directive when any of its bindings have changed.
@@ -41,7 +38,7 @@ export interface LifecycleHook {}
4138
* }
4239
* ```
4340
*/
44-
export class OnChanges implements LifecycleHook {
41+
export class OnChanges {
4542
onChanges(changes: StringMap<string, any>): void {}
4643
}
4744

@@ -63,7 +60,7 @@ export class OnChanges implements LifecycleHook {
6360
* }
6461
* ```
6562
*/
66-
export class OnInit implements LifecycleHook {
63+
export class OnInit {
6764
onInit(): void {}
6865
}
6966

@@ -86,7 +83,7 @@ export class OnInit implements LifecycleHook {
8683
* }
8784
* ```
8885
*/
89-
export class DoCheck implements LifecycleHook {
86+
export class DoCheck {
9087
doCheck(): void {}
9188
}
9289

@@ -104,7 +101,7 @@ export class DoCheck implements LifecycleHook {
104101
* }
105102
* ```
106103
*/
107-
export class OnDestroy implements LifecycleHook {
104+
export class OnDestroy {
108105
onDestroy(): void {}
109106
}
110107

@@ -122,7 +119,7 @@ export class OnDestroy implements LifecycleHook {
122119
* }
123120
* ```
124121
*/
125-
export class AfterContentInit implements LifecycleHook {
122+
export class AfterContentInit {
126123
afterContentInit(): void {}
127124
}
128125

@@ -140,7 +137,7 @@ export class AfterContentInit implements LifecycleHook {
140137
* }
141138
* ```
142139
*/
143-
export class AfterContentChecked implements LifecycleHook {
140+
export class AfterContentChecked {
144141
afterContentChecked(): void {}
145142
}
146143

@@ -158,7 +155,7 @@ export class AfterContentChecked implements LifecycleHook {
158155
* }
159156
* ```
160157
*/
161-
export class AfterViewInit implements LifecycleHook {
158+
export class AfterViewInit {
162159
afterViewInit(): void {}
163160
}
164161

@@ -176,6 +173,6 @@ export class AfterViewInit implements LifecycleHook {
176173
* }
177174
* ```
178175
*/
179-
export class AfterViewChecked implements LifecycleHook {
176+
export class AfterViewChecked {
180177
afterViewChecked(): void {}
181178
}

modules/angular2/src/core/directives/ng_class.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {isPresent, isString, StringWrapper, isBlank} from 'angular2/src/core/facade/lang';
2-
import {Directive, DoCheck, OnDestroy} from 'angular2/metadata';
2+
import {Directive} from 'angular2/metadata';
3+
import {DoCheck, OnDestroy} from 'angular2/lifecycle_hooks';
34
import {ElementRef} from 'angular2/core';
45
import {Renderer} from 'angular2/src/core/render/api';
56
import {

0 commit comments

Comments
 (0)