Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Firestore Support #956

Closed
HormCodes opened this issue Oct 5, 2017 · 9 comments
Closed

Firestore Support #956

HormCodes opened this issue Oct 5, 2017 · 9 comments

Comments

@HormCodes
Copy link

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

@johnmorrellif
Copy link

johnmorrellif commented Oct 12, 2017

+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

  • I haven't taken the time to figure out how to port over the $firebaseArray factory to create a $firestoreArray factory yet (and may not need to for my current project)
  • I removed the $save and $remove functions from $firestoreObject since I don't think that they are tremendously useful and I didn't want to take the time to update the associated $firebaseUtil functions needed to make them work
  • I haven't done a ton of testing on this so it probably has some problems (not super familiar with Firestore yet) but maybe it will help one of the legit angularfire contributors get an official update out there.

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
Copy link

johnmorrellif commented Oct 13, 2017

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
Copy link

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
Copy link

knvpk commented Jan 5, 2018

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

@wwrrss
Copy link

wwrrss commented Jan 5, 2018

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

@cianochannel
Copy link

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

@waxxxd
Copy link

waxxxd commented Jan 14, 2018

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
Copy link
Contributor

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants