FirebaseExtended / angularfire

AngularJS bindings for Firebase
MIT License
2.73k stars 632 forks source link

Firestore Support #956

Closed HormCodes closed 4 years ago

HormCodes commented 7 years ago

Are you planning add support for new Firebase feature called Firestore? I've looked at AngularFire2 and it has. What about AngularFire1?

johnmorrellif commented 7 years ago

+1 An official release with firestore support would be great!

In the mean time I was able to copy and modify the $firebaseObject factory to create a $firestoreObject factory that seems to work for what I need (just display data from Firestore that updates as the DB updates - mostly just the $loaded() and $destroy() methods)

DISCLAIMERS

The changes I made to the $firebaseObject factory were as follows (Version 2.3.0 of Angular Fire):

Line 1215 - Firestore refs now have the key renamed to id and moved up a level Old: this.$id = ref.ref.key; New: this.$id = ref.id;

Line 1380 - I had to duplicate one function in $firebaseUtils in order to handle the new data structure introduced by Firestore Old: var changed = $firebaseUtils.updateRec(this, snap); New: var changed = $firebaseUtils.updateFirestoreRec(this, snap);

Line 1590 - Destroying Listeners changed in Firestore - https://firebase.google.com/docs/firestore/query-data/listen#detach_a_listener Old: ref.off('value', applyUpdate); New: var unsubscribe = firestoreObject.$$conf.ref.onSnapshot(applyUpdate); unsubscribe();

Line 1597 - changed on() to onSnapshot() Old: ref.on('value', applyUpdate, error); New: ref.onSnapshot(applyUpdate, error);

Lines 1598 - changed once() to get() Old: ref.once('value', function(snap) { New: ref.get().then(function(snap) { (I also killed the isArray error message from 1599-1601 since I didn't want to figure out how to check that in Firestore / it may not be relevant with strict docs and collections now)

The changes I made to the $firebaseUtils factory were as follows (Version 2.3.0 of Angular Fire):

Line 2296 - duplicated updateRec() to create updateFirestoreRec() I made a copy of the updateRec() function, naming it updateFirestoreRec() since the way we are going to handle the Firestore data is different.

Line 2297 - Handle data for both Firestore collections and documents in the new updateFirestoreRec() function Old: var data = snap.val(); New:var data = {}; if (typeof snap.forEach == 'function') { snap.forEach(function(doc) { data[doc.id] = doc.data(); }); } else{ data = snap.data(); }

Hopefully I didn't miss anything here. Basically there are a couple of places where on, once, and off functions need to be swapped out and then a couple of places where the data format is slightly different for Firestore than it was for Realtime Database.

johnmorrellif commented 7 years ago

Just found an issue with my change on Line 2297. Just need to add a conditional to make sure that there is actually data in Firestore to set to the data variable.

var data = {};
if (typeof  snap.forEach == 'function') {
  snap.forEach(function(doc) {
    if(doc != null){
      data[doc.id] = doc.data();
    }
  });
} else{
  if(snap.exists){
    data = snap.data();
  }
}
cianochannel commented 7 years ago

I too am really interested in using firestore on angularjs. I have a new urgent project to implement and I do not have the time to learn Angular 2. If you have news please let me know. Thanks so much

knvpk commented 6 years ago

I need to add firebase to my app which is already written in the angularjs.

wwrrss commented 6 years ago

@pavankumarkatakam you could use firestore with angularjs using the javascript lib, I developed a little project that way

cianochannel commented 6 years ago

@wwrrss Can you give us some code? Thank's

waxxxd commented 6 years ago

I would love support for firestore in this project. For everyone else needing a quick fix, here are the docs to firestore (Docs) showing exactly how to use standard javascript to access it.

You will need to do quite a bit of legwork yourself. Good Luck

samtstern commented 6 years ago

@jamesdaniels can you confirm that there are no plans to bring Firestore to this library? This issue has a lot of comments/reactions and I'd like to set the record straight.