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

Support of $bind with nested key path #404

Closed
andrewspy opened this issue Sep 25, 2019 · 5 comments
Closed

Support of $bind with nested key path #404

andrewspy opened this issue Sep 25, 2019 · 5 comments

Comments

@andrewspy
Copy link

andrewspy commented Sep 25, 2019

I intend to $bind a collection of documents under docs by id. It seems to work, and wonder if it is supported officially.

const documents = db.collection('documents')

export default {
  props: ['documentId'],
  data: () => ({ docs: { }}),
},
  watch: {
    documentId(id) {
      // $bind automatically unbinds the previously bound property
      this.$bind(`docs.${id}`, documents.doc(id))
    },
  },
}
@posva
Copy link
Member

posva commented Sep 26, 2019

It's not completely supported yet. BTW you should declare id inside docs

Duplicate of #152

@posva posva closed this as completed Sep 26, 2019
@andrewspy
Copy link
Author

@posva Actually I intend to have dynamic id, instead of a static one, as I need to listen to changes in dynamic id (such as a list of saved stock symbol).

I've also seen #152, and though it refers to firebaseRTDB, while I'm referring to firestore.

I would also like to know if there is any workaround for dynamic $bind() of keys. Thanks!

@posva
Copy link
Member

posva commented Sep 26, 2019

#152 is for both

For dynamic keys, you should sett them with Vue.set before binding

@andrewspy
Copy link
Author

@posva Thanks for the pointer, I manage to get it working with:

const documents = db.collection('documents')

export default {
  props: ['documentId'],
  data: () => ({ docs: { }}),
},
  watch: {
    documentId(id) {
      // $set manually for reactivity to work
      this.$set(this.docs, id, null)
      this.$bind(`docs.${id}`, documents.doc(id))
    },
  },
}

I noticed that when binding this way, $bind always return undefined instead of Promise<Object> as per documentation.

I would also propose having a topic on "Dynamic binding with Vue.set" in the documentation as this is common use-case.

@posva
Copy link
Member

posva commented Sep 27, 2019

Added to the roadmap #145 🙂

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