Building a Firebase CRUD Service for Angular
Anyone who knows me, knows I ππ Firebase. It could be considered unhealthy π. Despite my love for it, I have had my fair share of disagreements with it. The biggest one that comes to mind relates to Firestore.
NOTE: This article assumes you have a basic knowledge of how Firestore works. (docs)
This article will contain:
- π€ The Problem β Something that annoyed me
- πͺ My Solution β A brief overview
- π€© LETβS BUILD! β Party time! ππ
π€ The Problem
I tend to use Firestore as my go to NoSQL store. But when we pair it with AngularFire the examples shown are at times not perfect, especially when we try to adhere to the DRY Principle.
The examples all tend to start with your call to the collection
method in your Component
to ensure you are working with the correct collection in Firestore. But all these calls to collection
add up. There must be a better way?
πͺ My Solution
To me, there is! But, this is subjective. I create a Generic Firebase CRUD Service*, that accepts a Type to define the model that I want to store in my Collection on Firestore.