Firestore: DocumentReference/CollectionReference are sealed classes
See original GitHub issueIs 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:
- Created 6 years ago
- Comments:5
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Great! Closing now.
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.