chore(LifecycleEvent): change to PascalCase / rename

BREAKING CHANGE

Closes #3863

- LifecycleEvent.onInit => LifecycleEvent.OnInit
- LifecycleEvent.onDestroy => LifecycleEvent.OnDestroy
- LifecycleEvent.onChange => LifecycleEvent.OnChanges
- LifecycleEvent.onCheck => LifecycleEvent.DoCheck
- LifecycleEvent.onAllChangesDone => LifecycleEvent.AfterContentChecked
- OnCheck.onCheck() => DoCheck.doCheck()
- OnChange.onChange() => OnChanges.onChanges()
- OnAllChangesDone.onAllChangesDone() => AfterContentChecked.afterContentChecked

Closes #3851
This commit is contained in:
Misko Hevery 2015-08-27 21:19:56 -07:00
parent ac3f5106e4
commit 551d9a1688
64 changed files with 492 additions and 487 deletions

View File

@ -38,11 +38,11 @@ export {
} from './src/core/metadata';
export {
OnAllChangesDone,
OnChange,
AfterContentChecked,
OnChanges,
OnDestroy,
OnInit,
OnCheck
DoCheck
} from './src/core/compiler/interfaces';
export {Class, ClassDefinition, TypeDecorator} from './src/core/util/decorators';

View File

