firebase / firebase/firebase-js-sdk
FR: Method to combine two firestore WriteBatch
- Dominant language
- TypeScript
- Stars
- 5.1k
- Forks
- 1k
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 37
Description
It'd be great if `firestore.WriteBatch` had a `merge(batch: firebase.firestore.WriteBatch)` method.
The goal is to have utility methods that can return a batch. Before committing, those batches could be merged together.
(It looks like a basic implementation will be to concat the `batch. _mutations`).
```ts
function starBlogArticle(articleId: string): firebase.firestore.WriteBatch {
const batch = firebase.firestore().batch();
batch.set(...); // Some changes
batch.update(...);
return batch;
}
function createBlogArticle(articleId: string, title: string): firebase.firestore.WriteBatch {
const batch = firebase.firestore().batch();
batch.set(...);
batch.set(...);
return batch;
}
...
// On the application side
const onClickCreate = () => {
const articleId = '...';
const batch = createBlogArticle(articleId, title);
batch.merge(starBlogArticle(articleId));
batch.commit();
}
```
Contributor guide
Assessment
This issue has not been assessed yet.