Skip to content

Commit

Permalink
Some copy/paste related fixes:
Browse files Browse the repository at this point in the history
* In firestore compat `doc` function, client variant: if doc path is not provided (we wish a new server-assigned id), pass only the parent node (to prevent empty path crashes)
* In firestore compat `batch` function, bind `this` to returned `commit` methods (for both client and server variant)
  • Loading branch information
ikusteu committed Sep 10, 2023
1 parent c97ab23 commit 4a12a2d
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions packages/client/src/utils/firestore/compat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,14 @@ export const doc = (
return match(node, {
[FirestoreEnv.Client]: ({ instance }) =>
FirestoreDocVariant.client({
// Even though 'doc' (aliased as 'clientDoc' here) works on both firestore and collection instanceerences,
// Even though 'doc' (aliased as 'clientDoc' here) works on both firestore and collection references,
// it doesn't work well on unions because of slightly different type overloads, hence the typecast.
instance: clientDoc(
instance as ClientFirestore,
pathSegments.join("/")
),
instance: docPath.length
? clientDoc(
instance as ClientCollectionReference,
docPath.length ? docPath : undefined
)
: clientDoc(instance as ClientCollectionReference),
}),
[FirestoreEnv.Server]: ({ instance }) =>
FirestoreDocVariant.server({
Expand Down Expand Up @@ -235,7 +237,7 @@ export const writeBatch = (db: FirestoreVariant) =>
}
return batch.set(doc.instance, data);
},
commit: batch.commit,
commit: batch.commit.bind(batch),
};
},
[FirestoreEnv.Server]: ({ instance }) => {
Expand All @@ -248,7 +250,7 @@ export const writeBatch = (db: FirestoreVariant) =>
}
return batch.set(doc.instance, data);
},
commit: batch.commit,
commit: batch.commit.bind(batch),
};
},
});
Expand Down

0 comments on commit 4a12a2d

Please sign in to comment.