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

I must be doing something wrong big time... #97

Closed DarkLite1 closed 4 years ago

DarkLite1 commented 4 years ago

I've tried to follow the insallation procedure to the letter, but I can't seem to get it to work properly. So what I did was:

When I then try to use the following in my codesandbox:

console.log(get('navigation/pageLinks@tickets'))

It seems to return a function instead of the array expected:

image

Thank you for having a look. I might be missing something super obvious but I just can't get it right.

DarkLite1 commented 4 years ago

I finnaly figured out what I did wrong. Feeling so stupid now as I tried practcally all variations. I was missing the reference to the Store itself:

let test = Store.get('navigation/pageLinks@tickets')

Maybe if the error message was a bit more clear I would've cought it sooner. Would it be pssoble to return an actual error like 'You're not referencing the store....' instead of rerturning a function?

Anyhow, thank you again for this wonderfull plugin.

DarkLite1 commented 4 years ago

Appears I don't even need to import these anymore either:

import { get, sync, call } from 'vuex-pathify'

However, only get and set will work, sync will fail if you only use:

import Store from "../store/index";

I'm not using it correctly yet I guess.

DarkLite1 commented 4 years ago

I'm reopening this because I can't seem to use the get function after importing it. Check out this codesandbox.

let test = get('navigation/pageLinks@tickets')
console.log(test)

I expect this code to return an array but instead I get a function: image

Can you have a look at what I'm doing wrong?

davestewart commented 4 years ago

Hey there...

Yes, sorry if it's a bit confusing.

There are two kinds of get (perhaps I should make this clearer in the docs):

This is why you are seeing a function - because you are importing the helper and expecting it to "get" something. The semantics are clearer when you use it within the context of a computed property block, especially when you are also using sync().

The correct usage would be:

import { get } from 'vuex-pathify'
export default {
  computed: {
    tickets: get('navigation/pageLinks@tickets') // create a getter
  }
}

or

export default {
  data () {
    return {
      tickets: [],
    }
  },
  methods: {
    getTickets () {
      this.tickets = this.$store.get('navigation/pageLinks@tickets')
    }
  }
}

or from the console:

store.get('navigation/pageLinks@tickets')
DarkLite1 commented 4 years ago

That was indeed what was tripping me over. I'm really new to web development, so I'm learning things as I go.

Before your plugin I used vuex-map-fields, but then I found your plugin and fell in love with the concept immediately. The simplicity of the syntax, the logic behind it, ... Love it!

Maybe other newbies like me might have this same issue. So a small clarification on the docs might help others.

Something I'm missing too, but is only briefly mentioned is set pathify best practices are, besides all it can do. For example: use make.mutations only? Or also add the make.getters? Is there a speed difference? Advantage of one over the other?

Besides that this is an awesome plugin! Should've been the vuex default nu design.