From b91351469f23a8663137fcd4ee3d5263a73ac275 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Thu, 15 Oct 2015 16:24:42 -0700 Subject: [PATCH] refactor(ChangeDetector): misc minor updates --- .../src/core/change_detection/coalesce.ts | 13 +++--- .../dynamic_change_detector.ts | 46 ++++++++++--------- .../change_detection/proto_change_detector.ts | 13 +++--- 3 files changed, 38 insertions(+), 34 deletions(-) diff --git a/modules/angular2/src/core/change_detection/coalesce.ts b/modules/angular2/src/core/change_detection/coalesce.ts index 80edefbf35..fcc6b07a53 100644 --- a/modules/angular2/src/core/change_detection/coalesce.ts +++ b/modules/angular2/src/core/change_detection/coalesce.ts @@ -3,14 +3,15 @@ import {ListWrapper, Map} from 'angular2/src/core/facade/collection'; import {RecordType, ProtoRecord} from './proto_record'; /** - * Removes "duplicate" records. It assuming that record evaluation does not - * have side-effects. + * Removes "duplicate" records. It assumes that record evaluation does not have side-effects. * - * Records that are not last in bindings are removed and all the indices - * of the records that depend on them are updated. + * Records that are not last in bindings are removed and all the indices of the records that depend + * on them are updated. * - * Records that are last in bindings CANNOT be removed, and instead are - * replaced with very cheap SELF records. + * Records that are last in bindings CANNOT be removed, and instead are replaced with very cheap + * SELF records. + * + * @internal */ export function coalesce(records: ProtoRecord[]): ProtoRecord[] { var res: ProtoRecord[] = []; diff --git a/modules/angular2/src/core/change_detection/dynamic_change_detector.ts b/modules/angular2/src/core/change_detection/dynamic_change_detector.ts index efbca30e31..361b558c06 100644 --- a/modules/angular2/src/core/change_detection/dynamic_change_detector.ts +++ b/modules/angular2/src/core/change_detection/dynamic_change_detector.ts @@ -7,7 +7,7 @@ import {EventBinding} from './event_binding'; import {BindingRecord, BindingTarget} from './binding_record'; import {DirectiveRecord, DirectiveIndex} from './directive_record'; import {Locals} from './parser/locals'; -import {ChangeDetectorGenConfig} from './interfaces'; +import {ChangeDispatcher, ChangeDetectorGenConfig} from './interfaces'; import {ChangeDetectionUtil, SimpleChange} from './change_detection_util'; import {ChangeDetectionStrategy, ChangeDetectorState} from './constants'; import {ProtoRecord, RecordType} from './proto_record'; @@ -19,7 +19,7 @@ export class DynamicChangeDetector extends AbstractChangeDetector { prevContexts: any[]; directives: any = null; - constructor(id: string, dispatcher: any, numberOfPropertyProtoRecords: number, + constructor(id: string, dispatcher: ChangeDispatcher, numberOfPropertyProtoRecords: number, propertyBindingTargets: BindingTarget[], directiveIndices: DirectiveIndex[], strategy: ChangeDetectionStrategy, private _records: ProtoRecord[], private _eventBindings: EventBinding[], private _directiveRecords: DirectiveRecord[], @@ -195,7 +195,7 @@ export class DynamicChangeDetector extends AbstractChangeDetector { } /** @internal */ - _updateDirectiveOrElement(change, bindingRecord) { + private _updateDirectiveOrElement(change, bindingRecord) { if (isBlank(bindingRecord.directiveRecord)) { super.notifyDispatcher(change.currentValue); } else { @@ -209,7 +209,7 @@ export class DynamicChangeDetector extends AbstractChangeDetector { } /** @internal */ - _addChange(bindingRecord: BindingRecord, change, changes) { + private _addChange(bindingRecord: BindingRecord, change, changes) { if (bindingRecord.callOnChanges()) { return super.addChange(changes, change.previousValue, change.currentValue); } else { @@ -218,13 +218,16 @@ export class DynamicChangeDetector extends AbstractChangeDetector { } /** @internal */ - _getDirectiveFor(directiveIndex) { return this.directives.getDirectiveFor(directiveIndex); } + private _getDirectiveFor(directiveIndex) { + return this.directives.getDirectiveFor(directiveIndex); + } /** @internal */ - _getDetectorFor(directiveIndex) { return this.directives.getDetectorFor(directiveIndex); } + private _getDetectorFor(directiveIndex) { return this.directives.getDetectorFor(directiveIndex); } /** @internal */ - _check(proto: ProtoRecord, throwOnChange: boolean, values: any[], locals: Locals): SimpleChange { + private _check(proto: ProtoRecord, throwOnChange: boolean, values: any[], + locals: Locals): SimpleChange { if (proto.isPipeRecord()) { return this._pipeCheck(proto, throwOnChange, values); } else { @@ -233,7 +236,8 @@ export class DynamicChangeDetector extends AbstractChangeDetector { } /** @internal */ - _referenceCheck(proto: ProtoRecord, throwOnChange: boolean, values: any[], locals: Locals) { + private _referenceCheck(proto: ProtoRecord, throwOnChange: boolean, values: any[], + locals: Locals) { if (this._pureFuncAndArgsDidNotChange(proto)) { this._setChanged(proto, false); return null; @@ -272,7 +276,7 @@ export class DynamicChangeDetector extends AbstractChangeDetector { } /** @internal */ - _calculateCurrValue(proto: ProtoRecord, values: any[], locals: Locals) { + private _calculateCurrValue(proto: ProtoRecord, values: any[], locals: Locals) { switch (proto.mode) { case RecordType.Self: return this._readContext(proto, values); @@ -340,7 +344,7 @@ export class DynamicChangeDetector extends AbstractChangeDetector { } /** @internal */ - _pipeCheck(proto: ProtoRecord, throwOnChange: boolean, values: any[]) { + private _pipeCheck(proto: ProtoRecord, throwOnChange: boolean, values: any[]) { var context = this._readContext(proto, values); var selectedPipe = this._pipeFor(proto, context); if (!selectedPipe.pure || this._argsOrContextChanged(proto)) { @@ -379,7 +383,7 @@ export class DynamicChangeDetector extends AbstractChangeDetector { } /** @internal */ - _pipeFor(proto: ProtoRecord, context) { + private _pipeFor(proto: ProtoRecord, context) { var storedPipe = this._readPipe(proto); if (isPresent(storedPipe)) return storedPipe; @@ -389,7 +393,7 @@ export class DynamicChangeDetector extends AbstractChangeDetector { } /** @internal */ - _readContext(proto: ProtoRecord, values: any[]) { + private _readContext(proto: ProtoRecord, values: any[]) { if (proto.contextIndex == -1) { return this._getDirectiveFor(proto.directiveIndex); } @@ -397,29 +401,29 @@ export class DynamicChangeDetector extends AbstractChangeDetector { } /** @internal */ - _readSelf(proto: ProtoRecord, values: any[]) { return values[proto.selfIndex]; } + private _readSelf(proto: ProtoRecord, values: any[]) { return values[proto.selfIndex]; } /** @internal */ - _writeSelf(proto: ProtoRecord, value, values: any[]) { values[proto.selfIndex] = value; } + private _writeSelf(proto: ProtoRecord, value, values: any[]) { values[proto.selfIndex] = value; } /** @internal */ - _readPipe(proto: ProtoRecord) { return this.localPipes[proto.selfIndex]; } + private _readPipe(proto: ProtoRecord) { return this.localPipes[proto.selfIndex]; } /** @internal */ - _writePipe(proto: ProtoRecord, value) { this.localPipes[proto.selfIndex] = value; } + private _writePipe(proto: ProtoRecord, value) { this.localPipes[proto.selfIndex] = value; } /** @internal */ - _setChanged(proto: ProtoRecord, value: boolean) { + private _setChanged(proto: ProtoRecord, value: boolean) { if (proto.argumentToPureFunction) this.changes[proto.selfIndex] = value; } /** @internal */ - _pureFuncAndArgsDidNotChange(proto: ProtoRecord): boolean { + private _pureFuncAndArgsDidNotChange(proto: ProtoRecord): boolean { return proto.isPureFunction() && !this._argsChanged(proto); } /** @internal */ - _argsChanged(proto: ProtoRecord): boolean { + private _argsChanged(proto: ProtoRecord): boolean { var args = proto.args; for (var i = 0; i < args.length; ++i) { if (this.changes[args[i]]) { @@ -430,12 +434,12 @@ export class DynamicChangeDetector extends AbstractChangeDetector { } /** @internal */ - _argsOrContextChanged(proto: ProtoRecord): boolean { + private _argsOrContextChanged(proto: ProtoRecord): boolean { return this._argsChanged(proto) || this.changes[proto.contextIndex]; } /** @internal */ - _readArgs(proto: ProtoRecord, values: any[]) { + private _readArgs(proto: ProtoRecord, values: any[]) { var res = ListWrapper.createFixedSize(proto.args.length); var args = proto.args; for (var i = 0; i < args.length; ++i) { diff --git a/modules/angular2/src/core/change_detection/proto_change_detector.ts b/modules/angular2/src/core/change_detection/proto_change_detector.ts index 1dfd3e342b..15f93f59da 100644 --- a/modules/angular2/src/core/change_detection/proto_change_detector.ts +++ b/modules/angular2/src/core/change_detection/proto_change_detector.ts @@ -80,9 +80,7 @@ export function createEventRecords(definition: ChangeDetectorDefinition): EventB } export class ProtoRecordBuilder { - records: ProtoRecord[]; - - constructor() { this.records = []; } + records: ProtoRecord[] = []; add(b: BindingRecord, variableNames: string[], bindingIndex: number) { var oldLast = ListWrapper.last(this.records); @@ -265,8 +263,7 @@ class _ConvertAstIntoProtoRecords implements AstVisitor { return this._addRecord(RecordType.Chain, "chain", null, args, null, 0); } - /** @internal */ - _visitAll(asts: any[]) { + private _visitAll(asts: any[]) { var res = ListWrapper.createFixedSize(asts.length); for (var i = 0; i < asts.length; ++i) { res[i] = asts[i].visit(this); @@ -274,8 +271,10 @@ class _ConvertAstIntoProtoRecords implements AstVisitor { return res; } - /** @internal */ - _addRecord(type, name, funcOrValue, args, fixedArgs, context) { + /** + * Adds a `ProtoRecord` and returns its selfIndex. + */ + private _addRecord(type, name, funcOrValue, args, fixedArgs, context): number { var selfIndex = this._records.length + 1; if (context instanceof DirectiveIndex) { this._records.push(new ProtoRecord(type, name, funcOrValue, args, fixedArgs, -1, context,