refactor: add leading underscore to private fields

Closes #4001
This commit is contained in:
Harry Terkelsen
2015-09-04 15:09:02 -07:00
committed by Harry Terkelsen
parent c320240086
commit d8c5ab232c
16 changed files with 150 additions and 138 deletions

View File

@ -25,8 +25,8 @@ export class CodegenLogicUtil {
* value of the record. Used by property bindings.
*/
genPropertyBindingEvalValue(protoRec: ProtoRecord): string {
return this.genEvalValue(protoRec, idx => this._names.getLocalName(idx),
this._names.getLocalsAccessorName());
return this._genEvalValue(protoRec, idx => this._names.getLocalName(idx),
this._names.getLocalsAccessorName());
}
/**
@ -34,12 +34,12 @@ export class CodegenLogicUtil {
* value of the record. Used by event bindings.
*/
genEventBindingEvalValue(eventRecord: any, protoRec: ProtoRecord): string {
return this.genEvalValue(protoRec, idx => this._names.getEventLocalName(eventRecord, idx),
"locals");
return this._genEvalValue(protoRec, idx => this._names.getEventLocalName(eventRecord, idx),
"locals");
}
private genEvalValue(protoRec: ProtoRecord, getLocalName: Function,
localsAccessor: string): string {
private _genEvalValue(protoRec: ProtoRecord, getLocalName: Function,
localsAccessor: string): string {
var context = (protoRec.contextIndex == -1) ?
this._names.getDirectiveName(protoRec.directiveIndex) :
getLocalName(protoRec.contextIndex);

View File

@ -44,17 +44,17 @@ export class CodegenNameUtil {
_sanitizedNames: string[];
_sanitizedEventNames: Map<EventBinding, string[]>;
constructor(private records: ProtoRecord[], private eventBindings: EventBinding[],
private directiveRecords: any[], private utilName: string) {
this._sanitizedNames = ListWrapper.createFixedSize(this.records.length + 1);
constructor(private _records: ProtoRecord[], private _eventBindings: EventBinding[],
private _directiveRecords: any[], private _utilName: string) {
this._sanitizedNames = ListWrapper.createFixedSize(this._records.length + 1);
this._sanitizedNames[CONTEXT_INDEX] = _CONTEXT_ACCESSOR;
for (var i = 0, iLen = this.records.length; i < iLen; ++i) {
this._sanitizedNames[i + 1] = sanitizeName(`${this.records[i].name}${i}`);
for (var i = 0, iLen = this._records.length; i < iLen; ++i) {
this._sanitizedNames[i + 1] = sanitizeName(`${this._records[i].name}${i}`);
}
this._sanitizedEventNames = new Map();
for (var ebIndex = 0; ebIndex < eventBindings.length; ++ebIndex) {
var eb = eventBindings[ebIndex];
for (var ebIndex = 0; ebIndex < _eventBindings.length; ++ebIndex) {
var eb = _eventBindings[ebIndex];
var names = [_CONTEXT_ACCESSOR];
for (var i = 0, iLen = eb.records.length; i < iLen; ++i) {
names.push(sanitizeName(`${eb.records[i].name}${i}_${ebIndex}`));
@ -99,7 +99,7 @@ export class CodegenNameUtil {
if (i == CONTEXT_INDEX) {
declarations.push(`${this.getLocalName(i)} = ${this.getFieldName(i)}`);
} else {
var rec = this.records[i - 1];
var rec = this._records[i - 1];
if (rec.argumentToPureFunction) {
var changeName = this.getChangeName(i);
declarations.push(`${this.getLocalName(i)},${changeName}`);
@ -138,20 +138,20 @@ export class CodegenNameUtil {
getAllFieldNames(): string[] {
var fieldList = [];
for (var k = 0, kLen = this.getFieldCount(); k < kLen; ++k) {
if (k === 0 || this.records[k - 1].shouldBeChecked()) {
if (k === 0 || this._records[k - 1].shouldBeChecked()) {
fieldList.push(this.getFieldName(k));
}
}
for (var i = 0, iLen = this.records.length; i < iLen; ++i) {
var rec = this.records[i];
for (var i = 0, iLen = this._records.length; i < iLen; ++i) {
var rec = this._records[i];
if (rec.isPipeRecord()) {
fieldList.push(this.getPipeName(rec.selfIndex));
}
}
for (var j = 0, jLen = this.directiveRecords.length; j < jLen; ++j) {
var dRec = this.directiveRecords[j];
for (var j = 0, jLen = this._directiveRecords.length; j < jLen; ++j) {
var dRec = this._directiveRecords[j];
fieldList.push(this.getDirectiveName(dRec.directiveIndex));
if (!dRec.isDefaultChangeDetection()) {
fieldList.push(this.getDetectorName(dRec.directiveIndex));
@ -169,7 +169,7 @@ export class CodegenNameUtil {
if (ListWrapper.isEmpty(fields)) return '';
// At least one assignment.
fields.push(`${this.utilName}.uninitialized;`);
fields.push(`${this._utilName}.uninitialized;`);
return ListWrapper.join(fields, ' = ');
}
@ -179,9 +179,9 @@ export class CodegenNameUtil {
genPipeOnDestroy(): string {
return ListWrapper.join(
ListWrapper.map(
ListWrapper.filter(this.records, (r) => { return r.isPipeRecord(); }),
ListWrapper.filter(this._records, (r) => { return r.isPipeRecord(); }),
(r) => {
return `${this.utilName}.callPipeOnDestroy(${this.getPipeName(r.selfIndex)});`;
return `${this._utilName}.callPipeOnDestroy(${this.getPipeName(r.selfIndex)});`;
}),
'\n');
}

View File

@ -26,12 +26,12 @@ export class DynamicChangeDetector extends AbstractChangeDetector<any> {
constructor(id: string, dispatcher: any, numberOfPropertyProtoRecords: number,
propertyBindingTargets: BindingTarget[], directiveIndices: DirectiveIndex[],
strategy: ChangeDetectionStrategy, private records: ProtoRecord[],
private eventBindings: EventBinding[], private directiveRecords: DirectiveRecord[],
private genConfig: ChangeDetectorGenConfig) {
strategy: ChangeDetectionStrategy, private _records: ProtoRecord[],
private _eventBindings: EventBinding[], private _directiveRecords: DirectiveRecord[],
private _genConfig: ChangeDetectorGenConfig) {
super(id, dispatcher, numberOfPropertyProtoRecords, propertyBindingTargets, directiveIndices,
strategy);
var len = records.length + 1;
var len = _records.length + 1;
this.values = ListWrapper.createFixedSize(len);
this.localPipes = ListWrapper.createFixedSize(len);
this.prevContexts = ListWrapper.createFixedSize(len);
@ -80,7 +80,7 @@ export class DynamicChangeDetector extends AbstractChangeDetector<any> {
}
_matchingEventBindings(eventName: string, elIndex: number): EventBinding[] {
return ListWrapper.filter(this.eventBindings,
return ListWrapper.filter(this._eventBindings,
eb => eb.eventName == eventName && eb.elIndex === elIndex);
}
@ -119,7 +119,7 @@ export class DynamicChangeDetector extends AbstractChangeDetector<any> {
checkNoChanges(): void { this.runDetectChanges(true); }
detectChangesInRecordsInternal(throwOnChange: boolean) {
var protos = this.records;
var protos = this._records;
var changes = null;
var isChanged = false;
@ -162,12 +162,12 @@ export class DynamicChangeDetector extends AbstractChangeDetector<any> {
}
_firstInBinding(r: ProtoRecord): boolean {
var prev = ChangeDetectionUtil.protoByIndex(this.records, r.selfIndex - 1);
var prev = ChangeDetectionUtil.protoByIndex(this._records, r.selfIndex - 1);
return isBlank(prev) || prev.bindingRecord !== r.bindingRecord;
}
afterContentLifecycleCallbacksInternal() {
var dirs = this.directiveRecords;
var dirs = this._directiveRecords;
for (var i = dirs.length - 1; i >= 0; --i) {
var dir = dirs[i];
if (dir.callAfterContentInit && !this.alreadyChecked) {
@ -181,7 +181,7 @@ export class DynamicChangeDetector extends AbstractChangeDetector<any> {
}
afterViewLifecycleCallbacksInternal() {
var dirs = this.directiveRecords;
var dirs = this._directiveRecords;
for (var i = dirs.length - 1; i >= 0; --i) {
var dir = dirs[i];
if (dir.callAfterViewInit && !this.alreadyChecked) {
@ -201,7 +201,7 @@ export class DynamicChangeDetector extends AbstractChangeDetector<any> {
bindingRecord.setter(this._getDirectiveFor(directiveIndex), change.currentValue);
}
if (this.genConfig.logBindingUpdate) {
if (this._genConfig.logBindingUpdate) {
super.logBindingUpdate(change.currentValue);
}
}

View File

@ -42,19 +42,19 @@ export class DynamicProtoChangeDetector implements ProtoChangeDetector {
_eventBindingRecords: EventBinding[];
_directiveIndices: DirectiveIndex[];
constructor(private definition: ChangeDetectorDefinition) {
this._propertyBindingRecords = createPropertyRecords(definition);
this._eventBindingRecords = createEventRecords(definition);
this._propertyBindingTargets = this.definition.bindingRecords.map(b => b.target);
this._directiveIndices = this.definition.directiveRecords.map(d => d.directiveIndex);
constructor(private _definition: ChangeDetectorDefinition) {
this._propertyBindingRecords = createPropertyRecords(_definition);
this._eventBindingRecords = createEventRecords(_definition);
this._propertyBindingTargets = this._definition.bindingRecords.map(b => b.target);
this._directiveIndices = this._definition.directiveRecords.map(d => d.directiveIndex);
}
instantiate(dispatcher: any): ChangeDetector {
return new DynamicChangeDetector(
this.definition.id, dispatcher, this._propertyBindingRecords.length,
this._propertyBindingTargets, this._directiveIndices, this.definition.strategy,
this._propertyBindingRecords, this._eventBindingRecords, this.definition.directiveRecords,
this.definition.genConfig);
this._definition.id, dispatcher, this._propertyBindingRecords.length,
this._propertyBindingTargets, this._directiveIndices, this._definition.strategy,
this._propertyBindingRecords, this._eventBindingRecords, this._definition.directiveRecords,
this._definition.genConfig);
}
}