Vuefire: Add a callback when data is ready

Created on 1 Feb 2017  Â·  18Comments  Â·  Source: vuejs/vuefire

Most helpful comment

@shershen08 thanks for the input
@posva yes sure, my question was about vuefire

My strategy is very similar to what @shershen08 posted:

mounted: function () { firebase.database().ref('events/2017-02-sorrento/users/').once('value', snapshot => { this.loading = false }) }

In the component I have a v-if to show/hide the spinner:

<div v-if="loading" class="spinner">...</div>

It'd be neat to do it within vuefire

All 18 comments

The referenced SO post is truely helpfull.
However I could not get new Firebase() with only including
https://gstatic.com/firebasejs/3.5.2/firebase.js for Vuefire.

new Firebase() is the syntax for the legacy SDKs. You should use firebase.initializeApp() instead. See Add Firebase to your app for more information.

Is this a necessary feature to show a spinning wheel (Loading...) while waiting for data? I cannot find a way to do that within vuefire.

@ruvido agree, that could simplify that common case usage.
the solution I took from that stackoverflow post and used looks like this:

//firebase for Vue init
var firebaseApp = firebase.initializeApp(config);
var db = firebaseApp.database();

//..

//firebase loaded callback
db.ref('products').once('value', function() {
  //e.g. some other non-Vue but related to data utils can run here
  extractItemsArray(__app__.products);
  //hide DOM element with preloader 
  $('.preloader').hide();
});


@ruvido It's not necessary because as @shershen08 said you can do it yourself. It could however improve the API a bit 🙂

@shershen08 thanks for the input
@posva yes sure, my question was about vuefire

My strategy is very similar to what @shershen08 posted:

mounted: function () { firebase.database().ref('events/2017-02-sorrento/users/').once('value', snapshot => { this.loading = false }) }

In the component I have a v-if to show/hide the spinner:

<div v-if="loading" class="spinner">...</div>

It'd be neat to do it within vuefire

before releasing this I'm making sure this allows SSR

Any progress in this?

I'm binding an array of data like this:

// ...
firebase: {
  list: database.ref('list')
}
// ...

How can I get the readyCallback() method to know all the data has been fetch from Firebase si I can unhide a progress spinner?

Thank you.

This should work:

firebase () {
    return {
        list: {
            source: database.ref('list'),
            readyCallback: () => this.loading = false
        }
    }
}

Thanks for your quick response. Unfortunately, it gives me the following error:

image

firebase () {
  return {
    list: database.ref('list', { readyCallback: () => { this.loading = false } })
  }
},

oh, lol what am I saying. You need to use the object syntax. Updated my comment. It's all in the Readme: https://github.com/vuejs/vuefire#usage

Works like a charm. Thank you.

readyCallback 🤯 thx

Hi @posva

Is there functionality like this for the lerna branch?

I tried something similar:

data() {
  return {
    bands: [],
  }
},

firestore() {
  return {
    bands: {
      source: db.collection('bands'),
      readyCallback() {
        this.loading = false
      },
    },
  }
},

But that throws an error:

Uncaught (in promise) TypeError: document.onSnapshot is not a function

in the new version, bind is a promise, so you wait for the promise :)

Not quite sure I follow. Where would I set the loading variable to false?

firestore() {
  // here? this.loading = false
  return {
    bands: db.collection('bands'),
  }
},

This has actually been answered in many issues already. Could you look them
up please? 😛
On Fri 16 Nov 2018 at 11:33, Cornelius notifications@github.com wrote:

Not quite sure I follow. Where would I set the loading variable to false?

firestore() {
// here? this.loading = false
return {
bands: db.collection('bands'),
}
},

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/vuejs/vuefire/issues/69#issuecomment-439449765, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAoicV4TjGmJBa-4oKe0WuC3GzJ3fihFks5uvujWgaJpZM4LzTmj
.

>

Eduardo San Martin Morote

For solution using $bind see: https://github.com/vuejs/vuefire/issues/157#issuecomment-380266815

Sorry for the hassle...

Was this page helpful?
0 / 5 - 0 ratings

Related issues

torfeld6 picture torfeld6  Â·  4Comments

dev-kr2020 picture dev-kr2020  Â·  4Comments

JFGHT picture JFGHT  Â·  5Comments

KMolendijk picture KMolendijk  Â·  3Comments

cairinmichie picture cairinmichie  Â·  6Comments