refactor(change_detector): moves enableRecord/disableRecord into the Record class

This commit is contained in:
vsavkin 2014-12-04 13:19:10 -08:00
parent 7f941eb936
commit c3dc373ec4
3 changed files with 44 additions and 44 deletions

View File

@ -177,7 +177,7 @@ export class Record {
return ! this.disabled;
}
set disabled(value:boolean) {
_setDisabled(value:boolean) {
if (value) {
this._mode |= RECORD_FLAG_DISABLED;
} else {
@ -185,6 +185,31 @@ export class Record {
}
}
enable() {
if (this.isEnabled()) return;
var prevEnabled = this.findPrevEnabled();
var nextEnabled = this.findNextEnabled();
this.prevEnabled = prevEnabled;
this.nextEnabled = nextEnabled;
if (isPresent(prevEnabled)) prevEnabled.nextEnabled = this;
if (isPresent(nextEnabled)) nextEnabled.prevEnabled = this;
this._setDisabled(false);
}
disable() {
var prevEnabled = this.prevEnabled;
var nextEnabled = this.nextEnabled;
if (isPresent(prevEnabled)) prevEnabled.nextEnabled = nextEnabled;
if (isPresent(nextEnabled)) nextEnabled.prevEnabled = prevEnabled;
this._setDisabled(true);
}
get isImplicitReceiver():boolean {
return (this._mode & RECORD_FLAG_IMPLICIT_RECEIVER) === RECORD_FLAG_IMPLICIT_RECEIVER;
}
@ -237,7 +262,7 @@ export class Record {
case RECORD_TYPE_NULL:
// no need to check the content again unless the context changes
this.recordRange.disableRecord(this);
this.disable();
this.currentValue = null;
return true;
@ -259,11 +284,11 @@ export class Record {
case RECORD_TYPE_INVOKE_PURE_FUNCTION:
case RECORD_TYPE_INVOKE_FORMATTER:
this.recordRange.disableRecord(this);
this.disable();
return FunctionWrapper.apply(this.funcOrValue, this.args);
case RECORD_TYPE_CONST:
this.recordRange.disableRecord(this);
this.disable();
return this.funcOrValue;
default:
@ -273,12 +298,12 @@ export class Record {
updateArg(value, position:int) {
this.args[position] = value;
this.recordRange.enableRecord(this);
this.enable();
}
updateContext(value) {
this.context = value;
this.recordRange.enableRecord(this);
this.enable();
if (this.isCollection) {
if (ArrayChanges.supports(value)) {
@ -327,7 +352,7 @@ export class Record {
*
* [H ER1 T] [H ER2 T] _nextEnable(ER1) will return ER2
*
* The function skips disabled sub ranges.
* The function skips disabled ranges.
*/
findNextEnabled() {
if (this.isEnabled()) return this.nextEnabled;
@ -348,7 +373,7 @@ export class Record {
*
* [H ER1 T] [H ER2 T] _nextEnable(ER2) will return ER1
*
* The function skips disabled sub ranges.
* The function skips disabled ranges.
*/
findPrevEnabled() {
if (this.isEnabled()) return this.prevEnabled;

View File

@ -163,31 +163,6 @@ export class RecordRange {
}
}
disableRecord(record:Record) {
var prevEnabled = record.prevEnabled;
var nextEnabled = record.nextEnabled;
if (isPresent(prevEnabled)) prevEnabled.nextEnabled = nextEnabled;
if (isPresent(nextEnabled)) nextEnabled.prevEnabled = prevEnabled;
record.disabled = true;
}
enableRecord(record:Record) {
if (record.isEnabled()) return;
var prevEnabled = record.findPrevEnabled();
var nextEnabled = record.findNextEnabled();
record.prevEnabled = prevEnabled;
record.nextEnabled = nextEnabled;
if (isPresent(prevEnabled)) prevEnabled.nextEnabled = record;
if (isPresent(nextEnabled)) nextEnabled.prevEnabled = record;
record.disabled = false;
}
disable() {
var firstEnabledChildRecord = this.findFirstEnabledRecord();
if (isPresent(firstEnabledChildRecord)) {

View File

@ -190,16 +190,16 @@ export function main() {
it('should disable a single record', () => {
rr.addRecord(record1);
rr.disableRecord(record1);
record1.disable();
expect(enabledRecords(rr, recordNames)).toEqual([]);
});
it('should enable a single record', () => {
rr.addRecord(record1);
rr.disableRecord(record1);
record1.disable();
rr.enableRecord(record1);
record1.enable();
expect(enabledRecords(rr, recordNames)).toEqual(['record1']);
});
@ -210,8 +210,8 @@ export function main() {
rr.addRecord(record3);
rr.addRecord(record4);
rr.disableRecord(record2);
rr.disableRecord(record3);
record2.disable();
record3.disable();
expect(record2.disabled).toBeTruthy();
expect(record3.disabled).toBeTruthy();
@ -224,11 +224,11 @@ export function main() {
rr.addRecord(record2);
rr.addRecord(record3);
rr.addRecord(record4);
rr.disableRecord(record2);
rr.disableRecord(record3);
record2.disable();
record3.disable();
rr.enableRecord(record2);
rr.enableRecord(record3);
record2.enable();
record3.enable();
expect(enabledRecords(rr, recordNames)).toEqual(['record1', 'record2', 'record3', 'record4']);
});
@ -247,11 +247,11 @@ export function main() {
rr.addRange(rr2);
rr.addRange(rr3);
rr2.disableRecord(record2);
record2.disable();
expect(enabledRecords(rr, recordNames)).toEqual(['record1', 'record3']);
rr2.enableRecord(record2);
record2.enable();
expect(enabledRecords(rr, recordNames)).toEqual(['record1', 'record2', 'record3']);
});