Thanks to visit codestin.com
Credit goes to github.com

Skip to content

firestoreBind creates a value property #1123

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
wujekbogdan opened this issue Jun 30, 2021 · 2 comments
Closed

firestoreBind creates a value property #1123

wujekbogdan opened this issue Jun 30, 2021 · 2 comments

Comments

@wujekbogdan
Copy link
Contributor

Reproduction

import Firebase from 'firebase';
import { firestoreBind } from 'vuefire';
import { defineStore } from 'pinia'

defineStore({
  id: 'user',

  state: () => ({
    user: {},
  }),

  getters: {
    userProfile(state) {
      console.log(state.user);
      /** Logs:
       *
       * {
       *   value: {
       *     // user data
       *   }
       * }
       *
       */

      /** Expected:
       *
       * {
       *   // user data
       * }
       *
       */

      return this.state.user;
    },
  },

  actions: {
    init(userId) {
      const userDocRef = Firebase.firestore().collection('users').doc(userId)
      return firestoreBind(this.user, userDocRef);
    },
  },
});

Steps to reproduce the behavior

  1. Use firestoreBind() to bind a document to a store property.
  2. The document is bound as expected

Expected behavior

The document should be bound directly to the property passed as a first parameter of the firestoreBind function

Actual behavior

A new value property is created under the property to which the document was bound.

Additional information

I'm not 100% sure if this is a bug. I thought that state is already a reactive object so there's no need to create nested reactive refs when binding Firestore documents, but I suppose that firestoreBind() is not able to recognize that this is already a reactive object so it creates a new ref under this.user. Am I right?

Or maybe I'm just not using it properly with Pinia?

@wujekbogdan wujekbogdan changed the title firestoreBind creates a value property firestoreBind creates a value property Jun 30, 2021
@posva
Copy link
Member

posva commented Jun 30, 2021

You need to do firestoreBind(toRef(this.$state, 'user'), userDocRef)

@wujekbogdan
Copy link
Contributor Author

Thanks! So we can close this ticket - it's clearly not a bug.

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