X Tutup
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/public-docs-package/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
1 change: 1 addition & 0 deletions modules/angular2/angular2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ export * from './forms';
export * from './render';
export * from './profile';
export {bootstrap} from 'angular2/src/core/application';
export * from './lifecycle_hooks';
1 change: 1 addition & 0 deletions modules/angular2/angular2_exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ export * from './forms';
export * from './render';
export * from './profile';
export {bootstrap} from 'angular2/src/core/application';
export * from './lifecycle_hooks';
17 changes: 17 additions & 0 deletions modules/angular2/lifecycle_hooks.ts
Original file line number Diff line number Diff line change
@@ -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';
1 change: 0 additions & 1 deletion modules/angular2/metadata.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
library angular2.metadata;

export 'package:angular2/src/core/metadata.dart';
export 'package:angular2/src/core/compiler/interfaces.dart';
18 changes: 3 additions & 15 deletions modules/angular2/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,16 @@
* @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.
*
*/

export {
ComponentMetadata,
DirectiveMetadata,
PipeMetadata,
LifecycleEvent,
ViewMetadata,
ViewEncapsulation,
QueryMetadata,
Expand Down Expand Up @@ -49,15 +47,5 @@ export {
HostListenerMetadata
} from './src/core/metadata';

export {
AfterContentInit,
AfterContentChecked,
AfterViewInit,
AfterViewChecked,
OnChanges,
OnDestroy,
OnInit,
DoCheck
} from './src/core/compiler/interfaces';

export {Class, ClassDefinition, TypeDecorator} from './src/core/util/decorators';
Original file line number Diff line number Diff line change
@@ -1,36 +1,9 @@
library angular2.src.core.compiler.directive_lifecycle_reflector;

import 'package:angular2/src/core/metadata.dart';
import 'package:angular2/src/core/compiler/interfaces.dart';
import 'package:angular2/src/core/reflection/reflection.dart';

bool hasLifecycleHook(LifecycleEvent e, type, DirectiveMetadata annotation) {
if (annotation.lifecycle != null) {
return annotation.lifecycle.contains(e);
} else {
if (type is! Type) return false;
bool hasLifecycleHook(interface, type) {
if (type is! Type) return false;

final List interfaces = reflector.interfaces(type);
var interface;

if (e == LifecycleEvent.OnChanges) {
interface = OnChanges;
} else if (e == LifecycleEvent.OnDestroy) {
interface = OnDestroy;
} else if (e == LifecycleEvent.AfterContentInit) {
interface = AfterContentInit;
} else if (e == LifecycleEvent.AfterContentChecked) {
interface = AfterContentChecked;
} else if (e == LifecycleEvent.AfterViewInit) {
interface = AfterViewInit;
} else if (e == LifecycleEvent.AfterViewChecked) {
interface = AfterViewChecked;
} else if (e == LifecycleEvent.DoCheck) {
interface = DoCheck;
} else if (e == LifecycleEvent.OnInit) {
interface = OnInit;
}

return interfaces.contains(interface);
}
return reflector.interfaces(type).contains(interface);
}
54 changes: 26 additions & 28 deletions modules/angular2/src/core/compiler/directive_lifecycle_reflector.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,29 @@
import {Type, isPresent} from 'angular2/src/core/facade/lang';
import {LifecycleEvent, DirectiveMetadata} from 'angular2/metadata';
import {Type} from 'angular2/src/core/facade/lang';
import * as Interfaces from './interfaces';

export function hasLifecycleHook(e: LifecycleEvent, type, annotation: DirectiveMetadata): boolean {
if (isPresent(annotation.lifecycle)) {
return annotation.lifecycle.indexOf(e) !== -1;
} else {
if (!(type instanceof Type)) return false;
var proto = (<any>type).prototype;
switch (e) {
case LifecycleEvent.AfterContentInit:
return !!proto.afterContentInit;
case LifecycleEvent.AfterContentChecked:
return !!proto.afterContentChecked;
case LifecycleEvent.AfterViewInit:
return !!proto.afterViewInit;
case LifecycleEvent.AfterViewChecked:
return !!proto.afterViewChecked;
case LifecycleEvent.OnChanges:
return !!proto.onChanges;
case LifecycleEvent.DoCheck:
return !!proto.doCheck;
case LifecycleEvent.OnDestroy:
return !!proto.onDestroy;
case LifecycleEvent.OnInit:
return !!proto.onInit;
default:
return false;
}
export function hasLifecycleHook(lcInterface, type): boolean {
if (!(type instanceof Type)) return false;

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

switch (lcInterface) {
case Interfaces.AfterContentInit:
return !!proto.afterContentInit;
case Interfaces.AfterContentChecked:
return !!proto.afterContentChecked;
case Interfaces.AfterViewInit:
return !!proto.afterViewInit;
case Interfaces.AfterViewChecked:
return !!proto.afterViewChecked;
case Interfaces.OnChanges:
return !!proto.onChanges;
case Interfaces.DoCheck:
return !!proto.doCheck;
case Interfaces.OnDestroy:
return !!proto.onDestroy;
case Interfaces.OnInit:
return !!proto.onInit;
default:
return false;
}
}
2 changes: 0 additions & 2 deletions modules/angular2/src/core/compiler/directive_resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ export class DirectiveResolver {
properties: mergedProperties,
events: mergedEvents,
host: mergedHost,
lifecycle: dm.lifecycle,
bindings: dm.bindings,
exportAs: dm.exportAs,
compileChildren: dm.compileChildren,
Expand All @@ -106,7 +105,6 @@ export class DirectiveResolver {
properties: mergedProperties,
events: mergedEvents,
host: mergedHost,
lifecycle: dm.lifecycle,
bindings: dm.bindings,
exportAs: dm.exportAs,
compileChildren: dm.compileChildren
Expand Down
20 changes: 11 additions & 9 deletions modules/angular2/src/core/compiler/element_injector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import * as avmModule from './view_manager';
import {ViewContainerRef} from './view_container_ref';
import {ElementRef} from './element_ref';
import {TemplateRef} from './template_ref';
import {DirectiveMetadata, ComponentMetadata, LifecycleEvent} from '../metadata/directives';
import {DirectiveMetadata, ComponentMetadata} from '../metadata/directives';
import {hasLifecycleHook} from './directive_lifecycle_reflector';
import {
ChangeDetector,
Expand All @@ -51,6 +51,8 @@ import {RenderDirectiveMetadata} from 'angular2/src/core/render/api';
import {EventConfig} from 'angular2/src/core/render/event_config';
import {PipeBinding} from '../pipes/pipe_binding';

import * as LifecycleHooks from './interfaces';

var _staticKeys;

export class StaticKeys {
Expand Down Expand Up @@ -160,14 +162,14 @@ export class DirectiveBinding extends ResolvedBinding {
properties: meta.properties,
readAttributes: DirectiveBinding._readAttributes(<any>deps),

callOnDestroy: hasLifecycleHook(LifecycleEvent.OnDestroy, token, meta),
callOnChanges: hasLifecycleHook(LifecycleEvent.OnChanges, token, meta),
callDoCheck: hasLifecycleHook(LifecycleEvent.DoCheck, token, meta),
callOnInit: hasLifecycleHook(LifecycleEvent.OnInit, token, meta),
callAfterContentInit: hasLifecycleHook(LifecycleEvent.AfterContentInit, token, meta),
callAfterContentChecked: hasLifecycleHook(LifecycleEvent.AfterContentChecked, token, meta),
callAfterViewInit: hasLifecycleHook(LifecycleEvent.AfterViewInit, token, meta),
callAfterViewChecked: hasLifecycleHook(LifecycleEvent.AfterViewChecked, token, meta),
callOnDestroy: hasLifecycleHook(LifecycleHooks.OnDestroy, token),
callOnChanges: hasLifecycleHook(LifecycleHooks.OnChanges, token),
callDoCheck: hasLifecycleHook(LifecycleHooks.DoCheck, token),
callOnInit: hasLifecycleHook(LifecycleHooks.OnInit, token),
callAfterContentInit: hasLifecycleHook(LifecycleHooks.AfterContentInit, token),
callAfterContentChecked: hasLifecycleHook(LifecycleHooks.AfterContentChecked, token),
callAfterViewInit: hasLifecycleHook(LifecycleHooks.AfterViewInit, token),
callAfterViewChecked: hasLifecycleHook(LifecycleHooks.AfterViewChecked, token),

changeDetection: meta instanceof ComponentMetadata ? meta.changeDetection : null,

Expand Down
Loading
X Tutup