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

call() seems like not return the promise as vuex mapActions #25

Closed maimake closed 6 years ago

maimake commented 6 years ago

The Component helper fun call() should create functions which should be return promise as mapActions, Thx

davestewart commented 6 years ago

So what is currently happening, and what did you want to happen, and why? How is it different from mapActions?

Can you outline your use-cases with example code?

traherom commented 6 years ago

I ran into this today. Snippet of code:

methods: {
    ...call([
      'benchmarks/loadBenchmarks',
      // 'data/loadScan', // Using this will cause the .then to fail in onSelectScan because nothing is returned
    ]),
    ...mapActions('data', [
      'loadScan', // This will work properly though
    ]),

    onSelectScan(side, scan) {
      // Fully load scan
      this.loadScan({ id: scan.pk, truncate: true }).then(scan => {
        if(side === 'old')
          this.oldScan = scan;
        else
          this.newScan = scan;

        this.loadBenchmarks({ benchmarkIds: scan.benchmark_ids });
      });
    },
}

I believe all it takes to fix this is changing https://github.com/davestewart/vuex-pathify/blob/892e2403794521c4dcd18242932768dbb21bc6de/src/helpers/component.js#L152 to be return this.$store.dispatch(path, value). According to https://vuex.vuejs.org/guide/actions.html#composing-actions, this returning a Promise thing is the normal vuex action behavior.

I can submit a PR if needed. I just started using Pathify, but it's great so far!

davestewart commented 6 years ago

Oh, sorry - that's certainly an oversight! It should absolutely be returning the promise!

Let me patch and submit.

Glad you're enjoying it!

davestewart commented 6 years ago

Fixes 03079f458afda39a3524816b3f785ae05c9c1762

davestewart commented 6 years ago

Fix isn't published on NPM.

See: https://github.com/davestewart/vuex-pathify/commit/03079f458afda39a3524816b3f785ae05c9c1762

kevinly24 commented 6 years ago

waiting for this

traherom commented 6 years ago

There's an issue with getting it published (see discussion on the commit). For now, just use mapActions(). It'll be a drop-in replacement once updated.

maimake commented 6 years ago

@davestewart Can not be fixed ?

davestewart commented 6 years ago

Sorry for the wait, working very long days right now! Let me get in touch with NPM and see what they say

davestewart commented 6 years ago

OK, I think I must have been patching and building in the wrong order. I've just checked unpkg and it looks like it has published correctly!

traherom commented 6 years ago

Confirmed working for me now. Thanks!