Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FR: Method to combine two firestore WriteBatch #2004

Open
SamyPesse opened this issue Jul 17, 2019 · 1 comment
Open

FR: Method to combine two firestore WriteBatch #2004

SamyPesse opened this issue Jul 17, 2019 · 1 comment

Comments

@SamyPesse
Copy link
Contributor

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).

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();
}
@SamyPesse SamyPesse changed the title FR: Combine two firestore WriteBatch FR: Method to combine two firestore WriteBatch Jul 17, 2019
@schmidt-sebastian
Copy link
Contributor

schmidt-sebastian commented Jul 31, 2019

@SamyPesse Thanks for filing this issue. We currently don't expose this functionality, and we will discuss internally if this is something that we should add to our API. For now, you can achieve the desired result by passing an already instantiated WriteBatch to starBlogArticle and createBlogArticle.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants