mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 07:14:28 +01:00
opt.: TimeSeq
This commit is contained in:
22
lib/data/model/server/time_seq.dart
Normal file
22
lib/data/model/server/time_seq.dart
Normal file
@@ -0,0 +1,22 @@
|
||||
// ignore_for_file: prefer_final_fields
|
||||
|
||||
abstract class TimeSeq<T extends TimeSeqIface> {
|
||||
List<T> pre;
|
||||
List<T> now;
|
||||
|
||||
void update(List<T> new_) {
|
||||
pre = now;
|
||||
now = new_;
|
||||
|
||||
if (pre.length != now.length) {
|
||||
pre.removeWhere((e) => now.any((el) => e.same(el)));
|
||||
pre.addAll(now.where((e) => pre.every((el) => !e.same(el))));
|
||||
}
|
||||
}
|
||||
|
||||
TimeSeq(this.pre, this.now);
|
||||
}
|
||||
|
||||
abstract class TimeSeqIface<T> {
|
||||
bool same(T other);
|
||||
}
|
||||
Reference in New Issue
Block a user