firebase / firebase/firebase-js-sdk

FR: Method to combine two firestore WriteBatch

Open
#2,004 1 comment 3 reactions 0 assignees View on GitHub
api: firestore feature request
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.