Firebase and RxJS for all frameworks.
What is RxFire?
- Observable creators - Observables bindings for most Firebase web libraries.
- Portable - Use across any framework or no framework at all.
- Tree shake-able - Import only what you need. Shake the rest out with your favorite module bundler like Webpack or Rollup.
- Combine multiple data sources - Need to join two Firestore references? Want to combine an image from Cloud Storage with a Firestore document? Super easy with observables and operators.
- Simplify code-splitting of Firebase - Using RxFire with Webpack makes it easy to load Firebase features on-demand.
# npmnpm i rxfire firebase rxjs --save# yarnyarn add rxfire firebase rxjs
Make sure to install Firebase and RxJS individually as they are peer dependencies of RxFire.
;;;;;;citiesRef.where'state', '==', 'CO';collectionDatacitiesRef, 'id'.pipetapconsole.log'This is just an observable!'.subscribe
Easily combine multiple Firebase data sources
RxJS provides multiple operators and creation methods for combining observable streams. This makes it easy to combine data from multiple Firebase resources. You can also handle simplify high asynchronous tasks like joins into a flat stream.
The example below streams a list of "cities" from Firestore and then retrieves their image from a Cloud Storage bucket. Both tasks are asynchronous but RxJS makes it easy to combine these tasks together.
;;;;;;;;citiesRef.where'state', '==', 'CO';collectionDatacitiesRef, 'id'.pipeswitchMap.subscribe;
Understanding RxFire imports
RxFire is a complementary library to Firebase. It is not meant to wrap the entire Firebase SDK. RxFire's purpose is to simplify async streams from Firebase. You need to import the Firebase SDK and initialize an app before using RxFire.
;; // import only the features needed;;;// Now you can use RxFire!;
RxFire contains multiple entry points for module imports. Each Firebase library is an entry point.
RxFire is a set of functions. Most functions create observables and from there you can use regular RxJS operators. Some functions are custom operators. But at the end of the day, it's all just functions. This is important for tree shaking. Any unused functions are stripped from your final build if you use a module bundler like Webpack or Rollup.
Examples: See this example repository for a list of ways to configure and use RxFire.