rx_model.dart
1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
class Change<T> {
/// Value before change
final T $old;
/// Value after change
final $new;
final ListChangeOp op;
final int pos;
final DateTime time;
final int batch;
Change({this.$new, this.$old, this.batch, this.op, this.pos, DateTime time})
: time = time ?? DateTime.now();
String toString() => 'Change(new: ${$new}, old: ${$old})';
Change.insert({this.$new, this.$old, this.batch, this.pos, DateTime time})
: op = ListChangeOp.add,
time = time ?? new DateTime.now();
Change.set({this.$new, this.$old, this.batch, this.pos, DateTime time})
: op = ListChangeOp.set,
time = time ?? new DateTime.now();
Change.remove({this.$new, this.$old, this.batch, this.pos, DateTime time})
: op = ListChangeOp.remove,
time = time ?? new DateTime.now();
Change.clear({this.$new, this.$old, this.batch, DateTime time})
: op = ListChangeOp.clear,
pos = null,
time = time ?? new DateTime.now();
}
typedef bool Condition();
/// Change operation
enum ListChangeOp { add, remove, clear, set }