Skip to content
This repository has been archived by the owner on Apr 19, 2019. It is now read-only.

$bindAsArray Throws Vuex Outside Store Mutation Error #54

Closed
19r3ka opened this issue Apr 4, 2017 · 1 comment
Closed

$bindAsArray Throws Vuex Outside Store Mutation Error #54

19r3ka opened this issue Apr 4, 2017 · 1 comment

Comments

@19r3ka
Copy link

19r3ka commented Apr 4, 2017

Hi all,

I am pretty sure I am the only one with this issue. I posted on StackOverflow but the system would not let me tag it properly with 'VuexFire'.

Here is my main.js where I declare the main VueJS app and its main components:

export default new Vue({
  el: '#app',

  // Binds app with Firebase servers as to always have the       currentUser
  beforeCreate () {
    auth()
      .onAuthStateChanged(user => {
        if (user) {
          // save the new user
          this.currentUser = user

          // get the required references to the Firebase database
          const currentUserRef = database().ref(`users/${user.uid}`)
          const claimsRef = database().ref(`claims/${user.uid}/`)

          // do the actual bindings from firebase to the vuex store
          this.$bindAsObject('users.currentUser', currentUserRef)
          this.$bindAsArray('claims.items', claimsRef) // <-- Here is the problem apparently

          // Make the binding references available on the root module
          this.currentUserRef = currentUserRef
          this.claimsRef = claimsRef
        } else {
          auth()
            .signInAnonymously()
            .catch(this.$handleError)
        }
      }).bind(this)
  },

  data: {
    claimsRef: null,
    currentUserRef: {},
    currentUser: null
  },

  render: h => h(App),

  router, // defines the main routing system in the app

  store // inject vuex into all components as this.$store
})

Binding as an Object is totally fine (no errors). But binding as an Array throws the following error:

VuexFire Error

Also, for reference, here is my corresponding Vuex module definition:

import { mutations as vuexMutations } from 'vuexfire'

const state = {
  items: null
}

const getters = {
  claims: ({ items }) => items
}

// Needed for VuexFire to automutate the bound claims items
const mutations = vuexMutations

export default {
  namespaced: true,
  mutations,
  state
}
@posva
Copy link
Owner

posva commented Apr 5, 2017

Hello, yeah, v1 didn't support strict mode. See #30 for more. There's a PR at #34 but it wasn't working yet. It should be easy to do but now that there's the v2 I won't do it myself, contributions are welcome to the v1 branch though 🙂

@posva posva closed this as completed Apr 5, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants