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:
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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 {
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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; }
|
||||
|
@ -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
|
||||
}));
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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)) {
|
||||
|
@ -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);
|
||||
|
@ -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)) {
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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
|
||||
});
|
||||
|
Reference in New Issue
Block a user