1
1
library change_detection;
2
2
3
- typedef EvalExceptionHandler (error, stack);
3
+ typedef void EvalExceptionHandler (error, stack);
4
4
5
5
/**
6
6
* An interface for [ChangeDetectorGroup] groups related watches together. It
@@ -13,49 +13,48 @@ abstract class ChangeDetectorGroup<H> {
13
13
* Watch a specific [field] on an [object] .
14
14
*
15
15
* If the [field] is:
16
- * - _name_ - Name of the property to watch. (If the [object] is a Map then
16
+ * * _name_ - Name of the property to watch. (If the [object] is a Map then
17
17
* treat the name as a key.)
18
- * - _[] _ - Watch all items in an array.
19
- * - _{}_ - Watch all items in a Map.
20
- * - _._ - Watch the actual object identity.
21
- *
18
+ * * _null_ - Watch all the items for arrays and maps otherwise the object
19
+ * identity.
22
20
*
23
21
* Parameters:
24
- * - [object] to watch.
25
- * - [field] to watch on the [object] .
26
- * - [handler] an opaque object passed on to [Record] .
22
+ * * [object] to watch.
23
+ * * [field] to watch on the [object] .
24
+ * * [handler] an opaque object passed on to [Record] .
27
25
*/
28
26
WatchRecord <H > watch (Object object, String field, H handler);
29
27
30
- /** Use to remove all watches in the group in an efficient manner. */
28
+ /// Remove all the watches in an efficient manner.
31
29
void remove ();
32
30
33
- /** Create a child [ChangeDetectorGroup] */
31
+ /// Create a child [ChangeDetectorGroup]
34
32
ChangeDetectorGroup <H > newGroup ();
35
33
}
36
34
37
35
/**
38
36
* An interface for [ChangeDetector] . An application can have multiple instances
39
- * of the [ChangeDetector] to be used for checking different application domains.
37
+ * of the [ChangeDetector] to be used for checking different application
38
+ * domains.
40
39
*
41
40
* [ChangeDetector] works by comparing the identity of the objects not by
42
41
* calling the `.equals()` method. This is because ChangeDetector needs to have
43
42
* predictable performance, and the developer can implement `.equals()` on top
44
43
* of identity checks.
45
44
*
46
- * - [H] A [Record] has associated handler object. The handler object is
47
- * opaque to the [ChangeDetector] but it is meaningful to the code which
48
- * registered the watcher. It can be a data structure, an object, or a function.
49
- * It is up to the developer to attach meaning to it.
45
+ * [H] A [Record] has associated handler object. The handler object is opaque
46
+ * to the [ChangeDetector] but it is meaningful to the code which registered the
47
+ * watcher. It can be a data structure, an object, or a function. It is up to
48
+ * the developer to attach meaning to it.
50
49
*/
51
50
abstract class ChangeDetector <H > extends ChangeDetectorGroup <H > {
52
51
/**
53
52
* This method does the work of collecting the changes and returns them as a
54
53
* linked list of [Record] s. The [Record] s are returned in the
55
54
* same order as they were registered.
56
55
*/
57
- Iterator <Record <H >> collectChanges ({ EvalExceptionHandler exceptionHandler,
58
- AvgStopwatch stopwatch });
56
+ Iterator <Record <H >> collectChanges ({EvalExceptionHandler exceptionHandler,
57
+ AvgStopwatch stopwatch });
59
58
}
60
59
61
60
abstract class Record <H > {
@@ -64,10 +63,9 @@ abstract class Record<H> {
64
63
65
64
/**
66
65
* The field which is being watched:
67
- * - _name_ - Name of the field to watch.
68
- * - _[] _ - Watch all items in an array.
69
- * - _{}_ - Watch all items in a Map.
70
- * - _._ - Watch the actual object identity.
66
+ * * _name_ - Name of the field to watch.
67
+ * * _null_ - Watch all the items for arrays and maps otherwise the object
68
+ * identity.
71
69
*/
72
70
String get field;
73
71
@@ -78,9 +76,16 @@ abstract class Record<H> {
78
76
*/
79
77
H get handler;
80
78
81
- /** Current value of the [field] on the [object] */
79
+ /**
80
+ * * The current value of the [field] on the [object] ,
81
+ * * a [CollectionChangeRecord] if an iterable is observed,
82
+ * * a [MapChangeRecord] if a map is observed.
83
+ */
82
84
get currentValue;
83
- /** Previous value of the [field] on the [object] */
85
+ /**
86
+ * * Previous value of the [field] on the [object] ,
87
+ * * [:null:] when an iterable or a map are observed.
88
+ */
84
89
get previousValue;
85
90
}
86
91
@@ -89,27 +94,24 @@ abstract class Record<H> {
89
94
* manually triggering the checking.
90
95
*/
91
96
abstract class WatchRecord <H > extends Record <H > {
92
- /** Set a new object for checking */
97
+ /// Set a new object for checking
93
98
set object (value);
94
99
95
- /**
96
- * Check to see if the field on the object has changed. Returns [true] if
97
- * change has been detected.
98
- */
100
+ /// Returns [:true:] when changes have been detected
99
101
bool check ();
100
102
101
103
void remove ();
102
104
}
103
105
104
106
/**
105
107
* If the [ChangeDetector] is watching a [Map] then the [currentValue] of
106
- * [Record] will contain an instance of this object . A [MapChangeRecord]
108
+ * [Record] will contain an instance of [MapChangeRecord] . A [MapChangeRecord]
107
109
* contains the changes to the map since the last execution. The changes are
108
110
* reported as a list of [MapKeyValue] s which contain the key as well as its
109
111
* current and previous value.
110
112
*/
111
113
abstract class MapChangeRecord <K , V > {
112
- /// The underlying iterable object
114
+ /// The underlying map object
113
115
Map get map;
114
116
115
117
/// A list of [CollectionKeyValue] s which are in the iteration order. */
@@ -162,13 +164,12 @@ abstract class ChangedKeyValue<K, V> extends MapKeyValue<K, V> {
162
164
ChangedKeyValue <K , V > get nextChangedKeyValue;
163
165
}
164
166
165
-
166
167
/**
167
168
* If the [ChangeDetector] is watching an [Iterable] then the [currentValue] of
168
- * [Record] will contain this object. The [CollectionChangeRecord] contains the
169
- * changes to the collection since the last execution. The changes are reported
170
- * as a list of [CollectionChangeItem] s which contain the item as well as its
171
- * current and previous position in the list .
169
+ * [Record] will contain an instance of [CollectionChangeRecord] . The
170
+ * [CollectionChangeRecord] contains the changes to the collection since the
171
+ * last execution. The changes are reported as a list of [CollectionChangeItem] s
172
+ * which contain the item as well as its current and previous index .
172
173
*/
173
174
abstract class CollectionChangeRecord <V > {
174
175
/** The underlying iterable object */
@@ -195,10 +196,10 @@ abstract class CollectionChangeRecord<V> {
195
196
* which tracks the [item] s [currentKey] and [previousKey] location.
196
197
*/
197
198
abstract class CollectionChangeItem <V > {
198
- /** Previous item location in the list or [null] if addition. */
199
+ /** Previous item location in the list or [: null: ] if addition. */
199
200
int get previousIndex;
200
201
201
- /** Current item location in the list or [null] if removal. */
202
+ /** Current item location in the list or [: null: ] if removal. */
202
203
int get currentIndex;
203
204
204
205
/** The item. */
@@ -241,8 +242,8 @@ abstract class RemovedItem<V> extends CollectionChangeItem<V> {
241
242
RemovedItem <V > get nextRemovedItem;
242
243
}
243
244
244
- typedef FieldGetter (object);
245
- typedef FieldSetter (object, value);
245
+ typedef dynamic FieldGetter (object);
246
+ typedef void FieldSetter (object, value);
246
247
247
248
abstract class FieldGetterFactory {
248
249
get isMethodInvoke;
0 commit comments