Skip to content

Commit d8c5ab2

Browse files
harryterkelsenHarry Terkelsen
authored andcommitted
refactor: add leading underscore to private fields
Closes angular#4001
1 parent c320240 commit d8c5ab2

File tree

16 files changed

+150
-138
lines changed

16 files changed

+150
-138
lines changed

modules/angular2/src/core/change_detection/codegen_logic_util.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,21 @@ export class CodegenLogicUtil {
2525
* value of the record. Used by property bindings.
2626
*/
2727
genPropertyBindingEvalValue(protoRec: ProtoRecord): string {
28-
return this.genEvalValue(protoRec, idx => this._names.getLocalName(idx),
29-
this._names.getLocalsAccessorName());
28+
return this._genEvalValue(protoRec, idx => this._names.getLocalName(idx),
29+
this._names.getLocalsAccessorName());
3030
}
3131

3232
/**
3333
* Generates a statement which updates the local variable representing `protoRec` with the current
3434
* value of the record. Used by event bindings.
3535
*/
3636
genEventBindingEvalValue(eventRecord: any, protoRec: ProtoRecord): string {
37-
return this.genEvalValue(protoRec, idx => this._names.getEventLocalName(eventRecord, idx),
38-
"locals");
37+
return this._genEvalValue(protoRec, idx => this._names.getEventLocalName(eventRecord, idx),
38+
"locals");
3939
}
4040

41-
private genEvalValue(protoRec: ProtoRecord, getLocalName: Function,
42-
localsAccessor: string): string {
41+
private _genEvalValue(protoRec: ProtoRecord, getLocalName: Function,
42+
localsAccessor: string): string {
4343
var context = (protoRec.contextIndex == -1) ?
4444
this._names.getDirectiveName(protoRec.directiveIndex) :
4545
getLocalName(protoRec.contextIndex);

modules/angular2/src/core/change_detection/codegen_name_util.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,17 @@ export class CodegenNameUtil {
4444
_sanitizedNames: string[];
4545
_sanitizedEventNames: Map<EventBinding, string[]>;
4646

47-
constructor(private records: ProtoRecord[], private eventBindings: EventBinding[],
48-
private directiveRecords: any[], private utilName: string) {
49-
this._sanitizedNames = ListWrapper.createFixedSize(this.records.length + 1);
47+
constructor(private _records: ProtoRecord[], private _eventBindings: EventBinding[],
48+
private _directiveRecords: any[], private _utilName: string) {
49+
this._sanitizedNames = ListWrapper.createFixedSize(this._records.length + 1);
5050
this._sanitizedNames[CONTEXT_INDEX] = _CONTEXT_ACCESSOR;
51-
for (var i = 0, iLen = this.records.length; i < iLen; ++i) {
52-
this._sanitizedNames[i + 1] = sanitizeName(`${this.records[i].name}${i}`);
51+
for (var i = 0, iLen = this._records.length; i < iLen; ++i) {
52+
this._sanitizedNames[i + 1] = sanitizeName(`${this._records[i].name}${i}`);
5353
}
5454

5555
this._sanitizedEventNames = new Map();
56-
for (var ebIndex = 0; ebIndex < eventBindings.length; ++ebIndex) {
57-
var eb = eventBindings[ebIndex];
56+
for (var ebIndex = 0; ebIndex < _eventBindings.length; ++ebIndex) {
57+
var eb = _eventBindings[ebIndex];
5858
var names = [_CONTEXT_ACCESSOR];
5959
for (var i = 0, iLen = eb.records.length; i < iLen; ++i) {
6060
names.push(sanitizeName(`${eb.records[i].name}${i}_${ebIndex}`));
@@ -99,7 +99,7 @@ export class CodegenNameUtil {
9999
if (i == CONTEXT_INDEX) {
100100
declarations.push(`${this.getLocalName(i)} = ${this.getFieldName(i)}`);
101101
} else {
102-
var rec = this.records[i - 1];
102+
var rec = this._records[i - 1];
103103
if (rec.argumentToPureFunction) {
104104
var changeName = this.getChangeName(i);
105105
declarations.push(`${this.getLocalName(i)},${changeName}`);
@@ -138,20 +138,20 @@ export class CodegenNameUtil {
138138
getAllFieldNames(): string[] {
139139
var fieldList = [];
140140
for (var k = 0, kLen = this.getFieldCount(); k < kLen; ++k) {
141-
if (k === 0 || this.records[k - 1].shouldBeChecked()) {
141+
if (k === 0 || this._records[k - 1].shouldBeChecked()) {
142142
fieldList.push(this.getFieldName(k));
143143
}
144144
}
145145

146-
for (var i = 0, iLen = this.records.length; i < iLen; ++i) {
147-
var rec = this.records[i];
146+
for (var i = 0, iLen = this._records.length; i < iLen; ++i) {
147+
var rec = this._records[i];
148148
if (rec.isPipeRecord()) {
149149
fieldList.push(this.getPipeName(rec.selfIndex));
150150
}
151151
}
152152

153-
for (var j = 0, jLen = this.directiveRecords.length; j < jLen; ++j) {
154-
var dRec = this.directiveRecords[j];
153+
for (var j = 0, jLen = this._directiveRecords.length; j < jLen; ++j) {
154+
var dRec = this._directiveRecords[j];
155155
fieldList.push(this.getDirectiveName(dRec.directiveIndex));
156156
if (!dRec.isDefaultChangeDetection()) {
157157
fieldList.push(this.getDetectorName(dRec.directiveIndex));
@@ -169,7 +169,7 @@ export class CodegenNameUtil {
169169
if (ListWrapper.isEmpty(fields)) return '';
170170

171171
// At least one assignment.
172-
fields.push(`${this.utilName}.uninitialized;`);
172+
fields.push(`${this._utilName}.uninitialized;`);
173173
return ListWrapper.join(fields, ' = ');
174174
}
175175

@@ -179,9 +179,9 @@ export class CodegenNameUtil {
179179
genPipeOnDestroy(): string {
180180
return ListWrapper.join(
181181
ListWrapper.map(
182-
ListWrapper.filter(this.records, (r) => { return r.isPipeRecord(); }),
182+
ListWrapper.filter(this._records, (r) => { return r.isPipeRecord(); }),
183183
(r) => {
184-
return `${this.utilName}.callPipeOnDestroy(${this.getPipeName(r.selfIndex)});`;
184+
return `${this._utilName}.callPipeOnDestroy(${this.getPipeName(r.selfIndex)});`;
185185
}),
186186
'\n');
187187
}

modules/angular2/src/core/change_detection/dynamic_change_detector.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ export class DynamicChangeDetector extends AbstractChangeDetector<any> {
2626

2727
constructor(id: string, dispatcher: any, numberOfPropertyProtoRecords: number,
2828
propertyBindingTargets: BindingTarget[], directiveIndices: DirectiveIndex[],
29-
strategy: ChangeDetectionStrategy, private records: ProtoRecord[],
30-
private eventBindings: EventBinding[], private directiveRecords: DirectiveRecord[],
31-
private genConfig: ChangeDetectorGenConfig) {
29+
strategy: ChangeDetectionStrategy, private _records: ProtoRecord[],
30+
private _eventBindings: EventBinding[], private _directiveRecords: DirectiveRecord[],
31+
private _genConfig: ChangeDetectorGenConfig) {
3232
super(id, dispatcher, numberOfPropertyProtoRecords, propertyBindingTargets, directiveIndices,
3333
strategy);
34-
var len = records.length + 1;
34+
var len = _records.length + 1;
3535
this.values = ListWrapper.createFixedSize(len);
3636
this.localPipes = ListWrapper.createFixedSize(len);
3737
this.prevContexts = ListWrapper.createFixedSize(len);
@@ -80,7 +80,7 @@ export class DynamicChangeDetector extends AbstractChangeDetector<any> {
8080
}
8181

8282
_matchingEventBindings(eventName: string, elIndex: number): EventBinding[] {
83-
return ListWrapper.filter(this.eventBindings,
83+
return ListWrapper.filter(this._eventBindings,
8484
eb => eb.eventName == eventName && eb.elIndex === elIndex);
8585
}
8686

@@ -119,7 +119,7 @@ export class DynamicChangeDetector extends AbstractChangeDetector<any> {
119119
checkNoChanges(): void { this.runDetectChanges(true); }
120120

121121
detectChangesInRecordsInternal(throwOnChange: boolean) {
122-
var protos = this.records;
122+
var protos = this._records;
123123

124124
var changes = null;
125125
var isChanged = false;
@@ -162,12 +162,12 @@ export class DynamicChangeDetector extends AbstractChangeDetector<any> {
162162
}
163163

164164
_firstInBinding(r: ProtoRecord): boolean {
165-
var prev = ChangeDetectionUtil.protoByIndex(this.records, r.selfIndex - 1);
165+
var prev = ChangeDetectionUtil.protoByIndex(this._records, r.selfIndex - 1);
166166
return isBlank(prev) || prev.bindingRecord !== r.bindingRecord;
167167
}
168168

169169
afterContentLifecycleCallbacksInternal() {
170-
var dirs = this.directiveRecords;
170+
var dirs = this._directiveRecords;
171171
for (var i = dirs.length - 1; i >= 0; --i) {
172172
var dir = dirs[i];
173173
if (dir.callAfterContentInit && !this.alreadyChecked) {
@@ -181,7 +181,7 @@ export class DynamicChangeDetector extends AbstractChangeDetector<any> {
181181
}
182182

183183
afterViewLifecycleCallbacksInternal() {
184-
var dirs = this.directiveRecords;
184+
var dirs = this._directiveRecords;
185185
for (var i = dirs.length - 1; i >= 0; --i) {
186186
var dir = dirs[i];
187187
if (dir.callAfterViewInit && !this.alreadyChecked) {
@@ -201,7 +201,7 @@ export class DynamicChangeDetector extends AbstractChangeDetector<any> {
201201
bindingRecord.setter(this._getDirectiveFor(directiveIndex), change.currentValue);
202202
}
203203

204-
if (this.genConfig.logBindingUpdate) {
204+
if (this._genConfig.logBindingUpdate) {
205205
super.logBindingUpdate(change.currentValue);
206206
}
207207
}

modules/angular2/src/core/change_detection/proto_change_detector.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,19 @@ export class DynamicProtoChangeDetector implements ProtoChangeDetector {
4242
_eventBindingRecords: EventBinding[];
4343
_directiveIndices: DirectiveIndex[];
4444

45-
constructor(private definition: ChangeDetectorDefinition) {
46-
this._propertyBindingRecords = createPropertyRecords(definition);
47-
this._eventBindingRecords = createEventRecords(definition);
48-
this._propertyBindingTargets = this.definition.bindingRecords.map(b => b.target);
49-
this._directiveIndices = this.definition.directiveRecords.map(d => d.directiveIndex);
45+
constructor(private _definition: ChangeDetectorDefinition) {
46+
this._propertyBindingRecords = createPropertyRecords(_definition);
47+
this._eventBindingRecords = createEventRecords(_definition);
48+
this._propertyBindingTargets = this._definition.bindingRecords.map(b => b.target);
49+
this._directiveIndices = this._definition.directiveRecords.map(d => d.directiveIndex);
5050
}
5151

5252
instantiate(dispatcher: any): ChangeDetector {
5353
return new DynamicChangeDetector(
54-
this.definition.id, dispatcher, this._propertyBindingRecords.length,
55-
this._propertyBindingTargets, this._directiveIndices, this.definition.strategy,
56-
this._propertyBindingRecords, this._eventBindingRecords, this.definition.directiveRecords,
57-
this.definition.genConfig);
54+
this._definition.id, dispatcher, this._propertyBindingRecords.length,
55+
this._propertyBindingTargets, this._directiveIndices, this._definition.strategy,
56+
this._propertyBindingRecords, this._eventBindingRecords, this._definition.directiveRecords,
57+
this._definition.genConfig);
5858
}
5959
}
6060

modules/angular2/src/core/directives/ng_for.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ export class NgFor {
4040
_ngForOf: any;
4141
private _differ: IterableDiffer;
4242

43-
constructor(private viewContainer: ViewContainerRef, private templateRef: TemplateRef,
44-
private iterableDiffers: IterableDiffers, private cdr: ChangeDetectorRef) {}
43+
constructor(private _viewContainer: ViewContainerRef, private _templateRef: TemplateRef,
44+
private _iterableDiffers: IterableDiffers, private _cdr: ChangeDetectorRef) {}
4545

4646
set ngForOf(value: any) {
4747
this._ngForOf = value;
4848
if (isBlank(this._differ) && isPresent(value)) {
49-
this._differ = this.iterableDiffers.find(value).create(this.cdr);
49+
this._differ = this._iterableDiffers.find(value).create(this._cdr);
5050
}
5151
}
5252

@@ -67,19 +67,19 @@ export class NgFor {
6767
changes.forEachMovedItem((movedRecord) =>
6868
recordViewTuples.push(new RecordViewTuple(movedRecord, null)));
6969

70-
var insertTuples = NgFor.bulkRemove(recordViewTuples, this.viewContainer);
70+
var insertTuples = NgFor.bulkRemove(recordViewTuples, this._viewContainer);
7171

7272
changes.forEachAddedItem((addedRecord) =>
7373
insertTuples.push(new RecordViewTuple(addedRecord, null)));
7474

75-
NgFor.bulkInsert(insertTuples, this.viewContainer, this.templateRef);
75+
NgFor.bulkInsert(insertTuples, this._viewContainer, this._templateRef);
7676

7777
for (var i = 0; i < insertTuples.length; i++) {
7878
this._perViewChange(insertTuples[i].view, insertTuples[i].record);
7979
}
8080

81-
for (var i = 0, ilen = this.viewContainer.length; i < ilen; i++) {
82-
this.viewContainer.get(i).setLocal('last', i === ilen - 1);
81+
for (var i = 0, ilen = this._viewContainer.length; i < ilen; i++) {
82+
this._viewContainer.get(i).setLocal('last', i === ilen - 1);
8383
}
8484
}
8585

modules/angular2/src/core/exception_handler.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class _ArrayLogger {
3333
*/
3434
@Injectable()
3535
export class ExceptionHandler {
36-
constructor(private logger: any, private rethrowException: boolean = true) {}
36+
constructor(private _logger: any, private _rethrowException: boolean = true) {}
3737

3838
static exceptionToString(exception: any, stackTrace: any = null, reason: string = null): string {
3939
var l = new _ArrayLogger();
@@ -47,36 +47,36 @@ export class ExceptionHandler {
4747
var originalStack = this._findOriginalStack(exception);
4848
var context = this._findContext(exception);
4949

50-
this.logger.logGroup(`EXCEPTION: ${exception}`);
50+
this._logger.logGroup(`EXCEPTION: ${exception}`);
5151

5252
if (isPresent(stackTrace) && isBlank(originalStack)) {
53-
this.logger.logError("STACKTRACE:");
54-
this.logger.logError(this._longStackTrace(stackTrace));
53+
this._logger.logError("STACKTRACE:");
54+
this._logger.logError(this._longStackTrace(stackTrace));
5555
}
5656

5757
if (isPresent(reason)) {
58-
this.logger.logError(`REASON: ${reason}`);
58+
this._logger.logError(`REASON: ${reason}`);
5959
}
6060

6161
if (isPresent(originalException)) {
62-
this.logger.logError(`ORIGINAL EXCEPTION: ${originalException}`);
62+
this._logger.logError(`ORIGINAL EXCEPTION: ${originalException}`);
6363
}
6464

6565
if (isPresent(originalStack)) {
66-
this.logger.logError("ORIGINAL STACKTRACE:");
67-
this.logger.logError(this._longStackTrace(originalStack));
66+
this._logger.logError("ORIGINAL STACKTRACE:");
67+
this._logger.logError(this._longStackTrace(originalStack));
6868
}
6969

7070
if (isPresent(context)) {
71-
this.logger.logError("ERROR CONTEXT:");
72-
this.logger.logError(context);
71+
this._logger.logError("ERROR CONTEXT:");
72+
this._logger.logError(context);
7373
}
7474

75-
this.logger.logGroupEnd();
75+
this._logger.logGroupEnd();
7676

7777
// We rethrow exceptions, so operations like 'bootstrap' will result in an error
7878
// when an exception happens. If we do not rethrow, bootstrap will always succeed.
79-
if (this.rethrowException) throw exception;
79+
if (this._rethrowException) throw exception;
8080
}
8181

8282
_longStackTrace(stackTrace: any): any {

modules/angular2/src/core/pipes/date_pipe.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,5 +110,5 @@ export class DatePipe implements PipeTransform {
110110
return DateFormatter.format(value, defaultLocale, pattern);
111111
}
112112

113-
private supports(obj: any): boolean { return isDate(obj) || isNumber(obj); }
113+
supports(obj: any): boolean { return isDate(obj) || isNumber(obj); }
114114
}

modules/angular2/src/forms/directives/checkbox_value_accessor.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,30 +31,34 @@ import {setProperty} from './shared';
3131
}
3232
})
3333
export class CheckboxControlValueAccessor implements ControlValueAccessor {
34-
private cd: NgControl;
34+
private _cd: NgControl;
3535
onChange = (_) => {};
3636
onTouched = () => {};
3737

38-
constructor(@Self() cd: NgControl, private renderer: Renderer, private elementRef: ElementRef) {
39-
this.cd = cd;
38+
constructor(@Self() cd: NgControl, private _renderer: Renderer, private _elementRef: ElementRef) {
39+
this._cd = cd;
4040
cd.valueAccessor = this;
4141
}
4242

43-
writeValue(value: any) { setProperty(this.renderer, this.elementRef, "checked", value); }
43+
writeValue(value: any) { setProperty(this._renderer, this._elementRef, "checked", value); }
4444

4545
get ngClassUntouched(): boolean {
46-
return isPresent(this.cd.control) ? this.cd.control.untouched : false;
46+
return isPresent(this._cd.control) ? this._cd.control.untouched : false;
4747
}
4848
get ngClassTouched(): boolean {
49-
return isPresent(this.cd.control) ? this.cd.control.touched : false;
49+
return isPresent(this._cd.control) ? this._cd.control.touched : false;
5050
}
5151
get ngClassPristine(): boolean {
52-
return isPresent(this.cd.control) ? this.cd.control.pristine : false;
52+
return isPresent(this._cd.control) ? this._cd.control.pristine : false;
53+
}
54+
get ngClassDirty(): boolean {
55+
return isPresent(this._cd.control) ? this._cd.control.dirty : false;
56+
}
57+
get ngClassValid(): boolean {
58+
return isPresent(this._cd.control) ? this._cd.control.valid : false;
5359
}
54-
get ngClassDirty(): boolean { return isPresent(this.cd.control) ? this.cd.control.dirty : false; }
55-
get ngClassValid(): boolean { return isPresent(this.cd.control) ? this.cd.control.valid : false; }
5660
get ngClassInvalid(): boolean {
57-
return isPresent(this.cd.control) ? !this.cd.control.valid : false;
61+
return isPresent(this._cd.control) ? !this._cd.control.valid : false;
5862
}
5963

6064
registerOnChange(fn: (_: any) => {}): void { this.onChange = fn; }

0 commit comments

Comments
 (0)