diff --git a/modules/change_detection/src/record_range.js b/modules/change_detection/src/record_range.js index 480947e78a..d8aaa50ffd 100644 --- a/modules/change_detection/src/record_range.js +++ b/modules/change_detection/src/record_range.js @@ -116,8 +116,8 @@ export class RecordRange { addRange(child:RecordRange) { var lastRecord = this.tailRecord.prev; - var prevEnabledRecord = this._prevEnabled(this.tailRecord); - var nextEnabledRerord = this._nextEnabled(this.tailRecord); + var prevEnabledRecord = RecordRange._prevEnabled(this.tailRecord); + var nextEnabledRerord = RecordRange._nextEnabled(this.tailRecord); var firstEnabledChildRecord = child.findFirstEnabledRecord(); var lastEnabledChildRecord = child.findLastEnabledRecord(); @@ -134,12 +134,12 @@ export class RecordRange { } } - removeRange(child:RecordRange) { - var firstEnabledChildRecord = child.findFirstEnabledRecord(); - var lastEnabledChildRecord = child.findLastEnabledRecord(); + remove() { + var firstEnabledChildRecord = this.findFirstEnabledRecord(); + var lastEnabledChildRecord = this.findLastEnabledRecord(); - var next = child.tailRecord.next; - var prev = child.headRecord.prev; + var next = this.tailRecord.next; + var prev = this.headRecord.prev; _link(prev, next); @@ -164,8 +164,8 @@ export class RecordRange { enableRecord(record:Record) { if (!record.disabled) return; - var prevEnabled = this._prevEnabled(record); - var nextEnabled = this._nextEnabled(record); + var prevEnabled = RecordRange._prevEnabled(record); + var nextEnabled = RecordRange._nextEnabled(record); record.prevEnabled = prevEnabled; record.nextEnabled = nextEnabled; @@ -176,9 +176,9 @@ export class RecordRange { record.disabled = false; } - disableRange(child:RecordRange) { - var firstEnabledChildRecord = child.findFirstEnabledRecord(); - var lastEnabledChildRecord = child.findLastEnabledRecord(); + disable() { + var firstEnabledChildRecord = this.findFirstEnabledRecord(); + var lastEnabledChildRecord = this.findLastEnabledRecord(); var nextEnabled = lastEnabledChildRecord.nextEnabled; var prevEnabled = firstEnabledChildRecord.prevEnabled; @@ -186,25 +186,25 @@ export class RecordRange { if (isPresent(nextEnabled)) nextEnabled.prevEnabled = prevEnabled; if (isPresent(prevEnabled)) prevEnabled.nextEnabled = nextEnabled; - child.disabled = true; + this.disabled = true; } - enableRange(child:RecordRange) { - var prevEnabledRecord = this._prevEnabled(child.headRecord); - var nextEnabledRecord = this._nextEnabled(child.tailRecord); + enable() { + var prevEnabledRecord = RecordRange._prevEnabled(this.headRecord); + var nextEnabledRecord = RecordRange._nextEnabled(this.tailRecord); - var firstEnabledChildRecord = child.findFirstEnabledRecord(); - var lastEnabledChildRecord = child.findLastEnabledRecord(); + var firstEnabledthisRecord = this.findFirstEnabledRecord(); + var lastEnabledthisRecord = this.findLastEnabledRecord(); - if (isPresent(firstEnabledChildRecord) && isPresent(prevEnabledRecord)){ - _linkEnabled(prevEnabledRecord, firstEnabledChildRecord); + if (isPresent(firstEnabledthisRecord) && isPresent(prevEnabledRecord)){ + _linkEnabled(prevEnabledRecord, firstEnabledthisRecord); } - if (isPresent(lastEnabledChildRecord) && isPresent(nextEnabledRecord)){ - _linkEnabled(lastEnabledChildRecord, nextEnabledRecord); + if (isPresent(lastEnabledthisRecord) && isPresent(nextEnabledRecord)){ + _linkEnabled(lastEnabledthisRecord, nextEnabledRecord); } - child.disabled = false; + this.disabled = false; } /** @@ -262,7 +262,7 @@ export class RecordRange { * * The function skips disabled sub ranges. */ - _nextEnabled(record:Record) { + static _nextEnabled(record:Record) { record = record.next; while (isPresent(record) && record.disabled) { if (record.isMarkerRecord && record.recordRange.disabled) { @@ -281,7 +281,7 @@ export class RecordRange { * * The function skips disabled sub ranges. */ - _prevEnabled(record:Record) { + static _prevEnabled(record:Record) { record = record.prev; while (isPresent(record) && record.disabled) { if (record.isMarkerRecord && record.recordRange.disabled) { diff --git a/modules/change_detection/test/record_range_spec.js b/modules/change_detection/test/record_range_spec.js index d8173188f3..e48418709c 100644 --- a/modules/change_detection/test/record_range_spec.js +++ b/modules/change_detection/test/record_range_spec.js @@ -128,11 +128,11 @@ export function main() { parent.addRange(child1); parent.addRange(child2); - parent.removeRange(child1); + child1.remove(); expect(enabledRecords(parent, recordNames)).toEqual(['record2']); - parent.removeRange(child2); + child2.remove(); expect(enabledRecords(parent, recordNames)).toEqual([]); }); @@ -143,7 +143,7 @@ export function main() { parent.addRange(emptyRange); parent.addRange(child2); - parent.removeRange(emptyRange); + emptyRange.remove(); expect(enabledRecords(parent, recordNames)).toEqual(['record1', 'record2']); }); @@ -153,7 +153,7 @@ export function main() { parent.addRange(child2); parent.addRange(child3); - parent.removeRange(child2); + child2.remove(); expect(enabledRecords(parent, recordNames)).toEqual(['record1', 'record3']); }); @@ -283,7 +283,7 @@ export function main() { var parent = new RecordRange(null, null); parent.addRange(child1); - parent.disableRange(child1); + child1.disable(); expect(enabledRecords(parent, recordNames)).toEqual([]); }); @@ -291,9 +291,10 @@ export function main() { it('should enable a single record range', () => { var parent = new RecordRange(null, null); parent.addRange(child1); - parent.disableRange(child1); - parent.enableRange(child1); + child1.disable(); + + child1.enable(); expect(enabledRecords(parent, recordNames)).toEqual(['record1']); }); @@ -305,8 +306,8 @@ export function main() { parent.addRange(child3); parent.addRange(child4); - parent.disableRange(child2); - parent.disableRange(child3); + child2.disable(); + child3.disable(); expect(enabledRecords(parent, recordNames)).toEqual(['record1', 'record4']); }); @@ -317,11 +318,12 @@ export function main() { parent.addRange(child2); parent.addRange(child3); parent.addRange(child4); - parent.disableRange(child2); - parent.disableRange(child3); - parent.enableRange(child2); - parent.enableRange(child3); + child2.disable(); + child2.disable(); + + child2.enable(); + child3.enable(); expect(enabledRecords(parent, recordNames)).toEqual([ 'record1', 'record2', 'record3', 'record4'