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

@ -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 {