Skip to content

Commit 57643cc

Browse files
committed
onSnapshot should call callback if no data changed and includeMetadataChanges is true.
1 parent 1fade31 commit 57643cc

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/firestore-document.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,9 @@ MockFirestoreDocument.prototype.onSnapshot = function (optionsOrObserverOrOnNext
209209
var self = this;
210210
var onNext = optionsOrObserverOrOnNext;
211211
var onError = observerOrOnNextOrOnError;
212+
var includeMetadataChanges = optionsOrObserverOrOnNext.includeMetadataChanges;
212213

213-
if (_.has(optionsOrObserverOrOnNext, 'includeMetadataChanges')) {
214+
if (includeMetadataChanges) {
214215
// Note this doesn't truly mimic the firestore metadata changes behavior, however
215216
// since everything is syncronous, there isn't any difference in behavior.
216217
onNext = observerOrOnNextOrOnError;
@@ -223,7 +224,7 @@ MockFirestoreDocument.prototype.onSnapshot = function (optionsOrObserverOrOnNext
223224
// compare the current state to the one from when this function was created
224225
// and send the data to the callback if different.
225226
if (err === null) {
226-
if (JSON.stringify(this.data) !== JSON.stringify(context.data)) {
227+
if (JSON.stringify(this.data) !== JSON.stringify(context.data) || includeMetadataChanges) {
227228
onNext(new DocumentSnapshot(self.id, self.ref, self._getData()));
228229
context.data = this._getData();
229230
}

src/firestore-query.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,9 @@ MockFirestoreQuery.prototype.onSnapshot = function (optionsOrObserverOrOnNext, o
148148
var self = this;
149149
var onNext = optionsOrObserverOrOnNext;
150150
var onError = observerOrOnNextOrOnError;
151+
var includeMetadataChanges = optionsOrObserverOrOnNext.includeMetadataChanges;
151152

152-
if (_.has(optionsOrObserverOrOnNext, 'includeMetadataChanges')) {
153+
if (includeMetadataChanges) {
153154
// Note this doesn't truly mimic the firestore metadata changes behavior, however
154155
// since everything is syncronous, there isn't any difference in behavior.
155156
onNext = observerOrOnNextOrOnError;
@@ -164,7 +165,7 @@ MockFirestoreQuery.prototype.onSnapshot = function (optionsOrObserverOrOnNext, o
164165
if (err === null) {
165166
this.get().then(function (querySnapshot) {
166167
var results = self._results();
167-
if (JSON.stringify(results) !== JSON.stringify(context.data)) {
168+
if (JSON.stringify(results) !== JSON.stringify(context.data) || includeMetadataChanges) {
168169
onNext(new QuerySnapshot(self.parent === null ? self : self.parent.collection(self.id), results));
169170
// onNext(new QuerySnapshot(self.id, self.ref, results));
170171
context.data = results;

0 commit comments

Comments
 (0)