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

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);
}
}

View File

@ -40,13 +40,13 @@ export class NgFor {
_ngForOf: any;
private _differ: IterableDiffer;
constructor(private viewContainer: ViewContainerRef, private templateRef: TemplateRef,
private iterableDiffers: IterableDiffers, private cdr: ChangeDetectorRef) {}
constructor(private _viewContainer: ViewContainerRef, private _templateRef: TemplateRef,
private _iterableDiffers: IterableDiffers, private _cdr: ChangeDetectorRef) {}
set ngForOf(value: any) {
this._ngForOf = value;
if (isBlank(this._differ) && isPresent(value)) {
this._differ = this.iterableDiffers.find(value).create(this.cdr);
this._differ = this._iterableDiffers.find(value).create(this._cdr);
}
}
@ -67,19 +67,19 @@ export class NgFor {
changes.forEachMovedItem((movedRecord) =>
recordViewTuples.push(new RecordViewTuple(movedRecord, null)));
var insertTuples = NgFor.bulkRemove(recordViewTuples, this.viewContainer);
var insertTuples = NgFor.bulkRemove(recordViewTuples, this._viewContainer);
changes.forEachAddedItem((addedRecord) =>
insertTuples.push(new RecordViewTuple(addedRecord, null)));
NgFor.bulkInsert(insertTuples, this.viewContainer, this.templateRef);
NgFor.bulkInsert(insertTuples, this._viewContainer, this._templateRef);
for (var i = 0; i < insertTuples.length; i++) {
this._perViewChange(insertTuples[i].view, insertTuples[i].record);
}
for (var i = 0, ilen = this.viewContainer.length; i < ilen; i++) {
this.viewContainer.get(i).setLocal('last', i === ilen - 1);
for (var i = 0, ilen = this._viewContainer.length; i < ilen; i++) {
this._viewContainer.get(i).setLocal('last', i === ilen - 1);
}
}

View File

@ -33,7 +33,7 @@ class _ArrayLogger {
*/
@Injectable()
export class ExceptionHandler {
constructor(private logger: any, private rethrowException: boolean = true) {}
constructor(private _logger: any, private _rethrowException: boolean = true) {}
static exceptionToString(exception: any, stackTrace: any = null, reason: string = null): string {
var l = new _ArrayLogger();
@ -47,36 +47,36 @@ export class ExceptionHandler {
var originalStack = this._findOriginalStack(exception);
var context = this._findContext(exception);
this.logger.logGroup(`EXCEPTION: ${exception}`);
this._logger.logGroup(`EXCEPTION: ${exception}`);
if (isPresent(stackTrace) && isBlank(originalStack)) {
this.logger.logError("STACKTRACE:");
this.logger.logError(this._longStackTrace(stackTrace));
this._logger.logError("STACKTRACE:");
this._logger.logError(this._longStackTrace(stackTrace));
}
if (isPresent(reason)) {
this.logger.logError(`REASON: ${reason}`);
this._logger.logError(`REASON: ${reason}`);
}
if (isPresent(originalException)) {
this.logger.logError(`ORIGINAL EXCEPTION: ${originalException}`);
this._logger.logError(`ORIGINAL EXCEPTION: ${originalException}`);
}
if (isPresent(originalStack)) {
this.logger.logError("ORIGINAL STACKTRACE:");
this.logger.logError(this._longStackTrace(originalStack));
this._logger.logError("ORIGINAL STACKTRACE:");
this._logger.logError(this._longStackTrace(originalStack));
}
if (isPresent(context)) {
this.logger.logError("ERROR CONTEXT:");
this.logger.logError(context);
this._logger.logError("ERROR CONTEXT:");
this._logger.logError(context);
}
this.logger.logGroupEnd();
this._logger.logGroupEnd();
// We rethrow exceptions, so operations like 'bootstrap' will result in an error
// when an exception happens. If we do not rethrow, bootstrap will always succeed.
if (this.rethrowException) throw exception;
if (this._rethrowException) throw exception;
}
_longStackTrace(stackTrace: any): any {

View File

@ -110,5 +110,5 @@ export class DatePipe implements PipeTransform {
return DateFormatter.format(value, defaultLocale, pattern);
}
private supports(obj: any): boolean { return isDate(obj) || isNumber(obj); }
supports(obj: any): boolean { return isDate(obj) || isNumber(obj); }
}

View File

@ -31,30 +31,34 @@ import {setProperty} from './shared';
}
})
export class CheckboxControlValueAccessor implements ControlValueAccessor {
private cd: NgControl;
private _cd: NgControl;
onChange = (_) => {};
onTouched = () => {};
constructor(@Self() cd: NgControl, private renderer: Renderer, private elementRef: ElementRef) {
this.cd = cd;
constructor(@Self() cd: NgControl, private _renderer: Renderer, private _elementRef: ElementRef) {
this._cd = cd;
cd.valueAccessor = this;
}
writeValue(value: any) { setProperty(this.renderer, this.elementRef, "checked", value); }
writeValue(value: any) { setProperty(this._renderer, this._elementRef, "checked", value); }
get ngClassUntouched(): boolean {
return isPresent(this.cd.control) ? this.cd.control.untouched : false;
return isPresent(this._cd.control) ? this._cd.control.untouched : false;
}
get ngClassTouched(): boolean {
return isPresent(this.cd.control) ? this.cd.control.touched : false;
return isPresent(this._cd.control) ? this._cd.control.touched : false;
}
get ngClassPristine(): boolean {
return isPresent(this.cd.control) ? this.cd.control.pristine : false;
return isPresent(this._cd.control) ? this._cd.control.pristine : false;
}
get ngClassDirty(): boolean {
return isPresent(this._cd.control) ? this._cd.control.dirty : false;
}
get ngClassValid(): boolean {
return isPresent(this._cd.control) ? this._cd.control.valid : false;
}
get ngClassDirty(): boolean { return isPresent(this.cd.control) ? this.cd.control.dirty : false; }
get ngClassValid(): boolean { return isPresent(this.cd.control) ? this.cd.control.valid : false; }
get ngClassInvalid(): boolean {
return isPresent(this.cd.control) ? !this.cd.control.valid : false;
return isPresent(this._cd.control) ? !this._cd.control.valid : false;
}
registerOnChange(fn: (_: any) => {}): void { this.onChange = fn; }

View File

@ -32,12 +32,12 @@ import {setProperty} from './shared';
}
})
export class DefaultValueAccessor implements ControlValueAccessor {
private cd: NgControl;
private _cd: NgControl;
onChange = (_) => {};
onTouched = () => {};
constructor(@Self() cd: NgControl, private renderer: Renderer, private elementRef: ElementRef) {
this.cd = cd;
constructor(@Self() cd: NgControl, private _renderer: Renderer, private _elementRef: ElementRef) {
this._cd = cd;
cd.valueAccessor = this;
}
@ -45,22 +45,26 @@ export class DefaultValueAccessor implements ControlValueAccessor {
// both this.value and setProperty are required at the moment
// remove when a proper imperative API is provided
var normalizedValue = isBlank(value) ? '' : value;
setProperty(this.renderer, this.elementRef, 'value', normalizedValue);
setProperty(this._renderer, this._elementRef, 'value', normalizedValue);
}
get ngClassUntouched(): boolean {
return isPresent(this.cd.control) ? this.cd.control.untouched : false;
return isPresent(this._cd.control) ? this._cd.control.untouched : false;
}
get ngClassTouched(): boolean {
return isPresent(this.cd.control) ? this.cd.control.touched : false;
return isPresent(this._cd.control) ? this._cd.control.touched : false;
}
get ngClassPristine(): boolean {
return isPresent(this.cd.control) ? this.cd.control.pristine : false;
return isPresent(this._cd.control) ? this._cd.control.pristine : false;
}
get ngClassDirty(): boolean {
return isPresent(this._cd.control) ? this._cd.control.dirty : false;
}
get ngClassValid(): boolean {
return isPresent(this._cd.control) ? this._cd.control.valid : false;
}
get ngClassDirty(): boolean { return isPresent(this.cd.control) ? this.cd.control.dirty : false; }
get ngClassValid(): boolean { return isPresent(this.cd.control) ? this.cd.control.valid : false; }
get ngClassInvalid(): boolean {
return isPresent(this.cd.control) ? !this.cd.control.valid : false;
return isPresent(this._cd.control) ? !this._cd.control.valid : false;
}
registerOnChange(fn: (_: any) => void): void { this.onChange = fn; }

View File

@ -41,36 +41,40 @@ export class NgSelectOption {
}
})
export class SelectControlValueAccessor implements ControlValueAccessor {
private cd: NgControl;
private _cd: NgControl;
value: string;
onChange = (_) => {};
onTouched = () => {};
constructor(@Self() cd: NgControl, private renderer: Renderer, private elementRef: ElementRef,
constructor(@Self() cd: NgControl, private _renderer: Renderer, private _elementRef: ElementRef,
@Query(NgSelectOption, {descendants: true}) query: QueryList<NgSelectOption>) {
this.cd = cd;
this._cd = cd;
cd.valueAccessor = this;
this._updateValueWhenListOfOptionsChanges(query);
}
writeValue(value: any) {
this.value = value;
setProperty(this.renderer, this.elementRef, "value", value);
setProperty(this._renderer, this._elementRef, "value", value);
}
get ngClassUntouched(): boolean {
return isPresent(this.cd.control) ? this.cd.control.untouched : false;
return isPresent(this._cd.control) ? this._cd.control.untouched : false;
}
get ngClassTouched(): boolean {
return isPresent(this.cd.control) ? this.cd.control.touched : false;
return isPresent(this._cd.control) ? this._cd.control.touched : false;
}
get ngClassPristine(): boolean {
return isPresent(this.cd.control) ? this.cd.control.pristine : false;
return isPresent(this._cd.control) ? this._cd.control.pristine : false;
}
get ngClassDirty(): boolean {
return isPresent(this._cd.control) ? this._cd.control.dirty : false;
}
get ngClassValid(): boolean {
return isPresent(this._cd.control) ? this._cd.control.valid : false;
}
get ngClassDirty(): boolean { return isPresent(this.cd.control) ? this.cd.control.dirty : false; }
get ngClassValid(): boolean { return isPresent(this.cd.control) ? this.cd.control.valid : false; }
get ngClassInvalid(): boolean {
return isPresent(this.cd.control) ? !this.cd.control.valid : false;
return isPresent(this._cd.control) ? !this._cd.control.valid : false;
}
registerOnChange(fn: () => any): void { this.onChange = fn; }

View File

@ -191,7 +191,7 @@ export class PathRecognizer {
specificity: number;
terminal: boolean = true;
hash: string;
private cache: Map<string, ComponentInstruction> = new Map<string, ComponentInstruction>();
private _cache: Map<string, ComponentInstruction> = new Map<string, ComponentInstruction>();
// TODO: cache component instruction instances by params and by ParsedUrl instance
@ -299,11 +299,11 @@ export class PathRecognizer {
private _getInstruction(urlPath: string, urlParams: string[], _recognizer: PathRecognizer,
params: StringMap<string, any>): ComponentInstruction {
var hashKey = urlPath + '?' + urlParams.join('?');
if (this.cache.has(hashKey)) {
return this.cache.get(hashKey);
if (this._cache.has(hashKey)) {
return this._cache.get(hashKey);
}
var instruction = new ComponentInstruction(urlPath, urlParams, _recognizer, params);
this.cache.set(hashKey, instruction);
this._cache.set(hashKey, instruction);
return instruction;
}

View File

@ -74,19 +74,19 @@ function matchUrlSegment(str: string): string {
}
export class UrlParser {
private remaining: string;
private _remaining: string;
peekStartsWith(str: string): boolean { return this.remaining.startsWith(str); }
peekStartsWith(str: string): boolean { return this._remaining.startsWith(str); }
capture(str: string): void {
if (!this.remaining.startsWith(str)) {
if (!this._remaining.startsWith(str)) {
throw new BaseException(`Expected "${str}".`);
}
this.remaining = this.remaining.substring(str.length);
this._remaining = this._remaining.substring(str.length);
}
parse(url: string): Url {
this.remaining = url;
this._remaining = url;
if (url == '' || url == '/') {
return new Url('');
}
@ -98,7 +98,7 @@ export class UrlParser {
if (this.peekStartsWith('/')) {
this.capture('/');
}
var path = matchUrlSegment(this.remaining);
var path = matchUrlSegment(this._remaining);
this.capture(path);
var aux = [];
@ -123,13 +123,13 @@ export class UrlParser {
// segment + (matrix params) + (aux segments)
parseSegment(): Url {
if (this.remaining.length == 0) {
if (this._remaining.length == 0) {
return null;
}
if (this.peekStartsWith('/')) {
this.capture('/');
}
var path = matchUrlSegment(this.remaining);
var path = matchUrlSegment(this._remaining);
this.capture(path);
var matrixParams = null;
@ -152,7 +152,7 @@ export class UrlParser {
var params = {};
this.capture('?');
this.parseParam(params);
while (this.remaining.length > 0 && this.peekStartsWith('&')) {
while (this._remaining.length > 0 && this.peekStartsWith('&')) {
this.capture('&');
this.parseParam(params);
}
@ -161,7 +161,7 @@ export class UrlParser {
parseMatrixParams(): StringMap<string, any> {
var params = {};
while (this.remaining.length > 0 && this.peekStartsWith(';')) {
while (this._remaining.length > 0 && this.peekStartsWith(';')) {
this.capture(';');
this.parseParam(params);
}
@ -169,7 +169,7 @@ export class UrlParser {
}
parseParam(params: StringMap<string, any>): void {
var key = matchUrlSegment(this.remaining);
var key = matchUrlSegment(this._remaining);
if (isBlank(key)) {
return;
}
@ -177,7 +177,7 @@ export class UrlParser {
var value: any = true;
if (this.peekStartsWith('=')) {
this.capture('=');
var valueMatch = matchUrlSegment(this.remaining);
var valueMatch = matchUrlSegment(this._remaining);
if (isPresent(valueMatch)) {
value = valueMatch;
this.capture(value);
@ -191,7 +191,7 @@ export class UrlParser {
var routes = [];
this.capture('(');
while (!this.peekStartsWith(')') && this.remaining.length > 0) {
while (!this.peekStartsWith(')') && this._remaining.length > 0) {
routes.push(this.parseSegment());
if (this.peekStartsWith('//')) {
this.capture('//');

View File

@ -49,8 +49,8 @@ export function main() {
@Directive({selector: '[lifecycle-dir]', lifecycle: [LifecycleEvent.DoCheck]})
class LifecycleDir {
constructor(private log: Log) {}
doCheck() { this.log.add("child_doCheck"); }
constructor(private _log: Log) {}
doCheck() { this._log.add("child_doCheck"); }
}
@Component({
@ -69,21 +69,21 @@ class LifecycleDir {
@View({template: `<div lifecycle-dir></div>`, directives: [LifecycleDir]})
class LifecycleCmp {
field;
constructor(private log: Log) {}
constructor(private _log: Log) {}
onChanges(_) { this.log.add("onChanges"); }
onChanges(_) { this._log.add("onChanges"); }
onInit() { this.log.add("onInit"); }
onInit() { this._log.add("onInit"); }
doCheck() { this.log.add("doCheck"); }
doCheck() { this._log.add("doCheck"); }
afterContentInit() { this.log.add("afterContentInit"); }
afterContentInit() { this._log.add("afterContentInit"); }
afterContentChecked() { this.log.add("afterContentChecked"); }
afterContentChecked() { this._log.add("afterContentChecked"); }
afterViewInit() { this.log.add("afterViewInit"); }
afterViewInit() { this._log.add("afterViewInit"); }
afterViewChecked() { this.log.add("afterViewChecked"); }
afterViewChecked() { this._log.add("afterViewChecked"); }
}
@Component({selector: 'my-comp'})

View File

@ -217,16 +217,16 @@ export function main() {
}
export class MockStep implements CompileStep {
constructor(private processElementClosure: Function,
private processStyleClosure: Function = null) {}
constructor(private _processElementClosure: Function,
private _processStyleClosure: Function = null) {}
processElement(parent: CompileElement, current: CompileElement, control: CompileControl) {
if (isPresent(this.processElementClosure)) {
this.processElementClosure(parent, current, control);
if (isPresent(this._processElementClosure)) {
this._processElementClosure(parent, current, control);
}
}
processStyle(style: string): string {
if (isPresent(this.processStyleClosure)) {
return this.processStyleClosure(style);
if (isPresent(this._processStyleClosure)) {
return this._processStyleClosure(style);
} else {
return style;
}

View File

@ -33,9 +33,9 @@ class OrderItem {
class Order {
constructor(public orderId: number, public customerName: string, public limit: number,
private dataService: DataService) {}
private _dataService: DataService) {}
get items(): OrderItem[] { return this.dataService.itemsFor(this); }
get items(): OrderItem[] { return this._dataService.itemsFor(this); }
get total(): number { return this.items.map(i => i.total).reduce((a, b) => a + b); }
}
@ -113,8 +113,8 @@ class DataService {
class OrderListComponent {
orders: Order[];
constructor(private service: DataService) { this.orders = service.orders; }
select(order: Order): void { this.service.currentOrder = order; }
constructor(private _service: DataService) { this.orders = _service.orders; }
select(order: Order): void { this._service.currentOrder = order; }
}
@ -182,13 +182,13 @@ class OrderItemComponent {
directives: [FORM_DIRECTIVES, OrderItemComponent, NgFor, NgIf]
})
class OrderDetailsComponent {
constructor(private service: DataService) {}
constructor(private _service: DataService) {}
get order(): Order { return this.service.currentOrder; }
get order(): Order { return this._service.currentOrder; }
deleteItem(item: OrderItem): void { this.service.deleteItem(item); }
deleteItem(item: OrderItem): void { this._service.deleteItem(item); }
addItem(): void { this.service.addItemForOrder(this.order); }
addItem(): void { this._service.addItemForOrder(this.order); }
}
@Component({selector: 'order-management-app', viewBindings: [DataService]})

View File

@ -115,8 +115,8 @@ class DataService {
directives: [FORM_DIRECTIVES]
})
class FullNameComponent {
constructor(private service: DataService) {}
get person(): Person { return this.service.currentPerson; }
constructor(private _service: DataService) {}
get person(): Person { return this._service.currentPerson; }
}
@Component({selector: 'person-detail-cmp'})
@ -163,8 +163,8 @@ class FullNameComponent {
directives: [FORM_DIRECTIVES, NgIf]
})
class PersonsDetailComponent {
constructor(private service: DataService) {}
get person(): Person { return this.service.currentPerson; }
constructor(private _service: DataService) {}
get person(): Person { return this._service.currentPerson; }
}
@Component({selector: 'persons-cmp'})
@ -186,9 +186,9 @@ class PersonsDetailComponent {
class PersonsComponent {
persons: Person[];
constructor(private service: DataService) { this.persons = service.persons; }
constructor(private _service: DataService) { this.persons = _service.persons; }
select(person: Person): void { this.service.currentPerson = person; }
select(person: Person): void { this._service.currentPerson = person; }
}