-
Notifications
You must be signed in to change notification settings - Fork 3.9k
/
document_change.dart
85 lines (68 loc) 路 2.53 KB
/
document_change.dart
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Copyright 2020, the Chromium project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
part of cloud_firestore;
/// A [DocumentChange] represents a change to the documents matching a query.
///
/// It contains the document affected and the type of change that occurred
/// (added, modified, or removed).
abstract class DocumentChange<T extends Object?> {
/// The type of change that occurred (added, modified, or removed).
DocumentChangeType get type;
/// The index of the changed document in the result set immediately prior to
/// this [DocumentChange] (i.e. supposing that all prior [DocumentChange] objects
/// have been applied).
///
/// -1 is returned for [DocumentChangeType.added] events.
int get oldIndex;
/// The index of the changed document in the result set immediately after this
/// [DocumentChange] (i.e. supposing that all prior [DocumentChange] objects
/// and the current [DocumentChange] object have been applied).
///
/// -1 is returned for [DocumentChangeType.removed] events.
int get newIndex;
/// Returns the [DocumentSnapshot] for this instance.
DocumentSnapshot<T> get doc;
}
class _JsonDocumentChange implements DocumentChange<Map<String, dynamic>> {
_JsonDocumentChange(this._firestore, this._delegate) {
DocumentChangePlatform.verify(_delegate);
}
final DocumentChangePlatform _delegate;
final FirebaseFirestore _firestore;
@override
DocumentChangeType get type => _delegate.type;
@override
int get oldIndex => _delegate.oldIndex;
@override
int get newIndex => _delegate.newIndex;
@override
DocumentSnapshot<Map<String, dynamic>> get doc {
return _JsonDocumentSnapshot(_firestore, _delegate.document);
}
}
class _WithConverterDocumentChange<T extends Object?>
implements DocumentChange<T> {
_WithConverterDocumentChange(
this._originalDocumentChange,
this._fromFirestore,
this._toFirestore,
);
final DocumentChange<Map<String, dynamic>> _originalDocumentChange;
final FromFirestore<T> _fromFirestore;
final ToFirestore<T> _toFirestore;
@override
DocumentChangeType get type => _originalDocumentChange.type;
@override
int get oldIndex => _originalDocumentChange.oldIndex;
@override
int get newIndex => _originalDocumentChange.newIndex;
@override
DocumentSnapshot<T> get doc {
return _WithConverterDocumentSnapshot<T>(
_originalDocumentChange.doc,
_fromFirestore,
_toFirestore,
);
}
}