Skip to content

Commit

Permalink
Log errors to console if no handler is available
Browse files Browse the repository at this point in the history
  • Loading branch information
0x80 committed Dec 15, 2022
1 parent 0780b61 commit e792ca2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
15 changes: 0 additions & 15 deletions src/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,21 +318,6 @@ export class ObservableCollection<T extends DocumentData> {
`handleSnapshot, ${Date.now()} docs.length: ${snapshot.docs.length}`,
);

/**
* @TODO keep local cache of each document and only update data based on the
* docChanges
*/
// snapshot.docChanges().forEach(function(change) { if (change.type ===
// "added") { console.log("New: ", change.doc.data());
// }
// if (change.type === "modified") { console.log("Modified: ",
// change.doc.data());
// }
// if (change.type === "removed") { console.log("Removed: ",
// change.doc.data());
// }
// });

runInAction(() => {
this._documents = snapshot.docs.map(
(doc) =>
Expand Down
15 changes: 15 additions & 0 deletions src/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ export class ObservableDocument<T extends DocumentData> {
if (typeof this.onErrorCallback === "function") {
this.onErrorCallback(err);
} else {
this.logError(err);
throw err;
}
}
Expand Down Expand Up @@ -350,6 +351,20 @@ export class ObservableDocument<T extends DocumentData> {
}
}

private logError(err: unknown) {
if (!this.documentRef) {
console.error(
`${this.debugId} (${getPathFromCollectionRef(
this.collectionRef,
)}): ${getErrorMessage(err)}`,
);
} else {
console.error(
`${this.debugId} (${this.documentRef.path}): ${getErrorMessage(err)}`,
);
}
}

private updateListeners(shouldListen: boolean) {
const isListening = !!this.onSnapshotUnsubscribeFn;

Expand Down

0 comments on commit e792ca2

Please sign in to comment.