[Question]: WriteBatch and Transaction method return types
I'm working on an internal code library and I have some code that is only concerned with set(), update() and delete() methods of WriteBatch and Transaction. I notice the only thing that differs between the methods is the return type. Transaction return type is :this and WriteBatch is :WriteBatch
For example the set()'s:
- https://github.com/firebase/firebase-js-sdk/blob/master/packages/firestore/src/lite-api/transaction.ts#L130
- https://github.com/firebase/firebase-js-sdk/blob/master/packages/firestore/src/lite-api/write_batch.ts#L76
I wondered if it would be a possibility for them to all use the :this return type? I'd like to be able to use the 2 types interchangeably based on an interface of only those few methods. Thank you for your time.
I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
Hi smakinson, in order to further support this feature request, could you please share some of the use cases?
I have various class types created via the firestore converters that manage the data and determine whats what. They could work with batches, or transactions but the user of the class would be the one to decide which it is and the class would just use set, update or delete. I thought I'd ask if the return types might be able to match so the interface on those methods could be setup by referencing the methods with a typescript utility, or perhaps it would be useful for the firestore library to provide the interface. I'm thinking that there is no harm in changing the return type to this on the WriteBatch methods, if not I'll look at wrapping them.
Hi smakinson,
Thank you for your suggestion. Currently we don't support using the syntax of WriteBatch and Transaction interchangeably. I file the internal tracking ticket b/239950484 in order for the team to consider it in the future.
ok, thanks!
The feature request is tracked internally, so I will close this github ticket. Developer will be notified when feature is implemented.
Hi,
The team decided to keep the ticket open until the feature is implemented or bug is fixed for external visibility.