Skip to content

Commit

Permalink
Add more debug logging to collections
Browse files Browse the repository at this point in the history
  • Loading branch information
0x80 committed Jul 21, 2019
1 parent f698e7e commit 69f221b
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ interface Options {

type QueryFunction = (ref: firestore.CollectionReference) => firestore.Query;

// function isCollectionReference(
// source: firestore.CollectionReference | firestore.Query
// ): source is firestore.CollectionReference {
// return (source as firestore.CollectionReference).id !== undefined;
// }

export class ObservableCollection<T extends object> {
@observable private docsObservable: IObservableArray<Document<T>>;
@observable private isLoadingObservable: IObservableValue<boolean>;
Expand All @@ -35,6 +41,11 @@ export class ObservableCollection<T extends object> {
queryFn?: QueryFunction,
options?: Options
) {
/**
* I wish it was possible to extract the ref from a Query object, because
* then we could make a single source parameter
* firestore.CollectionReference | firestore.Query
*/
this._ref = ref;
this._path = ref.path;

Expand All @@ -47,6 +58,8 @@ export class ObservableCollection<T extends object> {
this.isDebugEnabled = options.debug || false;
}

this.logDebug("Constructor");

this.docsObservable = observable.array([]);
this.isLoadingObservable = observable.box(false);

Expand Down Expand Up @@ -118,7 +131,7 @@ export class ObservableCollection<T extends object> {
}

private handleSnapshot(snapshot: firestore.QuerySnapshot) {
this.logDebug("handleSnapshot");
this.logDebug(`handleSnapshot, docs.length: ${snapshot.docs.length}`);

runInAction(() => {
this.docsObservable.replace(
Expand Down

0 comments on commit 69f221b

Please sign in to comment.