firebase-js-sdk icon indicating copy to clipboard operation
firebase-js-sdk copied to clipboard

[Question]: WriteBatch and Transaction method return types

Open smakinson opened this issue 3 years ago • 7 comments

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.

smakinson avatar Jul 14 '22 19:07 smakinson

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

google-oss-bot avatar Jul 14 '22 19:07 google-oss-bot

Hi smakinson, in order to further support this feature request, could you please share some of the use cases?

cherylEnkidu avatar Jul 18 '22 14:07 cherylEnkidu

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.

smakinson avatar Jul 20 '22 00:07 smakinson

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.

cherylEnkidu avatar Jul 22 '22 17:07 cherylEnkidu

ok, thanks!

smakinson avatar Jul 22 '22 17:07 smakinson

The feature request is tracked internally, so I will close this github ticket. Developer will be notified when feature is implemented.

cherylEnkidu avatar Dec 20 '23 21:12 cherylEnkidu

Hi,

The team decided to keep the ticket open until the feature is implemented or bug is fixed for external visibility.

cherylEnkidu avatar Jan 16 '24 22:01 cherylEnkidu