question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Firestore: DocumentReference/CollectionReference are sealed classes

See original GitHub issue

Is there any special reason to make DocumentReference and CollectionReference sealed classes? It seems unreasonable to have such restriction. It makes very difficult to extend the functionalities of the API.

For example, instead of calling db.Collection("users").Document("id").Collection("purchases").Document("id"), I could get rid of the magic strings and call something like db.UsersCollection.UserDocument("id").PurchasesCollection.PurchaseDocument("id"). That would be possible by creating custom collections and documents references by deriving DocumentReference/CollectionReference.

Custom references would provide many useful features, such as:

  • Declare your entire database structure in code
  • Retrieve specific references without using magic strings
  • Create reusable queries/procedures by using extension methods
  • Improve the overall code readability, maintainability and scalability

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
jskeetcommented, Nov 28, 2017

Great! Closing now.

0reactions
pauloevprcommented, Nov 28, 2017

I think my previous comment did miss your point regarding the aspect of immutability. I apologize for that. Now that you brought reliability up, it seems very reasonable that these two classes are sealed.

My real concern is not regarding these two classes in particular, it is actually about making the API flexible so that the community can help to improve it by developing extension libraries. It seems you are already seriously taking this into consideration when developing the API. That is awesome!

This whole idea of making references more easy to access is not a particular use case of mine. I am actually wanting to develop a tool to help developers to materialize their Firestore database structure into code. The tool would basically auto generate helper classes and methods for references based on the provided database structure.

As far as I concern, this issue is completely resolved. Thank you very much for your time.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Firestore API - Class CollectionReference (3.3.0)
Creates a DocumentReference for a direct child document of this collection with a random ID. This performs no server-side operations; it only ...
Read more >
CollectionReference | Firebase - Google
A CollectionReference can be used for adding documents, getting document references, and querying for documents (using the methods inherited from Query ).
Read more >
Firebase Cloud Firestore: Sealed classes in custom objects ...
1 Answer 1 ... You won't be able to use a sealed class with toObject() . That's because sealed classes themselves don't have...
Read more >
DocumentReference class - cloud_firestore library - Dart API
A DocumentReference refers to a document location in a FirebaseFirestore database and can be used to write, read, or listen to the location....
Read more >
CollectionReference.cs
</summary> public sealed class CollectionReference : Query, IEquatable<CollectionReference>, IComparable<CollectionReference> { /// <summary> /// The final ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found