mikkopaderes / ember-firebase-service

Exposes a service that's a direct representation of Firebase
MIT License
4 stars 2 forks source link

Add support for Firebase v9 #49

Open mikkopaderes opened 3 years ago

mikkopaderes commented 3 years ago

This is an ongoing R&D project to see what works and what doesn't. The ideal goal is to be able to support both Firebase 9 modular and compat versions.

One thing to also check out is Firebase has removed the window.firebase browser global in their modular SDK. This should mean that when using the modular SDK, we no longer need to shim Firebase in order for it to work on both browser and Node (FastBoot) as well as no longer needing to make changes to the ember-cli-build.js.

But these are all just theories and is something that I have to see for myself first...

mikkopaderes commented 3 years ago

The modular SDK introduces a new way to access Firebase products, like getFirestore, getAuth, etc. Because of this, it's starting to make more sense that this addon will no longer expose a service but instead is just an initializer for the Firebase app. Using modular SDK should now look like this:

import Controller from '@ember/controller';

import { addDoc, collection, getFirestore } from 'firebase/firestore';

export default class Application extends Controller {
  createTestRecord() {
    const db = getFirestore();

    addDoc(collection(db, 'users'), { ... });
  }
}

As you can see, the service is no longer necessary.

In fact, you can even argue that every app can just initialize Firebase themselves as it's very trivial. Also, even before, the service doesn't seem too useful in my opinion, because doing this gives you a similar result:

import Controller from '@ember/controller';

import firebase from 'firebase/app';

export default class Application extends Controller {
  createTestRecord() {
    const db = firebase.app().firestore();

    db.collection('users').add({ ... });
  }
}

What was very useful for this addon was creating a shim for users where doing import firebase from 'firebase/app' would work for both browser and Node (FastBoot) environments. But now that Firebase 9 modular SDK can run on both environments, I'm starting to feel that this addon is losing its purpose moving forward.

The scenario I'm thinking of for this addon is it will reach end of life by Firebase 10 (when compat SDK is dropped). Until then, I might just release another version that will add support for the compat SDK with the shim advantage.

This decision isn't final, but I'm starting to lean towards it unless I find a good reason not to.