@ -84,7 +84,7 @@ export class AbstractChangeDetector<T> implements ChangeDetector {
var s = _scope_check(this.id, throwOnChange);
this.detectChangesInRecords(throwOnChange);
this._detectChangesInLightDomChildren(throwOnChange);
if (throwOnChange === false) this.callOnAllChangesDone();
if (throwOnChange === false) this.callAfterContentChecked();
this._detectChangesInShadowDomChildren(throwOnChange);
if (this.mode === ChangeDetectionStrategy.CheckOnce)
this.mode = ChangeDetectionStrategy.Checked;
@ -156,7 +156,7 @@ export class AbstractChangeDetector<T> implements ChangeDetector {
hydrated(): boolean { return this.context !== null; }
callOnAllChangesDone(): void { this.dispatcher.notifyOnAllChangesDone(); }
callAfterContentChecked(): void { this.dispatcher.notifyAfterContentChecked(); }
_detectChangesInLightDomChildren(throwOnChange: boolean): void {
var c = this.lightDomChildren;

View File

@ -39,8 +39,8 @@ export class BindingRecord {
isDirectiveLifecycle(): boolean { return this.mode === DIRECTIVE_LIFECYCLE; }
callOnChange(): boolean {
return isPresent(this.directiveRecord) && this.directiveRecord.callOnChange;
callOnChanges(): boolean {
return isPresent(this.directiveRecord) && this.directiveRecord.callOnChanges;
}
isDefaultChangeDetection(): boolean {
@ -48,16 +48,17 @@ export class BindingRecord {
}
static createDirectiveOnCheck(directiveRecord: DirectiveRecord): BindingRecord {
return new BindingRecord(DIRECTIVE_LIFECYCLE, null, 0, null, null, "onCheck", directiveRecord);
static createDirectiveDoCheck(directiveRecord: DirectiveRecord): BindingRecord {
return new BindingRecord(DIRECTIVE_LIFECYCLE, null, 0, null, null, "DoCheck", directiveRecord);
}
static createDirectiveOnInit(directiveRecord: DirectiveRecord): BindingRecord {
return new BindingRecord(DIRECTIVE_LIFECYCLE, null, 0, null, null, "onInit", directiveRecord);
return new BindingRecord(DIRECTIVE_LIFECYCLE, null, 0, null, null, "OnInit", directiveRecord);
}
static createDirectiveOnChange(directiveRecord: DirectiveRecord): BindingRecord {
return new BindingRecord(DIRECTIVE_LIFECYCLE, null, 0, null, null, "onChange", directiveRecord);
static createDirectiveOnChanges(directiveRecord: DirectiveRecord): BindingRecord {
return new BindingRecord(DIRECTIVE_LIFECYCLE, null, 0, null, null, "OnChanges",
directiveRecord);
}

View File

@ -71,7 +71,7 @@ export class ChangeDetectorJITGenerator {
${this._genCheckNoChanges()}
${this._maybeGenCallOnAllChangesDone()}
${this._maybeGenCallAfterContentChecked()}
${this._maybeGenHydrateDirectives()}
@ -172,23 +172,23 @@ export class ChangeDetectorJITGenerator {
}`;
}
_maybeGenCallOnAllChangesDone(): string {
_maybeGenCallAfterContentChecked(): string {
var notifications = [];
var dirs = this.directiveRecords;
// NOTE(kegluneq): Order is important!
for (var i = dirs.length - 1; i >= 0; --i) {
var dir = dirs[i];
if (dir.callOnAllChangesDone) {
if (dir.callAfterContentChecked) {
notifications.push(
`${this._names.getDirectiveName(dir.directiveIndex)}.onAllChangesDone();`);
`${this._names.getDirectiveName(dir.directiveIndex)}.afterContentChecked();`);
}
}
if (notifications.length > 0) {
var directiveNotifications = notifications.join("\n");
return `
${this._typeName}.prototype.callOnAllChangesDone = function() {
${ABSTRACT_CHANGE_DETECTOR}.prototype.callOnAllChangesDone.call(this);
${this._typeName}.prototype.callAfterContentChecked = function() {
${ABSTRACT_CHANGE_DETECTOR}.prototype.callAfterContentChecked.call(this);
${directiveNotifications}
}
`;
@ -214,11 +214,11 @@ export class ChangeDetectorJITGenerator {
}
_genDirectiveLifecycle(r: ProtoRecord): string {
if (r.name === "onCheck") {
if (r.name === "DoCheck") {
return this._genOnCheck(r);
} else if (r.name === "onInit") {
} else if (r.name === "OnInit") {
return this._genOnInit(r);
} else if (r.name === "onChange") {
} else if (r.name === "OnChanges") {
return this._genOnChange(r);
} else {
throw new BaseException(`Unknown lifecycle event '${r.name}'`);
@ -337,7 +337,7 @@ export class ChangeDetectorJITGenerator {
_genAddToChanges(r: ProtoRecord): string {
var newValue = this._names.getLocalName(r.selfIndex);
var oldValue = this._names.getFieldName(r.selfIndex);
if (!r.bindingRecord.callOnChange()) return "";
if (!r.bindingRecord.callOnChanges()) return "";
return `${CHANGES_LOCAL} = this.addChange(${CHANGES_LOCAL}, ${oldValue}, ${newValue});`;
}
@ -360,7 +360,7 @@ export class ChangeDetectorJITGenerator {
_genOnCheck(r: ProtoRecord): string {
var br = r.bindingRecord;
return `if (!throwOnChange) ${this._names.getDirectiveName(br.directiveRecord.directiveIndex)}.onCheck();`;
return `if (!throwOnChange) ${this._names.getDirectiveName(br.directiveRecord.directiveIndex)}.doCheck();`;
}
_genOnInit(r: ProtoRecord): string {
@ -370,7 +370,7 @@ export class ChangeDetectorJITGenerator {
_genOnChange(r: ProtoRecord): string {
var br = r.bindingRecord;
return `if (!throwOnChange && ${CHANGES_LOCAL}) ${this._names.getDirectiveName(br.directiveRecord.directiveIndex)}.onChange(${CHANGES_LOCAL});`;
return `if (!throwOnChange && ${CHANGES_LOCAL}) ${this._names.getDirectiveName(br.directiveRecord.directiveIndex)}.onChanges(${CHANGES_LOCAL});`;
}
_genNotifyOnPushDetectors(r: ProtoRecord): string {

View File

@ -9,25 +9,25 @@ export class DirectiveIndex {
export class DirectiveRecord {
directiveIndex: DirectiveIndex;
callOnAllChangesDone: boolean;
callOnChange: boolean;
callOnCheck: boolean;
callAfterContentChecked: boolean;
callOnChanges: boolean;
callDoCheck: boolean;
callOnInit: boolean;
changeDetection: ChangeDetectionStrategy;
constructor({directiveIndex, callOnAllChangesDone, callOnChange, callOnCheck, callOnInit,
constructor({directiveIndex, callAfterContentChecked, callOnChanges, callDoCheck, callOnInit,
changeDetection}: {
directiveIndex?: DirectiveIndex,
callOnAllChangesDone?: boolean,
callOnChange?: boolean,
callOnCheck?: boolean,
callAfterContentChecked?: boolean,
callOnChanges?: boolean,
callDoCheck?: boolean,
callOnInit?: boolean,
changeDetection?: ChangeDetectionStrategy
} = {}) {
this.directiveIndex = directiveIndex;
this.callOnAllChangesDone = normalizeBool(callOnAllChangesDone);
this.callOnChange = normalizeBool(callOnChange);
this.callOnCheck = normalizeBool(callOnCheck);
this.callAfterContentChecked = normalizeBool(callAfterContentChecked);
this.callOnChanges = normalizeBool(callOnChanges);
this.callDoCheck = normalizeBool(callDoCheck);
this.callOnInit = normalizeBool(callOnInit);
this.changeDetection = changeDetection;
}

View File

@ -133,12 +133,12 @@ export class DynamicChangeDetector extends AbstractChangeDetector<any> {
}
if (proto.isLifeCycleRecord()) {
if (proto.name === "onCheck" && !throwOnChange) {
this._getDirectiveFor(directiveRecord.directiveIndex).onCheck();
} else if (proto.name === "onInit" && !throwOnChange && !this.alreadyChecked) {
if (proto.name === "DoCheck" && !throwOnChange) {
this._getDirectiveFor(directiveRecord.directiveIndex).doCheck();
} else if (proto.name === "OnInit" && !throwOnChange && !this.alreadyChecked) {
this._getDirectiveFor(directiveRecord.directiveIndex).onInit();
} else if (proto.name === "onChange" && isPresent(changes) && !throwOnChange) {
this._getDirectiveFor(directiveRecord.directiveIndex).onChange(changes);
} else if (proto.name === "OnChanges" && isPresent(changes) && !throwOnChange) {
this._getDirectiveFor(directiveRecord.directiveIndex).onChanges(changes);
}
} else {
@ -168,13 +168,13 @@ export class DynamicChangeDetector extends AbstractChangeDetector<any> {
return isBlank(prev) || prev.bindingRecord !== r.bindingRecord;
}
callOnAllChangesDone() {
super.callOnAllChangesDone();
callAfterContentChecked() {
super.callAfterContentChecked();
var dirs = this.directiveRecords;
for (var i = dirs.length - 1; i >= 0; --i) {
var dir = dirs[i];
if (dir.callOnAllChangesDone) {
this._getDirectiveFor(dir.directiveIndex).onAllChangesDone();
if (dir.callAfterContentChecked) {
this._getDirectiveFor(dir.directiveIndex).afterContentChecked();
}
}
}
@ -193,7 +193,7 @@ export class DynamicChangeDetector extends AbstractChangeDetector<any> {
}
_addChange(bindingRecord: BindingRecord, change, changes) {
if (bindingRecord.callOnChange()) {
if (bindingRecord.callOnChanges()) {
return super.addChange(changes, change.previousValue, change.currentValue);
} else {
return changes;

View File

@ -51,7 +51,7 @@ export interface ChangeDispatcher {
getDebugContext(elementIndex: number, directiveIndex: DirectiveIndex): DebugContext;
notifyOnBinding(bindingTarget: BindingTarget, value: any): void;
logBindingUpdate(bindingTarget: BindingTarget, value: any): void;
notifyOnAllChangesDone(): void;
notifyAfterContentChecked(): void;
}
export interface ChangeDetector {

View File

@ -13,15 +13,15 @@ bool hasLifecycleHook(LifecycleEvent e, type, DirectiveMetadata annotation) {
final List interfaces = reflector.interfaces(type);
var interface;
if (e == LifecycleEvent.onChange) {
interface = OnChange;
} else if (e == LifecycleEvent.onDestroy) {
if (e == LifecycleEvent.OnChanges) {
interface = OnChanges;
} else if (e == LifecycleEvent.OnDestroy) {
interface = OnDestroy;
} else if (e == LifecycleEvent.onAllChangesDone) {
interface = OnAllChangesDone;
} else if (e == LifecycleEvent.onCheck) {
interface = OnCheck;
} else if (e == LifecycleEvent.onInit) {
} else if (e == LifecycleEvent.AfterContentChecked) {
interface = AfterContentChecked;
} else if (e == LifecycleEvent.DoCheck) {
interface = DoCheck;
} else if (e == LifecycleEvent.OnInit) {
interface = OnInit;
}

View File

@ -8,15 +8,15 @@ export function hasLifecycleHook(e: LifecycleEvent, type, annotation: DirectiveM
if (!(type instanceof Type)) return false;
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:
case LifecycleEvent.AfterContentChecked:
return !!proto.afterContentChecked;
case LifecycleEvent.OnChanges:
return !!proto.onChanges;
case LifecycleEvent.DoCheck:
return !!proto.doCheck;
case LifecycleEvent.OnDestroy:
return !!proto.onDestroy;
case LifecycleEvent.onInit:
case LifecycleEvent.OnInit:
return !!proto.onInit;
default:
return false;

View File

@ -204,9 +204,9 @@ export class DirectiveBinding extends ResolvedBinding {
get callOnDestroy(): boolean { return this.metadata.callOnDestroy; }
get callOnChange(): boolean { return this.metadata.callOnChange; }
get callOnChanges(): boolean { return this.metadata.callOnChanges; }
get callOnAllChangesDone(): boolean { return this.metadata.callOnAllChangesDone; }
get callAfterContentChecked(): boolean { return this.metadata.callAfterContentChecked; }
get displayName(): string { return this.key.displayName; }
@ -238,11 +238,12 @@ export class DirectiveBinding extends ResolvedBinding {
properties: ann.properties,
readAttributes: DirectiveBinding._readAttributes(deps),
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),
callOnDestroy: hasLifecycleHook(LifecycleEvent.OnDestroy, rb.key.token, ann),
callOnChanges: hasLifecycleHook(LifecycleEvent.OnChanges, rb.key.token, ann),
callDoCheck: hasLifecycleHook(LifecycleEvent.DoCheck, rb.key.token, ann),
callOnInit: hasLifecycleHook(LifecycleEvent.OnInit, rb.key.token, ann),
callAfterContentChecked:
hasLifecycleHook(LifecycleEvent.AfterContentChecked, rb.key.token, ann),
changeDetection: ann instanceof ComponentMetadata ? ann.changeDetection : null,
@ -431,7 +432,7 @@ export class ElementInjector extends TreeNode<ElementInjector> implements Depend
this._strategy.dehydrate();
}
onAllChangesDone(): void {
afterContentChecked(): void {
if (isPresent(this._query0) && this._query0.originator === this) {
this._query0.list.fireCallbacks();
}

View File

@ -6,32 +6,32 @@ import {global} from 'angular2/src/core/facade/lang';
// https://github.com/systemjs/systemjs/issues/487 gets closed.
var __ignore_me = global;
/**
* Defines lifecycle method {@link annotations/LifeCycleEvent#onChange `LifeCycleEvent.onChange`}
* Defines lifecycle method {@link metadata/LifeCycleEvent#OnChanges `LifeCycleEvent.OnChanges`}
* called after all of component's bound properties are updated.
*/
export interface OnChange { onChange(changes: StringMap<string, any>): void; }
export interface OnChanges { onChanges(changes: StringMap<string, any>): void; }
/**
* Defines lifecycle method {@link annotations/LifeCycleEvent#onDestroy `LifeCycleEvent.onDestroy`}
* called when a directive is being destroyed.
*/
export interface OnDestroy { onDestroy(): void; }
/**
* Defines lifecycle method {@link annotations/LifeCycleEvent#onCheck `LifeCycleEvent.onCheck`}
* called when a directive is being checked.
*/
export interface OnCheck { onCheck(): void; }
/**
* Defines lifecycle method {@link annotations/LifeCycleEvent#onInit `LifeCycleEvent.onInit`}
* Defines lifecycle method {@link metadata/LifeCycleEvent#OnInit `LifeCycleEvent.OnInit`}
* called when a directive is being checked the first time.
*/
export interface OnInit { onInit(): void; }
/**
* Defines lifecycle method
* {@link annotations/LifeCycleEvent#onAllChangesDone `LifeCycleEvent.onAllChangesDone`}
* called when the bindings of all its children have been changed.
* Defines lifecycle method {@link metadata/LifeCycleEvent#DoCheck `LifeCycleEvent.DoCheck`}
* called when a directive is being checked.
*/
export interface OnAllChangesDone { onAllChangesDone(): void; }
export interface DoCheck { doCheck(): boolean; }
/**
* Defines lifecycle method {@link metadata/LifeCycleEvent#OnDestroy `LifeCycleEvent.OnDestroy`}
* called when a directive is being destroyed.
*/
export interface OnDestroy { onDestroy(): void; }
/**
* Defines lifecycle method
* {@link metadata/LifeCycleEvent#AfterContentChecked `LifeCycleEvent.afterContentChecked`}
* called when the bindings of all its view children have been changed.
*/
export interface AfterContentChecked { afterContentChecked(): void; }

View File

@ -150,14 +150,14 @@ export class BindingRecordsCreator {
BindingRecord.createForDirective(astWithSource, propertyName, setter, directiveRecord));
});
if (directiveRecord.callOnChange) {
bindings.push(BindingRecord.createDirectiveOnChange(directiveRecord));
if (directiveRecord.callOnChanges) {
bindings.push(BindingRecord.createDirectiveOnChanges(directiveRecord));
}
if (directiveRecord.callOnInit) {
bindings.push(BindingRecord.createDirectiveOnInit(directiveRecord));
}
if (directiveRecord.callOnCheck) {
bindings.push(BindingRecord.createDirectiveOnCheck(directiveRecord));
if (directiveRecord.callDoCheck) {
bindings.push(BindingRecord.createDirectiveDoCheck(directiveRecord));
}
}
@ -191,9 +191,9 @@ export class BindingRecordsCreator {
this._directiveRecordsMap.set(
id, new DirectiveRecord({
directiveIndex: new DirectiveIndex(boundElementIndex, directiveIndex),
callOnAllChangesDone: directiveMetadata.callOnAllChangesDone,
callOnChange: directiveMetadata.callOnChange,
callOnCheck: directiveMetadata.callOnCheck,
callAfterContentChecked: directiveMetadata.callAfterContentChecked,
callOnChanges: directiveMetadata.callOnChanges,
callDoCheck: directiveMetadata.callDoCheck,
callOnInit: directiveMetadata.callOnInit,
changeDetection: directiveMetadata.changeDetection
}));

View File

@ -204,11 +204,11 @@ export class AppView implements ChangeDispatcher, RenderEventDispatcher {
}
}
notifyOnAllChangesDone(): void {
notifyAfterContentChecked(): void {
var eiCount = this.proto.elementBinders.length;
var ei = this.elementInjectors;
for (var i = eiCount - 1; i >= 0; i--) {
if (isPresent(ei[i + this.elementOffset])) ei[i + this.elementOffset].onAllChangesDone();
if (isPresent(ei[i + this.elementOffset])) ei[i + this.elementOffset].afterContentChecked();
}
}

View File

@ -36,7 +36,7 @@ import {
*/
@Directive({
selector: '[ng-class]',
lifecycle: [LifecycleEvent.onCheck, LifecycleEvent.onDestroy],
lifecycle: [LifecycleEvent.DoCheck, LifecycleEvent.OnDestroy],
properties: ['rawClass: ng-class', 'initialClasses: class']
})
export class NgClass {
@ -76,7 +76,7 @@ export class NgClass {
}
}
onCheck(): void {
doCheck(): void {
if (isPresent(this._differ)) {
var changes = this._differ.diff(this._rawClass);
if (isPresent(changes)) {

View File

@ -34,7 +34,7 @@ import {isPresent, isBlank} from 'angular2/src/core/facade/lang';
* - `<template ng-for #item [ng-for-of]="items" #i="index"><li>...</li></template>`
*/
@Directive(
{selector: '[ng-for][ng-for-of]', properties: ['ngForOf'], lifecycle: [LifecycleEvent.onCheck]})
{selector: '[ng-for][ng-for-of]', properties: ['ngForOf'], lifecycle: [LifecycleEvent.DoCheck]})
export class NgFor {
_ngForOf: any;
private _differ: IterableDiffer;
@ -49,7 +49,7 @@ export class NgFor {
}
}
onCheck() {
doCheck() {
if (isPresent(this._differ)) {
var changes = this._differ.diff(this._ngForOf);
if (isPresent(changes)) this._applyChanges(changes);

View File

@ -27,7 +27,7 @@ import {Renderer} from 'angular2/src/core/render/api';
*/
@Directive({
selector: '[ng-style]',
lifecycle: [LifecycleEvent.onCheck],
lifecycle: [LifecycleEvent.DoCheck],
properties: ['rawStyle: ng-style']
})
export class NgStyle {
@ -44,7 +44,7 @@ export class NgStyle {
}
}
onCheck() {
doCheck() {
if (isPresent(this._differ)) {
var changes = this._differ.diff(this._rawStyle);
if (isPresent(changes)) {

View File

@ -850,12 +850,37 @@ export class ComponentMetadata extends DirectiveMetadata {
/**
* Lifecycle events are guaranteed to be called in the following order:
* - `onChange` (optional if any bindings have changed),
* - `onInit` (optional after the first check only),
* - `onCheck`,
* - `onAllChangesDone`
* - `OnChanges` (if any bindings have changed),
* - `OnInit` (after the first check only),
* - `DoCheck`,
* - `AfterContentChecked`
* - `AfterContentChecked`
* - `OnDestroy` (at the very end before destruction)
*/
export enum LifecycleEvent {
/**
* Notify a directive when it has been checked the first time.
*
* This method is called right after the directive's bindings have been checked,
* and before any of its children's bindings have been checked.
*
* It is invoked only once.
*
* ## Example
*
* ```
* @Directive({
* selector: '[class-set]',
* lifecycle: [LifecycleEvent.OnInit]
* })
* class ClassSet {
* onInit() {
* }
* }
* ```
*/
OnInit,
/**
* Notify a directive whenever a {@link ViewMetadata} that contains it is destroyed.
*
@ -864,7 +889,7 @@ export enum LifecycleEvent {
* ```
* @Directive({
* ...,
* lifecycle: [LifecycleEvent.onDestroy]
* lifecycle: [LifecycleEvent.OnDestroy]
* })
* class ClassSet {
* onDestroy() {
@ -873,7 +898,7 @@ export enum LifecycleEvent {
* }
* ```
*/
onDestroy,
OnDestroy,
/**
@ -893,12 +918,12 @@ export enum LifecycleEvent {
* 'propA',
* 'propB'
* ],
* lifecycle: [LifecycleEvent.onChange]
* lifecycle: [LifecycleEvent.OnChanges]
* })
* class ClassSet {
* propA;
* propB;
* onChange(changes:{[idx: string, PropertyUpdate]}) {
* onChanges(changes:{[idx: string, PropertyUpdate]}) {
* // This will get called after any of the properties have been updated.
* if (changes['propA']) {
* // if propA was updated
@ -910,7 +935,7 @@ export enum LifecycleEvent {
* }
* ```
*/
onChange,
OnChanges,
/**
* Notify a directive when it has been checked.
@ -925,59 +950,36 @@ export enum LifecycleEvent {
* ```
* @Directive({
* selector: '[class-set]',
* lifecycle: [LifecycleEvent.onCheck]
* lifecycle: [LifecycleEvent.DoCheck]
* })
* class ClassSet {
* onCheck() {
* doCheck() {
* }
* }
* ```
*/
onCheck,
DoCheck,
/**
* Notify a directive when it has been checked the first itme.
*
* This method is called right after the directive's bindings have been checked,
* and before any of its children's bindings have been checked.
*
* It is invoked only once.
* Notify a directive when the bindings of all its view children have been checked (whether they
* have changed or not).
*
* ## Example
*
* ```
* @Directive({
* selector: '[class-set]',
* lifecycle: [LifecycleEvent.onInit]
* })
* class ClassSet {
* onInit() {
* }
* }
* ```
*/
onInit,
/**
* Notify a directive when the bindings of all its children have been checked (whether they have
* changed or not).
*
* ## Example
*
* ```
* @Directive({
* selector: '[class-set]',
* lifecycle: [LifecycleEvent.onAllChangesDone]
* lifecycle: [LifecycleEvent.AfterContentChecked]
* })
* class ClassSet {
*
* onAllChangesDone() {
* afterContentChecked() {
* }
*
* }
* ```
*/
onAllChangesDone
AfterContentChecked
}
/**

View File

@ -154,10 +154,10 @@ export class RenderDirectiveMetadata {
readAttributes: List<string>;
type: number;
callOnDestroy: boolean;
callOnChange: boolean;
callOnCheck: boolean;
callOnChanges: boolean;
callDoCheck: boolean;
callOnInit: boolean;
callOnAllChangesDone: boolean;
callAfterContentChecked: boolean;
changeDetection: ChangeDetectionStrategy;
exportAs: string;
hostListeners: Map<string, string>;
@ -168,8 +168,8 @@ export class RenderDirectiveMetadata {
private static _hostRegExp = /^(?:(?:\[([^\]]+)\])|(?:\(([^\)]+)\)))$/g;
constructor({id, selector, compileChildren, events, hostListeners, hostProperties, hostAttributes,
properties, readAttributes, type, callOnDestroy, callOnChange, callOnCheck,
callOnInit, callOnAllChangesDone, changeDetection, exportAs}: {
properties, readAttributes, type, callOnDestroy, callOnChanges, callDoCheck,
callOnInit, callAfterContentChecked, changeDetection, exportAs}: {
id?: string,
selector?: string,
compileChildren?: boolean,
@ -181,10 +181,10 @@ export class RenderDirectiveMetadata {
readAttributes?: List<string>,
type?: number,
callOnDestroy?: boolean,
callOnChange?: boolean,
callOnCheck?: boolean,
callOnChanges?: boolean,
callDoCheck?: boolean,
callOnInit?: boolean,
callOnAllChangesDone?: boolean,
callAfterContentChecked?: boolean,
changeDetection?: ChangeDetectionStrategy,
exportAs?: string
}) {
@ -199,16 +199,16 @@ export class RenderDirectiveMetadata {
this.readAttributes = readAttributes;
this.type = type;
this.callOnDestroy = callOnDestroy;
this.callOnChange = callOnChange;
this.callOnCheck = callOnCheck;
this.callOnChanges = callOnChanges;
this.callDoCheck = callDoCheck;
this.callOnInit = callOnInit;
this.callOnAllChangesDone = callOnAllChangesDone;
this.callAfterContentChecked = callAfterContentChecked;
this.changeDetection = changeDetection;
this.exportAs = exportAs;
}
static create({id, selector, compileChildren, events, host, properties, readAttributes, type,
callOnDestroy, callOnChange, callOnCheck, callOnInit, callOnAllChangesDone,
callOnDestroy, callOnChanges, callDoCheck, callOnInit, callAfterContentChecked,
changeDetection, exportAs}: {
id?: string,
selector?: string,
@ -219,10 +219,10 @@ export class RenderDirectiveMetadata {
readAttributes?: List<string>,
type?: number,
callOnDestroy?: boolean,
callOnChange?: boolean,
callOnCheck?: boolean,
callOnChanges?: boolean,
callDoCheck?: boolean,
callOnInit?: boolean,
callOnAllChangesDone?: boolean,
callAfterContentChecked?: boolean,
changeDetection?: ChangeDetectionStrategy,
exportAs?: string
}): RenderDirectiveMetadata {
@ -255,10 +255,10 @@ export class RenderDirectiveMetadata {
readAttributes: readAttributes,
type: type,
callOnDestroy: callOnDestroy,
callOnChange: callOnChange,
callOnCheck: callOnCheck,
callOnChanges: callOnChanges,
callDoCheck: callDoCheck,
callOnInit: callOnInit,
callOnAllChangesDone: callOnAllChangesDone,
callAfterContentChecked: callAfterContentChecked,
changeDetection: changeDetection,
exportAs: exportAs
});

View File

@ -52,7 +52,7 @@ const controlGroupBinding =
selector: '[ng-control-group]',
bindings: [controlGroupBinding],
properties: ['name: ng-control-group'],
lifecycle: [LifecycleEvent.onInit, LifecycleEvent.onDestroy],
lifecycle: [LifecycleEvent.OnInit, LifecycleEvent.OnDestroy],
exportAs: 'form'
})
export class NgControlGroup extends ControlContainer {

View File

@ -76,7 +76,7 @@ const controlNameBinding =
bindings: [controlNameBinding],
properties: ['name: ngControl', 'model: ngModel'],
events: ['update: ngModel'],
lifecycle: [LifecycleEvent.onDestroy, LifecycleEvent.onChange],
lifecycle: [LifecycleEvent.OnDestroy, LifecycleEvent.OnChanges],
exportAs: 'form'
})
export class NgControlName extends NgControl {
@ -95,7 +95,7 @@ export class NgControlName extends NgControl {
this.ngValidators = ngValidators;
}
onChange(c: StringMap<string, any>) {
onChanges(c: StringMap<string, any>) {
if (!this._added) {
this.formDirective.addControl(this);
this._added = true;

View File

@ -63,7 +63,7 @@ const formControlBinding =
bindings: [formControlBinding],
properties: ['form: ngFormControl', 'model: ngModel'],
events: ['update: ngModel'],
lifecycle: [LifecycleEvent.onChange],
lifecycle: [LifecycleEvent.OnChanges],
exportAs: 'form'
})
export class NgFormControl extends NgControl {
@ -80,7 +80,7 @@ export class NgFormControl extends NgControl {
this.ngValidators = ngValidators;
}
onChange(c: StringMap<string, any>) {
onChanges(c: StringMap<string, any>) {
if (!this._added) {
setUpControl(this.form, this);
this.form.updateValidity();

View File

@ -84,7 +84,7 @@ const formDirectiveBinding =
selector: '[ng-form-model]',
bindings: [formDirectiveBinding],
properties: ['form: ng-form-model'],
lifecycle: [LifecycleEvent.onChange],
lifecycle: [LifecycleEvent.OnChanges],
host: {
'(submit)': 'onSubmit()',
},
@ -96,7 +96,7 @@ export class NgFormModel extends ControlContainer implements Form {
directives: List<NgControl> = [];
ngSubmit = new EventEmitter();
onChange(_) { this._updateDomValue(); }
onChanges(_) { this._updateDomValue(); }
get formDirective(): Form { return this; }

View File

@ -33,7 +33,7 @@ const formControlBinding = CONST_EXPR(new Binding(NgControl, {toAlias: forwardRe
bindings: [formControlBinding],
properties: ['model: ngModel'],
events: ['update: ngModel'],
lifecycle: [LifecycleEvent.onChange],
lifecycle: [LifecycleEvent.OnChanges],
exportAs: 'form'
})
export class NgModel extends NgControl {
@ -50,7 +50,7 @@ export class NgModel extends NgControl {
this.ngValidators = ngValidators;
}
onChange(c: StringMap<string, any>) {
onChanges(c: StringMap<string, any>) {
if (!this._added) {
setUpControl(this._control, this);
this._control.updateValidity();

View File

@ -372,10 +372,10 @@ export class Serializer {
'readAttributes': meta.readAttributes,
'type': meta.type,
'callOnDestroy': meta.callOnDestroy,
'callOnChange': meta.callOnChange,
'callOnCheck': meta.callOnCheck,
'callOnChanges': meta.callOnChanges,
'callDoCheck': meta.callDoCheck,
'callOnInit': meta.callOnInit,
'callOnAllChangesDone': meta.callOnAllChangesDone,
'callAfterContentChecked': meta.callAfterContentChecked,
'changeDetection': meta.changeDetection,
'exportAs': meta.exportAs,
'hostProperties': this.mapToObject(meta.hostProperties),
@ -397,10 +397,10 @@ export class Serializer {
type: obj['type'],
exportAs: obj['exportAs'],
callOnDestroy: obj['callOnDestroy'],
callOnChange: obj['callOnChange'],
callOnCheck: obj['callOnCheck'],
callOnChanges: obj['callOnChanges'],
callDoCheck: obj['callDoCheck'],
callOnInit: obj['callOnInit'],
callOnAllChangesDone: obj['callOnAllChangesDone'],
callAfterContentChecked: obj['callAfterContentChecked'],
changeDetection: obj['changeDetection'],
events: obj['events']
});

View File

@ -282,23 +282,23 @@ class _DirectiveUpdating {
static basicRecords: List<DirectiveRecord> = [
new DirectiveRecord({
directiveIndex: new DirectiveIndex(0, 0),
callOnChange: true,
callOnCheck: true,
callOnAllChangesDone: true
callOnChanges: true,
callDoCheck: true,
callAfterContentChecked: true
}),
new DirectiveRecord({
directiveIndex: new DirectiveIndex(0, 1),
callOnChange: true,
callOnCheck: true,
callOnAllChangesDone: true
callOnChanges: true,
callDoCheck: true,
callAfterContentChecked: true
})
];
static recordNoCallbacks = new DirectiveRecord({
directiveIndex: new DirectiveIndex(0, 0),
callOnChange: false,
callOnCheck: false,
callOnAllChangesDone: false
callOnChanges: false,
callDoCheck: false,
callAfterContentChecked: false
});
/**
@ -315,13 +315,13 @@ class _DirectiveUpdating {
[
_DirectiveUpdating.updateA('1', _DirectiveUpdating.basicRecords[0]),
_DirectiveUpdating.updateB('2', _DirectiveUpdating.basicRecords[0]),
BindingRecord.createDirectiveOnChange(_DirectiveUpdating.basicRecords[0]),
BindingRecord.createDirectiveOnChanges(_DirectiveUpdating.basicRecords[0]),
_DirectiveUpdating.updateA('3', _DirectiveUpdating.basicRecords[1]),
BindingRecord.createDirectiveOnChange(_DirectiveUpdating.basicRecords[1])
BindingRecord.createDirectiveOnChanges(_DirectiveUpdating.basicRecords[1])
],
[_DirectiveUpdating.basicRecords[0], _DirectiveUpdating.basicRecords[1]]),
'directiveOnCheck': new _DirectiveUpdating(
[BindingRecord.createDirectiveOnCheck(_DirectiveUpdating.basicRecords[0])],
'directiveDoCheck': new _DirectiveUpdating(
[BindingRecord.createDirectiveDoCheck(_DirectiveUpdating.basicRecords[0])],
[_DirectiveUpdating.basicRecords[0]]),
'directiveOnInit': new _DirectiveUpdating(
[BindingRecord.createDirectiveOnInit(_DirectiveUpdating.basicRecords[0])],

View File

@ -364,7 +364,7 @@ export function main() {
it('should notify the dispatcher on all changes done', () => {
var val = _createChangeDetector('name', new Person('bob'));
val.changeDetector.detectChanges();
expect(val.dispatcher.onAllChangesDoneCalled).toEqual(true);
expect(val.dispatcher.afterContentCheckedCalled).toEqual(true);
});
describe('updating directives', () => {
@ -385,7 +385,7 @@ export function main() {
expect(directive1.a).toEqual(42);
});
describe('onChange', () => {
describe('onChanges', () => {
it('should notify the directive when a group of records changes', () => {
var cd = _createWithoutHydrate('groupChanges').changeDetector;
cd.hydrate(_DEFAULT_CONTEXT, null, new FakeDirectives([directive1, directive2], []),
@ -396,28 +396,28 @@ export function main() {
});
});
describe('onCheck', () => {
describe('doCheck', () => {
it('should notify the directive when it is checked', () => {
var cd = _createWithoutHydrate('directiveOnCheck').changeDetector;
var cd = _createWithoutHydrate('directiveDoCheck').changeDetector;
cd.hydrate(_DEFAULT_CONTEXT, null, new FakeDirectives([directive1], []), null);
cd.detectChanges();
expect(directive1.onCheckCalled).toBe(true);
directive1.onCheckCalled = false;
expect(directive1.doCheckCalled).toBe(true);
directive1.doCheckCalled = false;
cd.detectChanges();
expect(directive1.onCheckCalled).toBe(true);
expect(directive1.doCheckCalled).toBe(true);
});
it('should not call onCheck in detectNoChanges', () => {
var cd = _createWithoutHydrate('directiveOnCheck').changeDetector;
it('should not call doCheck in detectNoChanges', () => {
var cd = _createWithoutHydrate('directiveDoCheck').changeDetector;
cd.hydrate(_DEFAULT_CONTEXT, null, new FakeDirectives([directive1], []), null);
cd.checkNoChanges();
expect(directive1.onCheckCalled).toBe(false);
expect(directive1.doCheckCalled).toBe(false);
});
});
@ -449,7 +449,7 @@ export function main() {
});
});
describe('onAllChangesDone', () => {
describe('afterContentChecked', () => {
it('should be called after processing all the children', () => {
var cd = _createWithoutHydrate('emptyWithDirectiveRecords').changeDetector;
cd.hydrate(_DEFAULT_CONTEXT, null, new FakeDirectives([directive1, directive2], []),
@ -457,35 +457,35 @@ export function main() {
cd.detectChanges();
expect(directive1.onChangesDoneCalled).toBe(true);
expect(directive2.onChangesDoneCalled).toBe(true);
expect(directive1.afterContentCheckedCalled).toBe(true);
expect(directive2.afterContentCheckedCalled).toBe(true);
// reset directives
directive1.onChangesDoneCalled = false;
directive2.onChangesDoneCalled = false;
directive1.afterContentCheckedCalled = false;
directive2.afterContentCheckedCalled = false;
// Verify that checking should not call them.
cd.checkNoChanges();
expect(directive1.onChangesDoneCalled).toBe(false);
expect(directive2.onChangesDoneCalled).toBe(false);
expect(directive1.afterContentCheckedCalled).toBe(false);
expect(directive2.afterContentCheckedCalled).toBe(false);
// re-verify that changes are still detected
cd.detectChanges();
expect(directive1.onChangesDoneCalled).toBe(true);
expect(directive2.onChangesDoneCalled).toBe(true);
expect(directive1.afterContentCheckedCalled).toBe(true);
expect(directive2.afterContentCheckedCalled).toBe(true);
});
it('should not be called when onAllChangesDone is false', () => {
it('should not be called when afterContentChecked is false', () => {
var cd = _createWithoutHydrate('noCallbacks').changeDetector;
cd.hydrate(_DEFAULT_CONTEXT, null, new FakeDirectives([directive1], []), null);
cd.detectChanges();
expect(directive1.onChangesDoneCalled).toEqual(false);
expect(directive1.afterContentCheckedCalled).toEqual(false);
});
it('should be called in reverse order so the child is always notified before the parent',
@ -1104,17 +1104,17 @@ class TestDirective {
a;
b;
changes;
onChangesDoneCalled;
onChangesDoneSpy;
onCheckCalled;
afterContentCheckedCalled;
afterContentCheckedSpy;
doCheckCalled;
onInitCalled;
event;
constructor(onChangesDoneSpy = null) {
this.onChangesDoneCalled = false;
this.onCheckCalled = false;
this.afterContentCheckedCalled = false;
this.doCheckCalled = false;
this.onInitCalled = false;
this.onChangesDoneSpy = onChangesDoneSpy;
this.afterContentCheckedSpy = onChangesDoneSpy;
this.a = null;
this.b = null;
this.changes = null;
@ -1122,20 +1122,20 @@ class TestDirective {
onEvent(event) { this.event = event; }
onCheck() { this.onCheckCalled = true; }
doCheck() { this.doCheckCalled = true; }
onInit() { this.onInitCalled = true; }
onChange(changes) {
onChanges(changes) {
var r = {};
StringMapWrapper.forEach(changes, (c, key) => r[key] = c.currentValue);
this.changes = r;
}
onAllChangesDone() {
this.onChangesDoneCalled = true;
if (isPresent(this.onChangesDoneSpy)) {
this.onChangesDoneSpy();
afterContentChecked() {
this.afterContentCheckedCalled = true;
if (isPresent(this.afterContentCheckedSpy)) {
this.afterContentCheckedSpy();
}
}
}
@ -1182,7 +1182,7 @@ class TestDispatcher implements ChangeDispatcher {
log: string[];
debugLog: string[];
loggedValues: List<any>;
onAllChangesDoneCalled: boolean = false;
afterContentCheckedCalled: boolean = false;
constructor() { this.clear(); }
@ -1190,7 +1190,7 @@ class TestDispatcher implements ChangeDispatcher {
this.log = [];
this.debugLog = [];
this.loggedValues = [];
this.onAllChangesDoneCalled = true;
this.afterContentCheckedCalled = true;
}
notifyOnBinding(target, value) {
@ -1200,7 +1200,7 @@ class TestDispatcher implements ChangeDispatcher {
logBindingUpdate(target, value) { this.debugLog.push(`${target.name}=${this._asString(value)}`); }
notifyOnAllChangesDone() { this.onAllChangesDoneCalled = true; }
notifyAfterContentChecked() { this.afterContentCheckedCalled = true; }
getDebugContext(a, b) { return null; }

View File

@ -75,8 +75,8 @@ export function main() {
it("should not coalesce directive lifecycle records", () => {
var rs = coalesce([
r("onCheck", [], 0, 1, {mode: RecordType.DirectiveLifecycle}),
r("onCheck", [], 0, 1, {mode: RecordType.DirectiveLifecycle})
r("doCheck", [], 0, 1, {mode: RecordType.DirectiveLifecycle}),
r("doCheck", [], 0, 1, {mode: RecordType.DirectiveLifecycle})
]);
expect(rs.length).toEqual(2);

View File

@ -10,27 +10,27 @@ main() {
metadata(type, annotation) =>
DirectiveBinding.createFromType(type, annotation).metadata;
describe("onChange", () {
it("should be true when the directive implements OnChange", () {
expect(metadata(DirectiveImplementingOnChange, new Directive())
.callOnChange).toBe(true);
describe("onChanges", () {
it("should be true when the directive implements OnChanges", () {
expect(metadata(DirectiveImplementingOnChanges, new Directive())
.callOnChanges).toBe(true);
});
it("should be true when the lifecycle includes onChange", () {
it("should be true when the lifecycle includes onChanges", () {
expect(metadata(DirectiveNoHooks,
new Directive(lifecycle: [LifecycleEvent.onChange]))
.callOnChange).toBe(true);
new Directive(lifecycle: [LifecycleEvent.OnChanges]))
.callOnChanges).toBe(true);
});
it("should be false otherwise", () {
expect(metadata(DirectiveNoHooks, new Directive()).callOnChange)
expect(metadata(DirectiveNoHooks, new Directive()).callOnChanges)
.toBe(false);
});
it("should be false when empty lifecycle", () {
expect(metadata(
DirectiveImplementingOnChange, new Directive(lifecycle: []))
.callOnChange).toBe(false);
DirectiveImplementingOnChanges, new Directive(lifecycle: []))
.callOnChanges).toBe(false);
});
});
@ -42,7 +42,7 @@ main() {
it("should be true when the lifecycle includes onDestroy", () {
expect(metadata(DirectiveNoHooks,
new Directive(lifecycle: [LifecycleEvent.onDestroy]))
new Directive(lifecycle: [LifecycleEvent.OnDestroy]))
.callOnDestroy).toBe(true);
});
@ -52,20 +52,20 @@ main() {
});
});
describe("onCheck", () {
it("should be true when the directive implements OnCheck", () {
describe("doCheck", () {
it("should be true when the directive implements DoCheck", () {
expect(metadata(DirectiveImplementingOnCheck, new Directive())
.callOnCheck).toBe(true);
.callDoCheck).toBe(true);
});
it("should be true when the lifecycle includes onCheck", () {
it("should be true when the lifecycle includes doCheck", () {
expect(metadata(DirectiveNoHooks,
new Directive(lifecycle: [LifecycleEvent.onCheck]))
.callOnCheck).toBe(true);
new Directive(lifecycle: [LifecycleEvent.DoCheck]))
.callDoCheck).toBe(true);
});
it("should be false otherwise", () {
expect(metadata(DirectiveNoHooks, new Directive()).callOnCheck)
expect(metadata(DirectiveNoHooks, new Directive()).callDoCheck)
.toBe(false);
});
});
@ -78,7 +78,7 @@ main() {
it("should be true when the lifecycle includes onInit", () {
expect(metadata(DirectiveNoHooks,
new Directive(lifecycle: [LifecycleEvent.onInit])).callOnInit)
new Directive(lifecycle: [LifecycleEvent.OnInit])).callOnInit)
.toBe(true);
});
@ -88,22 +88,22 @@ main() {
});
});
describe("onAllChangesDone", () {
it("should be true when the directive implements OnAllChangesDone", () {
describe("afterContentChecked", () {
it("should be true when the directive implements AfterContentChecked", () {
expect(
metadata(DirectiveImplementingOnAllChangesDone, new Directive())
.callOnAllChangesDone).toBe(true);
metadata(DirectiveImplementingAfterContentChecked, new Directive())
.callAfterContentChecked).toBe(true);
});
it("should be true when the lifecycle includes onAllChangesDone", () {
it("should be true when the lifecycle includes afterContentChecked", () {
expect(metadata(DirectiveNoHooks,
new Directive(lifecycle: [LifecycleEvent.onAllChangesDone]))
.callOnAllChangesDone).toBe(true);
new Directive(lifecycle: [LifecycleEvent.AfterContentChecked]))
.callAfterContentChecked).toBe(true);
});
it("should be false otherwise", () {
expect(metadata(DirectiveNoHooks, new Directive())
.callOnAllChangesDone).toBe(false);
.callAfterContentChecked).toBe(false);
});
});
});
@ -112,12 +112,12 @@ main() {
class DirectiveNoHooks {}
class DirectiveImplementingOnChange implements OnChange {
onChange(_) {}
class DirectiveImplementingOnChanges implements OnChanges {
onChanges(_) {}
}
class DirectiveImplementingOnCheck implements OnCheck {
onCheck() {}
class DirectiveImplementingOnCheck implements DoCheck {
doCheck() {}
}
class DirectiveImplementingOnInit implements OnInit {
@ -128,6 +128,6 @@ class DirectiveImplementingOnDestroy implements OnDestroy {
onDestroy() {}
}
class DirectiveImplementingOnAllChangesDone implements OnAllChangesDone {
onAllChangesDone() {}
class DirectiveImplementingAfterContentChecked implements AfterContentChecked {
afterContentChecked() {}
}

View File

@ -15,34 +15,35 @@ import {
import {DirectiveMetadata, LifecycleEvent} from 'angular2/src/core/metadata';
import {DirectiveBinding} from 'angular2/src/core/compiler/element_injector';
import {RenderDirectiveMetadata} from 'angular2/src/core/render/api';
export function main() {
describe('Create DirectiveMetadata', () => {
describe('lifecycle', () => {
function metadata(type, annotation) {
function metadata(type, annotation): RenderDirectiveMetadata {
return DirectiveBinding.createFromType(type, annotation).metadata;
}
describe("onChange", () => {
it("should be true when the directive has the onChange method", () => {
expect(metadata(DirectiveWithOnChangeMethod, new DirectiveMetadata({})).callOnChange)
describe("onChanges", () => {
it("should be true when the directive has the onChanges method", () => {
expect(metadata(DirectiveWithOnChangesMethod, new DirectiveMetadata({})).callOnChanges)
.toBe(true);
});
it("should be true when the lifecycle includes onChange", () => {
it("should be true when the lifecycle includes onChanges", () => {
expect(metadata(DirectiveNoHooks,
new DirectiveMetadata({lifecycle: [LifecycleEvent.onChange]}))
.callOnChange)
new DirectiveMetadata({lifecycle: [LifecycleEvent.OnChanges]}))
.callOnChanges)
.toBe(true);
});
it("should be false otherwise", () => {
expect(metadata(DirectiveNoHooks, new DirectiveMetadata()).callOnChange).toBe(false);
expect(metadata(DirectiveNoHooks, new DirectiveMetadata()).callOnChanges).toBe(false);
});
it("should be false when empty lifecycle", () => {
expect(metadata(DirectiveWithOnChangeMethod, new DirectiveMetadata({lifecycle: []}))
.callOnChange)
expect(metadata(DirectiveWithOnChangesMethod, new DirectiveMetadata({lifecycle: []}))
.callOnChanges)
.toBe(false);
});
});
@ -55,7 +56,7 @@ export function main() {
it("should be true when the lifecycle includes onDestroy", () => {
expect(metadata(DirectiveNoHooks,
new DirectiveMetadata({lifecycle: [LifecycleEvent.onDestroy]}))
new DirectiveMetadata({lifecycle: [LifecycleEvent.OnDestroy]}))
.callOnDestroy)
.toBe(true);
});
@ -73,7 +74,7 @@ export function main() {
it("should be true when the lifecycle includes onDestroy", () => {
expect(metadata(DirectiveNoHooks,
new DirectiveMetadata({lifecycle: [LifecycleEvent.onInit]}))
new DirectiveMetadata({lifecycle: [LifecycleEvent.OnInit]}))
.callOnInit)
.toBe(true);
});
@ -83,40 +84,40 @@ export function main() {
});
});
describe("onCheck", () => {
it("should be true when the directive has the onCheck method", () => {
expect(metadata(DirectiveWithOnCheckMethod, new DirectiveMetadata({})).callOnCheck)
describe("doCheck", () => {
it("should be true when the directive has the doCheck method", () => {
expect(metadata(DirectiveWithOnCheckMethod, new DirectiveMetadata({})).callDoCheck)
.toBe(true);
});
it("should be true when the lifecycle includes onCheck", () => {
it("should be true when the lifecycle includes doCheck", () => {
expect(metadata(DirectiveNoHooks,
new DirectiveMetadata({lifecycle: [LifecycleEvent.onCheck]}))
.callOnCheck)
new DirectiveMetadata({lifecycle: [LifecycleEvent.DoCheck]}))
.callDoCheck)
.toBe(true);
});
it("should be false otherwise", () => {
expect(metadata(DirectiveNoHooks, new DirectiveMetadata()).callOnCheck).toBe(false);
expect(metadata(DirectiveNoHooks, new DirectiveMetadata()).callDoCheck).toBe(false);
});
});
describe("onAllChangesDone", () => {
it("should be true when the directive has the onAllChangesDone method", () => {
expect(metadata(DirectiveWithOnAllChangesDoneMethod, new DirectiveMetadata({}))
.callOnAllChangesDone)
describe("afterContentChecked", () => {
it("should be true when the directive has the afterContentChecked method", () => {
expect(metadata(DirectiveWithAfterContentCheckedMethod, new DirectiveMetadata({}))
.callAfterContentChecked)
.toBe(true);
});
it("should be true when the lifecycle includes onAllChangesDone", () => {
it("should be true when the lifecycle includes afterContentChecked", () => {
expect(metadata(DirectiveNoHooks,
new DirectiveMetadata({lifecycle: [LifecycleEvent.onAllChangesDone]}))
.callOnAllChangesDone)
new DirectiveMetadata({lifecycle: [LifecycleEvent.AfterContentChecked]}))
.callAfterContentChecked)
.toBe(true);
});
it("should be false otherwise", () => {
expect(metadata(DirectiveNoHooks, new DirectiveMetadata()).callOnAllChangesDone)
expect(metadata(DirectiveNoHooks, new DirectiveMetadata()).callAfterContentChecked)
.toBe(false);
});
});
@ -126,8 +127,8 @@ export function main() {
class DirectiveNoHooks {}
class DirectiveWithOnChangeMethod {
onChange(_) {}
class DirectiveWithOnChangesMethod {
onChanges(_) {}
}
class DirectiveWithOnInitMethod {
@ -135,13 +136,13 @@ class DirectiveWithOnInitMethod {
}
class DirectiveWithOnCheckMethod {
onCheck() {}
doCheck() {}
}
class DirectiveWithOnDestroyMethod {
onDestroy(_) {}
}
class DirectiveWithOnAllChangesDoneMethod {
onAllChangesDone() {}
class DirectiveWithAfterContentCheckedMethod {
afterContentChecked() {}
}

View File

@ -265,7 +265,7 @@ class DynamicallyCreatedComponentService {}
@Component({
selector: 'hello-cmp',
viewBindings: [DynamicallyCreatedComponentService],
lifecycle: [LifecycleEvent.onDestroy]
lifecycle: [LifecycleEvent.OnDestroy]
})
@View({template: "{{greeting}}"})
class DynamicallyCreatedCmp {

View File

@ -871,7 +871,7 @@ export function main() {
it("should call onDestroy on directives subscribed to this event", () => {
var inj = injector(ListWrapper.concat(
[DirectiveBinding.createFromType(DirectiveWithDestroy,
new DirectiveMetadata({lifecycle: [LifecycleEvent.onDestroy]}))],
new DirectiveMetadata({lifecycle: [LifecycleEvent.OnDestroy]}))],
extraBindings));
var destroy = inj.get(DirectiveWithDestroy);
inj.dehydrate();
@ -893,7 +893,7 @@ export function main() {
query.onChange(() => async.done());
inj.onAllChangesDone();
inj.afterContentChecked();
}));
it("should not notify inherited queries", inject([AsyncTestCompleter], (async) => {
@ -912,10 +912,10 @@ export function main() {
});
query.add(new CountingDirective());
child.onAllChangesDone(); // this does not notify the query
child.afterContentChecked(); // this does not notify the query
query.add(new CountingDirective());
child.parent.onAllChangesDone();
child.parent.afterContentChecked();
}));
});

View File

@ -267,15 +267,15 @@ class NoPropertyAccess {
@Component(
selector: 'on-change',
// TODO: needed because of https://github.com/angular/angular/issues/2120
lifecycle: const [LifecycleEvent.onChange],
lifecycle: const [LifecycleEvent.OnChanges],
properties: const ['prop'])
@View(template: '')
class OnChangeComponent implements OnChange {
class OnChangeComponent implements OnChanges {
Map changes;
String prop;
@override
void onChange(Map changes) {
void onChanges(Map changes) {
this.changes = changes;
}
}
@ -301,11 +301,11 @@ class ComponentWithObservableList {
@Directive(
selector: 'directive-logging-checks',
lifecycle: const [LifecycleEvent.onCheck])
class DirectiveLoggingChecks implements OnCheck {
lifecycle: const [LifecycleEvent.DoCheck])
class DirectiveLoggingChecks implements DoCheck {
Log log;
DirectiveLoggingChecks(this.log);
onCheck() => log.add("check");
doCheck() => log.add("check");
}

View File

@ -489,7 +489,7 @@ class InertDirective {
@Component({selector: 'needs-query'})
@View({
directives: [NgFor, TextDirective],
template: '<div text="ignoreme"></div><div *ng-for="var dir of query">{{dir.text}}|</div>'
template: '<div text="ignoreme"></div><b *ng-for="var dir of query">{{dir.text}}|</b>'
})
@Injectable()
class NeedsQuery {

View File

@ -17,7 +17,7 @@ import {Directive, Component, View, ViewMetadata, LifecycleEvent} from 'angular2
export function main() {
describe('directive lifecycle integration spec', () => {
it('should invoke lifecycle methods onChange > onInit > onCheck > onAllChangesDone',
it('should invoke lifecycle methods onChanges > onInit > doCheck > afterContentChecked',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.overrideView(
MyComp,
@ -28,17 +28,17 @@ export function main() {
var dir = tc.componentViewChildren[0].inject(LifecycleDir);
tc.detectChanges();
expect(dir.log).toEqual(["onChange", "onInit", "onCheck", "onAllChangesDone"]);
expect(dir.log).toEqual(["onChanges", "onInit", "doCheck", "afterContentChecked"]);
tc.detectChanges();
expect(dir.log).toEqual([
"onChange",
"onChanges",
"onInit",
"onCheck",
"onAllChangesDone",
"onCheck",
"onAllChangesDone"
"doCheck",
"afterContentChecked",
"doCheck",
"afterContentChecked"
]);
async.done();
@ -52,10 +52,10 @@ export function main() {
selector: "[lifecycle]",
properties: ['field'],
lifecycle: [
LifecycleEvent.onChange,
LifecycleEvent.onCheck,
LifecycleEvent.onInit,
LifecycleEvent.onAllChangesDone
LifecycleEvent.OnChanges,
LifecycleEvent.DoCheck,
LifecycleEvent.OnInit,
LifecycleEvent.AfterContentChecked
]
})
class LifecycleDir {
@ -64,13 +64,13 @@ class LifecycleDir {
constructor() { this.log = []; }
onChange(_) { this.log.push("onChange"); }
onChanges(_) { this.log.push("onChanges"); }
onInit() { this.log.push("onInit"); }
onCheck() { this.log.push("onCheck"); }
doCheck() { this.log.push("doCheck"); }
onAllChangesDone() { this.log.push("onAllChangesDone"); }
afterContentChecked() { this.log.push("afterContentChecked"); }
}
@Component({selector: 'my-comp'})

View File

@ -117,13 +117,13 @@ export function main() {
});
});
describe("onChange", () => {
describe("onChanges", () => {
it("should update dom values of all the directives", () => {
form.addControl(loginControlDir);
formModel.find(["login"]).updateValue("new value");
form.onChange(null);
form.onChanges(null);
expect((<any>loginControlDir.valueAccessor).writtenValue).toEqual("new value");
});
@ -244,7 +244,7 @@ export function main() {
expect(control.valid).toBe(true);
// this will add the required validator and recalculate the validity
controlDir.onChange({});
controlDir.onChanges({});
expect(control.valid).toBe(false);
});
@ -276,7 +276,7 @@ export function main() {
expect(ngModel.control.valid).toBe(true);
// this will add the required validator and recalculate the validity
ngModel.onChange({});
ngModel.onChanges({});
expect(ngModel.control.valid).toBe(false);
});

View File

@ -68,13 +68,13 @@ export function main() {
expect(c.value).toEqual("newValue");
});
it("should invoke onChange if it is present", () => {
var onChange;
c.registerOnChange((v) => onChange = ["invoked", v]);
it("should invoke onChanges if it is present", () => {
var onChanges;
c.registerOnChange((v) => onChanges = ["invoked", v]);
c.updateValue("newValue");
expect(onChange).toEqual(["invoked", "newValue"]);
expect(onChanges).toEqual(["invoked", "newValue"]);
});
it("should not invoke on change when explicitly specified", () => {

View File

@ -48,7 +48,7 @@ export class MdButton {
@Component({
selector: 'a[md-button], a[md-raised-button], a[md-fab]',
properties: ['disabled'],
lifecycle: [LifecycleEvent.onChange],
lifecycle: [LifecycleEvent.OnChanges],
host: {
'(^click)': 'onClick($event)',
'(^mousedown)': 'onMousedown()',
@ -86,7 +86,7 @@ export class MdAnchor extends MdButton {
}
/** Invoked when a change is detected. */
onChange(_) {
onChanges(_) {
// A disabled anchor should not be in the tab flow.
this.tabIndex = this.disabled ? -1 : 0;
}

View File

@ -28,7 +28,7 @@ class RowHeightMode {
@Component({
selector: 'md-grid-list',
properties: ['cols', 'rowHeight', 'gutterSize'],
lifecycle: [LifecycleEvent.onAllChangesDone]
lifecycle: [LifecycleEvent.AfterContentChecked]
})
@View({
templateUrl: 'package:angular2_material/src/components/grid_list/grid_list.html',
@ -88,7 +88,7 @@ export class MdGridList {
}
}
onAllChangesDone() {
afterContentChecked() {
this.layoutTiles();
}
@ -226,7 +226,7 @@ export class MdGridList {
'[style.marginTop]': 'style.marginTop',
'[style.paddingTop]': 'style.paddingTop',
},
lifecycle: [LifecycleEvent.onDestroy, LifecycleEvent.onChange]
lifecycle: [LifecycleEvent.OnDestroy, LifecycleEvent.OnChanges]
})
@View({
templateUrl: 'package:angular2_material/src/components/grid_list/grid_tile.html',
@ -269,7 +269,7 @@ export class MdGridTile {
* Change handler invoked when bindings are resolved or when bindings have changed.
* Notifies grid-list that a re-layout is required.
*/
onChange(_) {
onChanges(_) {
if (!this.isRegisteredWithGridList) {
this.gridList.addTile(this);
this.isRegisteredWithGridList = true;

View File

@ -9,7 +9,7 @@ import {ObservableWrapper, EventEmitter} from 'angular2/src/core/facade/async';
@Directive({
selector: 'md-input-container',
lifecycle: [LifecycleEvent.onAllChangesDone],
lifecycle: [LifecycleEvent.AfterContentChecked],
host: {
'[class.md-input-has-value]': 'inputHasValue',
'[class.md-input-focused]': 'inputHasFocus',
@ -31,7 +31,7 @@ export class MdInputContainer {
this.inputHasFocus = false;
}
onAllChangesDone() {
afterContentChecked() {
// Enforce that this directive actually contains a text input.
if (this._input == null) {
throw 'No <input> or <textarea> found inside of <md-input-container>';

View File

@ -15,7 +15,7 @@ class ProgressMode {
@Component({
selector: 'md-progress-linear',
lifecycle: [LifecycleEvent.onChange],
lifecycle: [LifecycleEvent.OnChanges],
properties: ['value', 'bufferValue'],
host: {
'role': 'progressbar',
@ -62,7 +62,7 @@ export class MdProgressLinear {
}
}
onChange(_) {
onChanges(_) {
// If the mode does not use a value, or if there is no value, do nothing.
if (this.mode == ProgressMode.QUERY || this.mode == ProgressMode.INDETERMINATE ||
isBlank(this.value)) {

View File

@ -33,7 +33,7 @@ var _uniqueIdCounter: number = 0;
@Component({
selector: 'md-radio-group',
lifecycle: [LifecycleEvent.onChange],
lifecycle: [LifecycleEvent.OnChanges],
events: ['change'],
properties: ['disabled', 'value'],
host: {
@ -103,7 +103,7 @@ export class MdRadioGroup {
}
/** Change handler invoked when bindings are resolved or when bindings have changed. */
onChange(_) {
onChanges(_) {
// If the component has a disabled attribute with no value, it will set disabled = ''.
this.disabled = isPresent(this.disabled) && this.disabled !== false;
@ -191,7 +191,7 @@ export class MdRadioGroup {
@Component({
selector: 'md-radio-button',
lifecycle: [LifecycleEvent.onInit],
lifecycle: [LifecycleEvent.OnInit],
properties: ['id', 'name', 'value', 'checked', 'disabled'],
host: {
'role': 'radio',

View File

@ -388,5 +388,5 @@ class DummyDispatcher implements ChangeDispatcher {
}
notifyOnBinding(bindingTarget, newValue) { throw "Should not be used"; }
logBindingUpdate(bindingTarget, newValue) { throw "Should not be used"; }
notifyOnAllChangesDone() {}
notifyAfterContentChecked() {}
}

View File

@ -24,10 +24,10 @@ Map<String, dynamic> directiveMetadataToMap(RenderDirectiveMetadata meta) {
["type", meta.type],
["exportAs", meta.exportAs],
["callOnDestroy", meta.callOnDestroy],
["callOnCheck", meta.callOnCheck],
["callDoCheck", meta.callDoCheck],
["callOnInit", meta.callOnInit],
["callOnChange", meta.callOnChange],
["callOnAllChangesDone", meta.callOnAllChangesDone],
["callOnChanges", meta.callOnChanges],
["callAfterContentChecked", meta.callAfterContentChecked],
["events", meta.events],
["changeDetection", meta.changeDetection == null ? null : meta.changeDetection.index],
["version", 1]
@ -54,10 +54,10 @@ RenderDirectiveMetadata directiveMetadataFromMap(Map<String, dynamic> map) {
type: (map["type"] as num),
exportAs: (map["exportAs"] as String),
callOnDestroy: (map["callOnDestroy"] as bool),
callOnCheck: (map["callOnCheck"] as bool),
callOnChange: (map["callOnChange"] as bool),
callDoCheck: (map["callDoCheck"] as bool),
callOnChanges: (map["callOnChanges"] as bool),
callOnInit: (map["callOnInit"] as bool),
callOnAllChangesDone: (map["callOnAllChangesDone"] as bool),
callAfterContentChecked: (map["callAfterContentChecked"] as bool),
events: (_cloneIfPresent(map["events"]) as List<String>),
changeDetection: map["changeDetection"] == null ? null
: ChangeDetectionStrategy.values[map["changeDetection"] as int]);

View File

@ -63,7 +63,7 @@ class _DirectiveMetadataVisitor extends Object
bool _callOnChange;
bool _callOnCheck;
bool _callOnInit;
bool _callOnAllChangesDone;
bool _callAfterContentChecked;
ChangeDetectionStrategy _changeDetection;
List<String> _events;
@ -83,7 +83,7 @@ class _DirectiveMetadataVisitor extends Object
_callOnChange = false;
_callOnCheck = false;
_callOnInit = false;
_callOnAllChangesDone = false;
_callAfterContentChecked = false;
_changeDetection = null;
_events = [];
}
@ -97,10 +97,10 @@ class _DirectiveMetadataVisitor extends Object
readAttributes: _readAttributes,
exportAs: _exportAs,
callOnDestroy: _callOnDestroy,
callOnChange: _callOnChange,
callOnCheck: _callOnCheck,
callOnChanges: _callOnChange,
callDoCheck: _callOnCheck,
callOnInit: _callOnInit,
callOnAllChangesDone: _callOnAllChangesDone,
callAfterContentChecked: _callAfterContentChecked,
changeDetection: _changeDetection,
events: _events);
@ -270,11 +270,11 @@ class _DirectiveMetadataVisitor extends Object
}
ListLiteral l = lifecycleValue;
var lifecycleEvents = l.elements.map((s) => s.toSource().split('.').last);
_callOnDestroy = lifecycleEvents.contains("onDestroy");
_callOnChange = lifecycleEvents.contains("onChange");
_callOnCheck = lifecycleEvents.contains("onCheck");
_callOnInit = lifecycleEvents.contains("onInit");
_callOnAllChangesDone = lifecycleEvents.contains("onAllChangesDone");
_callOnDestroy = lifecycleEvents.contains("OnDestroy");
_callOnChange = lifecycleEvents.contains("OnChanges");
_callOnCheck = lifecycleEvents.contains("DoCheck");
_callOnInit = lifecycleEvents.contains("OnInit");
_callAfterContentChecked = lifecycleEvents.contains("AfterContentChecked");
}
void _populateEvents(Expression eventsValue) {

View File

@ -10,10 +10,10 @@ export 'class_matcher_base.dart' show ClassDescriptor;
/// implemented by a class. These classes are re-exported in many places so this
/// covers all libraries which provide them.
const _ON_CHANGE_INTERFACES = const [
const ClassDescriptor('OnChange', 'package:angular2/angular2.dart'),
const ClassDescriptor('OnChange', 'package:angular2/metadata.dart'),
const ClassDescriptor('OnChanges', 'package:angular2/angular2.dart'),
const ClassDescriptor('OnChanges', 'package:angular2/metadata.dart'),
const ClassDescriptor(
'OnChange', 'package:angular2/src/core/compiler/interfaces.dart'),
'OnChanges', 'package:angular2/src/core/compiler/interfaces.dart'),
];
const _ON_DESTROY_INTERFACES = const [
const ClassDescriptor('OnDestroy', 'package:angular2/angular2.dart'),
@ -22,10 +22,10 @@ const _ON_DESTROY_INTERFACES = const [
'OnDestroy', 'package:angular2/src/core/compiler/interfaces.dart'),
];
const _ON_CHECK_INTERFACES = const [
const ClassDescriptor('OnCheck', 'package:angular2/angular2.dart'),
const ClassDescriptor('OnCheck', 'package:angular2/metadata.dart'),
const ClassDescriptor('DoCheck', 'package:angular2/angular2.dart'),
const ClassDescriptor('DoCheck', 'package:angular2/metadata.dart'),
const ClassDescriptor(
'OnCheck', 'package:angular2/src/core/compiler/interfaces.dart'),
'DoCheck', 'package:angular2/src/core/compiler/interfaces.dart'),
];
const _ON_INIT_INTERFACES = const [
const ClassDescriptor('OnInit', 'package:angular2/angular2.dart'),
@ -34,11 +34,11 @@ const _ON_INIT_INTERFACES = const [
'OnInit', 'package:angular2/src/core/compiler/interfaces.dart'),
];
const _ON_ALL_CHANGES_DONE_INTERFACES = const [
const ClassDescriptor('OnAllChangesDone', 'package:angular2/angular2.dart'),
const ClassDescriptor('AfterContentChecked', 'package:angular2/angular2.dart'),
const ClassDescriptor(
'OnAllChangesDone', 'package:angular2/metadata.dart'),
'AfterContentChecked', 'package:angular2/metadata.dart'),
const ClassDescriptor(
'OnAllChangesDone', 'package:angular2/src/core/compiler/interfaces.dart')
'AfterContentChecked', 'package:angular2/src/core/compiler/interfaces.dart')
];
/// Checks if a given [Annotation] matches any of the given
@ -55,7 +55,7 @@ class InterfaceMatcher extends ClassMatcherBase {
..addAll(_ON_ALL_CHANGES_DONE_INTERFACES));
}
/// Checks if an [Identifier] implements [OnChange].
/// Checks if an [Identifier] implements [OnChanges].
bool isOnChange(Identifier typeName, AssetId assetId) =>
implements(firstMatch(typeName, assetId), _ON_CHANGE_INTERFACES);
@ -63,7 +63,7 @@ class InterfaceMatcher extends ClassMatcherBase {
bool isOnDestroy(Identifier typeName, AssetId assetId) =>
implements(firstMatch(typeName, assetId), _ON_DESTROY_INTERFACES);
/// Checks if an [Identifier] implements [OnCheck].
/// Checks if an [Identifier] implements [DoCheck].
bool isOnCheck(Identifier typeName, AssetId assetId) =>
implements(firstMatch(typeName, assetId), _ON_CHECK_INTERFACES);
@ -71,7 +71,7 @@ class InterfaceMatcher extends ClassMatcherBase {
bool isOnInit(Identifier typeName, AssetId assetId) =>
implements(firstMatch(typeName, assetId), _ON_INIT_INTERFACES);
/// Checks if an [Identifier] implements [OnAllChangesDone].
bool isOnAllChangesDone(Identifier typeName, AssetId assetId) => implements(
/// Checks if an [Identifier] implements [AfterContentChecked].
bool isAfterContentChecked(Identifier typeName, AssetId assetId) => implements(
firstMatch(typeName, assetId), _ON_ALL_CHANGES_DONE_INTERFACES);
}

View File

@ -279,7 +279,7 @@ class _NgDepsDeclarationsVisitor extends Object with SimpleAstVisitor<Object> {
final AnnotationMatcher _annotationMatcher;
/// Responsible for testing whether interfaces are recognized by Angular2,
/// for example `OnChange`.
/// for example `OnChanges`.
final InterfaceMatcher _interfaceMatcher;
/// Used to fetch linked files.

View File

@ -256,23 +256,23 @@ class AnnotationsTransformVisitor extends ToSourceVisitor {
namesToTest.forEach((name) {
if (_interfaceMatcher.isOnChange(name, _assetId)) {
_ifaceLifecycleEntries.add('${LifecycleEvent.onChange}');
_ifaceLifecycleEntries.add('${LifecycleEvent.OnChanges}');
populateImport(name);
}
if (_interfaceMatcher.isOnDestroy(name, _assetId)) {
_ifaceLifecycleEntries.add('${LifecycleEvent.onDestroy}');
_ifaceLifecycleEntries.add('${LifecycleEvent.OnDestroy}');
populateImport(name);
}
if (_interfaceMatcher.isOnCheck(name, _assetId)) {
_ifaceLifecycleEntries.add('${LifecycleEvent.onCheck}');
_ifaceLifecycleEntries.add('${LifecycleEvent.DoCheck}');
populateImport(name);
}
if (_interfaceMatcher.isOnInit(name, _assetId)) {
_ifaceLifecycleEntries.add('${LifecycleEvent.onInit}');
_ifaceLifecycleEntries.add('${LifecycleEvent.OnInit}');
populateImport(name);
}
if (_interfaceMatcher.isOnAllChangesDone(name, _assetId)) {
_ifaceLifecycleEntries.add('${LifecycleEvent.onAllChangesDone}');
if (_interfaceMatcher.isAfterContentChecked(name, _assetId)) {
_ifaceLifecycleEntries.add('${LifecycleEvent.AfterContentChecked}');
populateImport(name);
}
});

View File

@ -151,7 +151,7 @@ class _CodegenState {
${_genCheckNoChanges()}
${_maybeGenCallOnAllChangesDone()}
${_maybeGenCallAfterContentChecked()}
${_maybeGenHydrateDirectives()}
@ -260,19 +260,19 @@ class _CodegenState {
'{ $hydrateDirectivesCode $hydrateDetectorsCode }';
}
/// Generates calls to `onAllChangesDone` for all `Directive`s that request
/// Generates calls to `afterContentChecked` for all `Directive`s that request
/// them.
String _maybeGenCallOnAllChangesDone() {
String _maybeGenCallAfterContentChecked() {
// NOTE(kegluneq): Order is important!
var directiveNotifications = _directiveRecords.reversed
.where((rec) => rec.callOnAllChangesDone)
.where((rec) => rec.callAfterContentChecked)
.map((rec) =>
'${_names.getDirectiveName(rec.directiveIndex)}.onAllChangesDone();');
'${_names.getDirectiveName(rec.directiveIndex)}.afterContentChecked();');
if (directiveNotifications.isNotEmpty) {
return '''
void callOnAllChangesDone() {
${_names.getDispatcherName()}.notifyOnAllChangesDone();
void callAfterContentChecked() {
${_names.getDispatcherName()}.notifyAfterContentChecked();
${directiveNotifications.join('')}
}
''';
@ -309,12 +309,12 @@ class _CodegenState {
}
String _genDirectiveLifecycle(ProtoRecord r) {
if (r.name == 'onCheck') {
return _genOnCheck(r);
} else if (r.name == 'onInit') {
if (r.name == 'DoCheck') {
return _genDoCheck(r);
} else if (r.name == 'OnInit') {
return _genOnInit(r);
} else if (r.name == 'onChange') {
return _genOnChange(r);
} else if (r.name == 'OnChanges') {
return _genOnChanges(r);
} else {
throw new BaseException("Unknown lifecycle event '${r.name}'");
}
@ -444,7 +444,7 @@ class _CodegenState {
String _genAddToChanges(ProtoRecord r) {
var newValue = _names.getLocalName(r.selfIndex);
var oldValue = _names.getFieldName(r.selfIndex);
if (!r.bindingRecord.callOnChange()) return '';
if (!r.bindingRecord.callOnChanges()) return '';
return "$_CHANGES_LOCAL = addChange($_CHANGES_LOCAL, $oldValue, $newValue);";
}
@ -457,10 +457,10 @@ class _CodegenState {
''';
}
String _genOnCheck(ProtoRecord r) {
String _genDoCheck(ProtoRecord r) {
var br = r.bindingRecord;
return 'if (!throwOnChange) '
'${_names.getDirectiveName(br.directiveRecord.directiveIndex)}.onCheck();';
'${_names.getDirectiveName(br.directiveRecord.directiveIndex)}.doCheck();';
}
String _genOnInit(ProtoRecord r) {
@ -469,11 +469,11 @@ class _CodegenState {
'${_names.getDirectiveName(br.directiveRecord.directiveIndex)}.onInit();';
}
String _genOnChange(ProtoRecord r) {
String _genOnChanges(ProtoRecord r) {
var br = r.bindingRecord;
return 'if (!throwOnChange && $_CHANGES_LOCAL != null) '
'${_names.getDirectiveName(br.directiveRecord.directiveIndex)}'
'.onChange($_CHANGES_LOCAL);';
'.onChanges($_CHANGES_LOCAL);';
}
String _genNotifyOnPushDetectors(ProtoRecord r) {

View File

@ -23,10 +23,10 @@ main() {
type: RenderDirectiveMetadata.COMPONENT_TYPE,
exportAs: "aaa",
callOnDestroy: true,
callOnChange: true,
callOnCheck: true,
callOnChanges: true,
callDoCheck: true,
callOnInit: true,
callOnAllChangesDone: true,
callAfterContentChecked: true,
events: ["onFoo", "onBar"],
changeDetection: ChangeDetectionStrategy.CheckOnce);
var map = directiveMetadataToMap(someComponent);
@ -43,10 +43,10 @@ main() {
expect(map["selector"]).toEqual("some-comp");
expect(map["type"]).toEqual(RenderDirectiveMetadata.COMPONENT_TYPE);
expect(map["callOnDestroy"]).toEqual(true);
expect(map["callOnCheck"]).toEqual(true);
expect(map["callOnChange"]).toEqual(true);
expect(map["callDoCheck"]).toEqual(true);
expect(map["callOnChanges"]).toEqual(true);
expect(map["callOnInit"]).toEqual(true);
expect(map["callOnAllChangesDone"]).toEqual(true);
expect(map["callAfterContentChecked"]).toEqual(true);
expect(map["exportAs"]).toEqual("aaa");
expect(map["events"]).toEqual(["onFoo", "onBar"]);
expect(map["changeDetection"]).toEqual(ChangeDetectionStrategy.CheckOnce.index);
@ -64,10 +64,10 @@ main() {
["type", RenderDirectiveMetadata.DIRECTIVE_TYPE],
["exportAs", "aaa"],
["callOnDestroy", true],
["callOnCheck", true],
["callDoCheck", true],
["callOnInit", true],
["callOnChange", true],
["callOnAllChangesDone", true],
["callOnChanges", true],
["callAfterContentChecked", true],
["events", ["onFoo", "onBar"]],
["changeDetection", ChangeDetectionStrategy.CheckOnce.index]
]);
@ -86,10 +86,10 @@ main() {
expect(meta.type).toEqual(RenderDirectiveMetadata.DIRECTIVE_TYPE);
expect(meta.exportAs).toEqual("aaa");
expect(meta.callOnDestroy).toEqual(true);
expect(meta.callOnCheck).toEqual(true);
expect(meta.callDoCheck).toEqual(true);
expect(meta.callOnInit).toEqual(true);
expect(meta.callOnChange).toEqual(true);
expect(meta.callOnAllChangesDone).toEqual(true);
expect(meta.callOnChanges).toEqual(true);
expect(meta.callAfterContentChecked).toEqual(true);
expect(meta.events).toEqual(["onFoo", "onBar"]);
expect(meta.changeDetection).toEqual(ChangeDetectionStrategy.CheckOnce);
});

View File

@ -103,10 +103,10 @@ void allTests() {
var metadata = await readMetadata('directive_metadata_extractor/'
'directive_metadata_files/lifecycle.ng_deps.dart');
expect(metadata.callOnDestroy).toBe(true);
expect(metadata.callOnChange).toBe(true);
expect(metadata.callOnCheck).toBe(true);
expect(metadata.callOnChanges).toBe(true);
expect(metadata.callDoCheck).toBe(true);
expect(metadata.callOnInit).toBe(true);
expect(metadata.callOnAllChangesDone).toBe(true);
expect(metadata.callAfterContentChecked).toBe(true);
});
it('should parse events.', () async {

View File

@ -13,11 +13,11 @@ void initReflector(reflector) {
HelloCmp,
new ReflectionInfo(const [
const Component(lifecycle: [
LifecycleEvent.onChange,
LifecycleEvent.onDestroy,
LifecycleEvent.onInit,
LifecycleEvent.onCheck,
LifecycleEvent.onAllChangesDone
LifecycleEvent.OnChanges,
LifecycleEvent.OnDestroy,
LifecycleEvent.OnInit,
LifecycleEvent.DoCheck,
LifecycleEvent.AfterContentChecked
])
], const [
const []

View File

@ -16,18 +16,18 @@ void initReflector() {
const [
const Component(
selector: '[soup]',
lifecycle: const [LifecycleEvent.onChange])
lifecycle: const [LifecycleEvent.OnChanges])
],
const [],
() => new OnChangeSoupComponent(),
const [OnChange]))
const [OnChanges]))
..registerType(
OnDestroySoupComponent,
new _ngRef.ReflectionInfo(
const [
const Component(
selector: '[soup]',
lifecycle: const [LifecycleEvent.onDestroy])
lifecycle: const [LifecycleEvent.OnDestroy])
],
const [],
() => new OnDestroySoupComponent(),
@ -37,30 +37,30 @@ void initReflector() {
new _ngRef.ReflectionInfo(
const [
const Component(
selector: '[soup]', lifecycle: const [LifecycleEvent.onCheck])
selector: '[soup]', lifecycle: const [LifecycleEvent.DoCheck])
],
const [],
() => new OnCheckSoupComponent(),
const [OnCheck]))
const [DoCheck]))
..registerType(
OnInitSoupComponent,
new _ngRef.ReflectionInfo(
const [
const Component(
selector: '[soup]', lifecycle: const [LifecycleEvent.onInit])
selector: '[soup]', lifecycle: const [LifecycleEvent.OnInit])
],
const [],
() => new OnInitSoupComponent(),
const [OnInit]))
..registerType(
OnAllChangesDoneSoupComponent,
AfterContentCheckedSoupComponent,
new _ngRef.ReflectionInfo(
const [
const Component(
selector: '[soup]',
lifecycle: const [LifecycleEvent.onAllChangesDone])
lifecycle: const [LifecycleEvent.AfterContentChecked])
],
const [],
() => new OnAllChangesDoneSoupComponent(),
const [OnAllChangesDone]));
() => new AfterContentCheckedSoupComponent(),
const [AfterContentChecked]));
}

View File

@ -3,16 +3,16 @@ library dinner.soup;
import 'package:angular2/metadata.dart';
@Component(selector: '[soup]')
class OnChangeSoupComponent implements OnChange {}
class OnChangeSoupComponent implements OnChanges {}
@Component(selector: '[soup]')
class OnDestroySoupComponent implements OnDestroy {}
@Component(selector: '[soup]')
class OnCheckSoupComponent implements OnCheck {}
class OnCheckSoupComponent implements DoCheck {}
@Component(selector: '[soup]')
class OnInitSoupComponent implements OnInit {}
@Component(selector: '[soup]')
class OnAllChangesDoneSoupComponent implements OnAllChangesDone {}
class AfterContentCheckedSoupComponent implements AfterContentChecked {}

View File

@ -16,5 +16,5 @@ void initReflector() {
const [const Component(selector: '[soup]')],
const [],
() => new ChangingSoupComponent(),
const [OnChange, AnotherInterface]));
const [OnChanges, AnotherInterface]));
}

View File

@ -3,4 +3,4 @@ library dinner.soup;
import 'package:angular2/src/core/metadata.dart';
@Component(selector: '[soup]')
class ChangingSoupComponent implements OnChange, AnotherInterface {}
class ChangingSoupComponent implements OnChanges, AnotherInterface {}

View File

@ -17,14 +17,14 @@ void initReflector() {
const Component(
selector: '[soup]',
lifecycle: const [
LifecycleEvent.onChange,
LifecycleEvent.onDestroy,
LifecycleEvent.onInit
LifecycleEvent.OnChanges,
LifecycleEvent.OnDestroy,
LifecycleEvent.OnInit
])
],
const [],
() => new MultiSoupComponent(),
const [OnChange, OnDestroy, OnInit]))
const [OnChanges, OnDestroy, OnInit]))
..registerType(
MixedSoupComponent,
new _ngRef.ReflectionInfo(
@ -32,22 +32,22 @@ void initReflector() {
const Component(
selector: '[soup]',
lifecycle: const [
LifecycleEvent.onChange,
LifecycleEvent.onCheck
LifecycleEvent.DoCheck,
LifecycleEvent.OnChanges
])
],
const [],
() => new MixedSoupComponent(),
const [OnChange]))
const [OnChanges]))
..registerType(
MatchedSoupComponent,
new _ngRef.ReflectionInfo(
const [
const Component(
selector: '[soup]',
lifecycle: const [LifecycleEvent.onChange])
lifecycle: const [LifecycleEvent.OnChanges])
],
const [],
() => new MatchedSoupComponent(),
const [OnChange]));
const [OnChanges]));
}

View File

@ -3,10 +3,10 @@ library dinner.soup;
import 'package:angular2/metadata.dart';
@Component(selector: '[soup]')
class MultiSoupComponent implements OnChange, OnDestroy, OnInit {}
class MultiSoupComponent implements OnChanges, OnDestroy, OnInit {}
@Component(selector: '[soup]', lifecycle: const [LifecycleEvent.onCheck])
class MixedSoupComponent implements OnChange {}
@Component(selector: '[soup]', lifecycle: const [LifecycleEvent.DoCheck])
class MixedSoupComponent implements OnChanges {}
@Component(selector: '[soup]', lifecycle: const [LifecycleEvent.onChange])
class MatchedSoupComponent implements OnChange {}
@Component(selector: '[soup]', lifecycle: const [LifecycleEvent.OnChanges])
class MatchedSoupComponent implements OnChanges {}

View File

@ -16,9 +16,9 @@ void initReflector() {
const [
const prefix.Component(
selector: '[soup]',
lifecycle: const [prefix.LifecycleEvent.onChange])
lifecycle: const [prefix.LifecycleEvent.OnChanges])
],
const [],
() => new OnChangeSoupComponent(),
const [prefix.OnChange]));
const [prefix.OnChanges]));
}

View File

@ -3,4 +3,4 @@ library dinner.soup;
import 'package:angular2/metadata.dart' as prefix;
@prefix.Component(selector: '[soup]')
class OnChangeSoupComponent implements prefix.OnChange {}
class OnChangeSoupComponent implements prefix.OnChanges {}

View File

@ -14,6 +14,6 @@ void initReflector() {
OnChangeSoupComponent,
new _ngRef.ReflectionInfo(const [
const Component(
selector: '[soup]', lifecycle: const [LifecycleEvent.onChange])
selector: '[soup]', lifecycle: const [LifecycleEvent.OnChanges])
], const [], () => new OnChangeSoupComponent()));
}

View File

@ -3,4 +3,4 @@ library dinner.soup;
import 'package:angular2/metadata.dart';
@Component(selector: '[soup]')
class OnChangeSoupComponent extends OnChange {}
class OnChangeSoupComponent extends OnChanges {}

View File

@ -13,10 +13,10 @@
"type": 1,
"exportAs": null,
"callOnDestroy": false,
"callOnCheck": false,
"callDoCheck": false,
"callOnInit": false,
"callOnChange": false,
"callOnAllChangesDone": false,
"callOnChanges": false,
"callAfterContentChecked": false,
"events": [],
"changeDetection": null,
"version": 1

View File

@ -13,10 +13,10 @@
"type": null,
"exportAs": null,
"callOnDestroy": null,
"callOnCheck": null,
"callDoCheck": null,
"callOnInit": null,
"callOnChange": null,
"callOnAllChangesDone": null,
"callOnChanges": null,
"callAfterContentChecked": null,
"events": ["dependencyEventName"],
"changeDetection": null,
"version": 1
@ -36,10 +36,10 @@
"type": null,
"exportAs": null,
"callOnDestroy": null,
"callOnCheck": null,
"callDoCheck": null,
"callOnInit": null,
"callOnChange": null,
"callOnAllChangesDone": null,
"callOnChanges": null,
"callAfterContentChecked": null,
"events": null,
"changeDetection": null,
"version": 1
@ -59,10 +59,10 @@
"type": null,
"exportAs": null,
"callOnDestroy": null,
"callOnCheck": null,
"callDoCheck": null,
"callOnInit": null,
"callOnChange": null,
"callOnAllChangesDone": null,
"callOnChanges": null,
"callAfterContentChecked": null,
"events": null,
"changeDetection": null,
"version": 1
@ -82,10 +82,10 @@
"type": null,
"exportAs": null,
"callOnDestroy": null,
"callOnCheck": true,
"callDoCheck": true,
"callOnInit": null,
"callOnChange": null,
"callOnAllChangesDone": null,
"callOnChanges": null,
"callAfterContentChecked": null,
"events": null,
"changeDetection": null,
"version": 1

View File

@ -13,10 +13,10 @@
"type": null,
"exportAs": null,
"callOnDestroy": null,
"callOnCheck": null,
"callDoCheck": null,
"callOnInit": null,
"callOnChange": null,
"callOnAllChangesDone": null,
"callOnChanges": null,
"callAfterContentChecked": null,
"events": null,
"changeDetection": null,
"version": 1
@ -36,10 +36,10 @@
"type": 0,
"exportAs": null,
"callOnDestroy": false,
"callOnCheck": false,
"callDoCheck": false,
"callOnInit": false,
"callOnChange": false,
"callOnAllChangesDone": false,
"callOnChanges": false,
"callAfterContentChecked": false,
"events": [],
"changeDetection": null,
"version": 1
@ -59,10 +59,10 @@
"type": 1,
"exportAs": null,
"callOnDestroy": false,
"callOnCheck": false,
"callDoCheck": false,
"callOnInit": false,
"callOnChange": false,
"callOnAllChangesDone": false,
"callOnChanges": false,
"callAfterContentChecked": false,
"events": ["eventName"],
"changeDetection": null,
"version": 1
@ -82,10 +82,10 @@
"type": 1,
"exportAs": null,
"callOnDestroy": false,
"callOnCheck": false,
"callDoCheck": false,
"callOnInit": false,
"callOnChange": false,
"callOnAllChangesDone": false,
"callOnChanges": false,
"callAfterContentChecked": false,
"events": [],
"changeDetection": null,
"version": 1
@ -105,10 +105,10 @@
"type": 1,
"exportAs": null,
"callOnDestroy": false,
"callOnCheck": false,
"callDoCheck": false,
"callOnInit": false,
"callOnChange": false,
"callOnAllChangesDone": false,
"callOnChanges": false,
"callAfterContentChecked": false,
"events": [],
"changeDetection": null,
"version": 1
@ -128,10 +128,10 @@
"type": 1,
"exportAs": null,
"callOnDestroy": false,
"callOnCheck": false,
"callDoCheck": false,
"callOnInit": false,
"callOnChange": false,
"callOnAllChangesDone": false,
"callOnChanges": false,
"callAfterContentChecked": false,
"events": [],
"changeDetection": null,
"version": 1
@ -151,10 +151,10 @@
"type": 1,
"exportAs": null,
"callOnDestroy": false,
"callOnCheck": false,
"callDoCheck": false,
"callOnInit": false,
"callOnChange": false,
"callOnAllChangesDone": false,
"callOnChanges": false,
"callAfterContentChecked": false,
"events": [],
"changeDetection": null,
"version": 1
@ -174,10 +174,10 @@
"type": 1,
"exportAs": null,
"callOnDestroy": false,
"callOnCheck": false,
"callDoCheck": false,
"callOnInit": false,
"callOnChange": false,
"callOnAllChangesDone": false,
"callOnChanges": false,
"callAfterContentChecked": false,
"events": [],
"changeDetection": null,
"version": 1