davestewart / vuex-pathify

Vue / Vuex plugin providing a unified path syntax to Vuex stores
https://davestewart.github.io/vuex-pathify
MIT License
1.37k stars 57 forks source link

How to add pathify on the fly #83

Closed BobbyBorisov closed 5 years ago

BobbyBorisov commented 5 years ago

Hi, first of all thanks for the awesome plugin!

I am trying to use it with Laravel Nova(don't know if you heard of it, basically its a SPA admin panel written in vue). and my issue is the following. I want to use pathify but could not get it to work. One caveat is that i already have a store as you can see and i am trying to register module and pathify plugin

import Vuex from "vuex"
import pathify from "vuex-pathify"

Nova.booting((Vue, router, store) => {
    Vue.use(Vuex);

    const state = {
        count: 2
    };

    let anotherStore = {
        state
    }
    store.registerModule('custom-module', anotherStore);
    pathify.plugin(store);
})

//and later in some other vue
data() {
        return {
            count: get('custom-module/count'),
        }
}

Somehow its not working and where i output count it says

function () { var args = [], len = arguments.length; while ( len-- ) args[ len ] = arguments[ len ]; if (!this.$store) { throw new Error('[Vuex Pathify] Unexpected condition: this.$store is undefined.\n\nThis is a known edge case with some setups and will cause future lookups to fail') } if (!getter || store !== this.$store) { store = this.$store; getter = makeGetter(store, path, stateOnly); } return getter.call.apply(getter, [ this ].concat( args )) }
Save as new

Thanks in advance!

davestewart commented 5 years ago

Hey Bobby,

Hmm. This is probably going to be difficult to debug because it's a separate platform.

What is this line attempting to do?

pathify.plugin(store);
davestewart commented 5 years ago

Actually, I just realised the issue.

This is wrong:

data () {
    return {
        count: get('custom-module/count'),
    }
}

What you want is:

computed: {
    count: get('custom-module/count'),
}

I'd certainly suggest getting to know Vuex and Pathify outside of such a system as Nova! I would imagine it's having to jump through its own hoops in order to expose Vue to you.

LMK how you get on :)

BobbyBorisov commented 5 years ago

@davestewart I own you a beer and maybe not just one! Exactly that was the issue! Will follow your advice and will get familiar asap. cheers! thank you and keep up the good work

davestewart commented 5 years ago

No worries! Good luck with the Nova app.