Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Commit fa1610c

Browse files
EisenbergEffectcaitp
authored andcommitted
refactor(change_detection): remove abstractions intended for multiple implementations
The new observer feature gives us a better model for plugging in custom methods of watching fields. The original detector abstraction turned out to be incorrect. This commit removes the now unnecessary abstractions which were originally intended as an extensibility point.
1 parent 548b0d4 commit fa1610c

8 files changed

+23
-154
lines changed

src/ast.js

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
import {
2-
WatchRecord
3-
} from './change_detection';
4-
51
import {
62
_Handler,
73
_ConstantHandler,
@@ -108,7 +104,7 @@ export class CollectionAST extends AST {
108104
}
109105
}
110106

111-
class _ConstantWatchRecord extends WatchRecord {
107+
class _ConstantWatchRecord {
112108
constructor(watchGroup, expression, currentValue) {
113109
this.currentValue = currentValue;
114110
this.handler = new _ConstantHandler(watchGroup, expression, currentValue);
@@ -141,4 +137,4 @@ class _ConstantWatchRecord extends WatchRecord {
141137
get nextChange() {
142138
return null;
143139
}
144-
}
140+
}

src/change_detection.js

-117
This file was deleted.

src/dirty_checking.js

+17-19
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
import {
2-
ChangeDetector,
3-
ChangeDetectorGroup,
4-
ChangeRecord,
5-
MapChangeRecord,
6-
MapKeyValue,
7-
CollectionChangeRecord,
8-
CollectionChangeItem
9-
} from './change_detection';
101
/**
112
* these cannot currently be defined in the DirtyCheckingRecord class itself,
123
* unfortunately. They've been moved outside and de-const-ified for this
@@ -15,6 +6,7 @@ import {
156
var _MODE_NAMES = [
167
'MARKER', 'IDENT', 'REFLECT', 'GETTER', 'MAP[]', 'ITERABLE', 'MAP'
178
];
9+
1810
var _MODE_MARKER_ = 0;
1911
var _MODE_IDENTITY_ = 1;
2012
var _MODE_REFLECT_ = 2;
@@ -34,7 +26,7 @@ export class GetterCache {
3426
}
3527
}
3628

37-
export class DirtyCheckingChangeDetectorGroup extends ChangeDetector {
29+
export class DirtyCheckingChangeDetectorGroup {
3830
constructor(parent, cache) {
3931
this._parent = parent;
4032
this._getterCache = cache;
@@ -286,7 +278,7 @@ class ChangeIterator {
286278
}
287279
}
288280

289-
class DirtyCheckingRecord extends ChangeRecord {
281+
class DirtyCheckingRecord {
290282
constructor(group, object, fieldName, getter, handler) {
291283
this._group = group;
292284
this._getter = getter;
@@ -341,12 +333,12 @@ class DirtyCheckingRecord extends ChangeRecord {
341333
if (this._mode !== _MODE_ITERABLE_) {
342334
// Last one was collection as well, don't reset state.
343335
this._mode = _MODE_ITERABLE_;
344-
this.currentValue = new _CollectionChangeRecord();
336+
this.currentValue = new CollectionChangeRecord();
345337
}
346338
} else if (this._mode !== _MODE_MAP_) {
347339
// Last one was collection as well, don't reset state.
348340
this._mode = _MODE_MAP_;
349-
this.currentValue = new _MapChangeRecord();
341+
this.currentValue = new MapChangeRecord();
350342
}
351343
} else {
352344
this._mode = _MODE_IDENTITY_;
@@ -439,7 +431,8 @@ class DirtyCheckingRecord extends ChangeRecord {
439431
return `${_MODE_NAMES[this._mode]}[${this.field}]{${hashCode}}`;
440432
}
441433
}
442-
class _MapChangeRecord extends MapChangeRecord {
434+
435+
export class MapChangeRecord {
443436
constructor() {
444437
this._records = {}; // WeakMap perhaps?
445438
this._map = {};
@@ -668,7 +661,8 @@ class _MapChangeRecord extends MapChangeRecord {
668661
}
669662
}
670663
}
671-
class KeyValueRecord extends MapKeyValue {
664+
665+
class KeyValueRecord {
672666
constructor(key) {
673667
this._key = key;
674668
this._previousValue = this._currentValue = null;
@@ -702,7 +696,8 @@ class KeyValueRecord extends MapKeyValue {
702696
: `${this._key}[${this._previousValue} -> ${this._currentValue}]`;
703697
}
704698
}
705-
class _CollectionChangeRecord extends CollectionChangeRecord {
699+
700+
export class CollectionChangeRecord {
706701
constructor() {
707702
this._iterable = null;
708703
this._items = new DuplicateMap();
@@ -827,7 +822,7 @@ class _CollectionChangeRecord extends CollectionChangeRecord {
827822
// assert(isDirty == false);
828823
}
829824
/**
830-
* A [_CollectionChangeRecord] is considered dirty if it has additions, moves
825+
* A [CollectionChangeRecord] is considered dirty if it has additions, moves
831826
* or removals.
832827
*/
833828
get isDirty() {
@@ -1087,7 +1082,8 @@ class _CollectionChangeRecord extends CollectionChangeRecord {
10871082
"removals: " + removals.join(', ') + "\n";
10881083
}
10891084
}
1090-
class ItemRecord extends CollectionChangeItem {
1085+
1086+
class ItemRecord {
10911087
constructor(item) {
10921088
this.item = item;
10931089
this.previousIndex = this.currentIndex = null;
@@ -1114,6 +1110,7 @@ class ItemRecord extends CollectionChangeItem {
11141110
: `${this.item}[${this.previousIndex} -> ${this.currentIndex}]`;
11151111
}
11161112
}
1113+
11171114
class _DuplicateItemRecordList {
11181115
constructor() {
11191116
this.head = this.tail = null;
@@ -1184,6 +1181,7 @@ class _DuplicateItemRecordList {
11841181
return this.head === null;
11851182
}
11861183
}
1184+
11871185
class DuplicateMap {
11881186
constructor() {
11891187
// For an identical behaviour to the Dart implementation, a Map or WeakMap is required. However,
@@ -1217,4 +1215,4 @@ class DuplicateMap {
12171215
clear() {
12181216
this._map.clear();
12191217
}
1220-
}
1218+
}

src/index.js

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
/* jshint ignore:start */
33
// TODO: JsHint right now fails for this code!
44
export * from './ast';
5-
export * from './change_detection';
65
export * from './dirty_checking';
76
export * from './watch_group';
87
/* jshint ignore:end */

src/watch.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ export class Watch {
2929
_WatchList._remove(handler, this);
3030
handler.release();
3131
}
32-
}
32+
}

src/watch_group.js

-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@ import {
22
AST
33
} from './ast';
44

5-
import {
6-
WatchRecord
7-
} from './change_detection';
8-
95
import {
106
_LinkedList,
117
_LinkedListItem,

src/watch_record.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -338,4 +338,4 @@ function methodInvoke(object, method, args) {
338338
return object[method].apply(object, args || __no_args__);
339339
}
340340
}
341-
}
341+
}

test/watchgroup.spec.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,10 @@ import {
99
} from '../src/ast';
1010

1111
import {
12+
GetterCache,
13+
DirtyCheckingChangeDetector,
1214
CollectionChangeRecord,
1315
MapChangeRecord
14-
} from '../src/change_detection';
15-
16-
import {
17-
GetterCache,
18-
DirtyCheckingChangeDetector
1916
} from '../src/dirty_checking';
2017

2118
import {

0 commit comments

Comments
 (0)