@@ -29,13 +29,18 @@ import {
29
29
} from '../../../lite/src/api/snapshot' ;
30
30
import { Firestore } from './database' ;
31
31
import { cast } from '../../../lite/src/api/util' ;
32
- import { DocumentReference , Query } from '../../../lite/src/api/reference' ;
32
+ import {
33
+ DocumentReference ,
34
+ Query ,
35
+ queryEqual
36
+ } from '../../../lite/src/api/reference' ;
33
37
import {
34
38
changesFromSnapshot ,
35
39
SnapshotMetadata
36
40
} from '../../../src/api/database' ;
37
41
import { Code , FirestoreError } from '../../../src/util/error' ;
38
42
import { ViewSnapshot } from '../../../src/core/view_snapshot' ;
43
+ import { arrayEquals } from '../../../src/util/misc' ;
39
44
40
45
const DEFAULT_SERVER_TIMESTAMP_BEHAVIOR : ServerTimestampBehavior = 'none' ;
41
46
@@ -121,9 +126,9 @@ export class QuerySnapshot<T = firestore.DocumentData>
121
126
private _cachedChangesIncludeMetadataChanges ?: boolean ;
122
127
123
128
constructor (
124
- private readonly _firestore : Firestore ,
129
+ readonly _firestore : Firestore ,
125
130
readonly query : Query < T > ,
126
- private readonly _snapshot : ViewSnapshot ,
131
+ readonly _snapshot : ViewSnapshot ,
127
132
readonly metadata : SnapshotMetadata
128
133
) { }
129
134
@@ -199,3 +204,30 @@ export class QuerySnapshot<T = firestore.DocumentData>
199
204
) ;
200
205
}
201
206
}
207
+
208
+ // TODO(firestoreexp): Add tests for snapshotEqual with different snapshot
209
+ // metadata
210
+ export function snapshotEqual < T > (
211
+ left : firestore . DocumentSnapshot < T > | firestore . QuerySnapshot < T > ,
212
+ right : firestore . DocumentSnapshot < T > | firestore . QuerySnapshot < T >
213
+ ) : boolean {
214
+ if ( left instanceof DocumentSnapshot && right instanceof DocumentSnapshot ) {
215
+ return (
216
+ left . _firestore === right . _firestore &&
217
+ left . _key . isEqual ( right . _key ) &&
218
+ ( left . _document === null
219
+ ? right . _document === null
220
+ : left . _document . isEqual ( right . _document ) ) &&
221
+ left . _converter === right . _converter
222
+ ) ;
223
+ } else if ( left instanceof QuerySnapshot && right instanceof QuerySnapshot ) {
224
+ return (
225
+ left . _firestore === right . _firestore &&
226
+ queryEqual ( left . query , right . query ) &&
227
+ left . metadata . isEqual ( right . metadata ) &&
228
+ left . _snapshot . isEqual ( right . _snapshot )
229
+ ) ;
230
+ }
231
+
232
+ return false ;
233
+ }
0 commit comments