Skip to content

Updating firebase query #82

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

Closed
alekbarszczewski opened this issue Feb 26, 2017 · 1 comment
Closed

Updating firebase query #82

alekbarszczewski opened this issue Feb 26, 2017 · 1 comment

Comments

@alekbarszczewski
Copy link

In my vue component I have this:

{
  firebase () {
    return {
      routes: Firebase.database().ref(`items/${this.$store.state.user.uid}`).orderByChild('when').limitToLast(5),
    };
  },
}

Now I would like to dynamically update this query to either increase limit or change ordering field.
Here is what I tried:

  1. Make firebase () func in component to depend on some data param:
{
  data: { limit: 5 },
  methods: {
    loadMore () { this.limit = 10; },
  }, 
  firebase () {
    return {
      items: Firebase.database().ref(`items/${this.$store.state.user.uid}`).orderByChild('when').limitToLast(this.limit),
    };
  },
}

It does not work, firebase() is no called on data.limit change.

  1. Update query using $firebaseRefs
{
  methods: {
    loadMore () { this.$firebaseRefs.items.limitToLast(10); },
  }, 
  firebase () {
    return {
      items: Firebase.database().ref(`items/${this.$store.state.user.uid}`).orderByChild('when').limitToLast(5),
    };
  },
}

It has no effect...

  1. Update whole firebase binding dynamically
{
  methods: {
    loadMore () {
      this.$bindAsArray('items', Firebase.database().ref(`items/${this.$store.state.user.uid}`).orderByChild('when').limitToLast(10));
    },
  }, 
  firebase () {
    return {
      items: Firebase.database().ref(`items/${this.$store.state.user.uid}`).orderByChild('when').limitToLast(5),
    };
  },
}

It works, but for a moment "items" is empty array and then loads with updated limit. I would like to avoid such "blink" and just display loader on top of current items (5) and just append new items added by changing limit to (10).

Any idea how I can do this?

@posva
Copy link
Member

posva commented Feb 26, 2017

I see. This is, unfortunately, necessary because when an array is bound, the current variable has to be set to an empty array so it is populated progressively. However, I think I could make it so binding over an existing reference, waits for it to be populated before taking into account the other firebase events responsible for adding children. I'll create a cleaned up issue to track the feature

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

2 participants