Maximize Firebase v9 bundle Efficiency with a Dot Pattern Helper Class in TypeScript #7490
MuhammadFaizan19
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Since the release of firebase v9, the bundle size of the client has reduced substantially since now the functions that are used are the only ones being imported and bundled.
But this modularity comes with its own trade offs. The code becomes cluttered if its complex and is utlizing more firebase functions. In order to tackle this issue, a helper class is created in typescript that is type safe and provides a much cleaner and readable way of utilizing firebase functions.
For now, we will only be dealing with firestore.
lets first import the functions that will be used in this custom firestore class and intialize the firebase app and firestore database.
The previous firestore implementation had two parts from a high level perspective i.e. Collections and Documents. Create a custom class for both but before we do that, lets start by defining what the interfaces will look like for type safety.
Now that the interfaces have been defined, In order for us to use generics in typescript, we need Collections and SubCollections interface to represent types in a single interface.
Now that the Collection and Document classes have been created, we can create a custom store class
Example usage
Beta Was this translation helpful? Give feedback.
All reactions