Code Monkey home page Code Monkey logo

Comments (4)

gertqin avatar gertqin commented on August 23, 2024 2

Alright, as the official Vue typings allow return type any for actions, I will change the typings to that too.

from vuex-class-modules.

gertqin avatar gertqin commented on August 23, 2024

Hmm, I'm not convinced:

  1. Vuex actions should not return values - see vuejs/vuex#46 (although it works now you cannot be sure that it will in future implementations of vuex as it is not part of their API)
  2. Like above, you cannot be sure that the internal implementation of vuex actions won't return a promise eventhough your function definition is synchronous (if you have multiple handlers for the same action a promise is actually always returned). Therefore in order to wait for their execution I think you should always 'await' them.

from vuex-class-modules.

c01nd01r avatar c01nd01r commented on August 23, 2024

@gertqin

  1. As I can see, the issue are you referring is outdated. If I'm not mistaken, this was relevant for Vuex v0.3.0 (?).
    At the moment, Actions (dispatch method) can return resolved Promise with payload.
    https://github.com/vuejs/vuex/blob/dev/types/index.d.ts#L41
    I don't think it will change in the near future.
    But for next major Vuex version, there may be more extensive changes (for example, "Getting rid of the need for separating actions and mutations")

from vuex-class-modules.

bodograumann avatar bodograumann commented on August 23, 2024

I was only trying to convert my existing code to use vuex-class-modules. As @c01nd01r has pointed out, vuex allows returning values and defining actions as synchronous functions. So that’s what I did ^^

Looking more closely at my code, I now see, that I don‘t actually use the returned value. Furthermore the question of (a)synchronous methods came up because I am calling rxjs methods, which return Observables and I felt reluctant to call toPromise everywhere.

So now I’m converting all my Observables to Promises and using then instead of subscribe, but in the future I might want to do more with the Observables and I don’t know whether this is even possible with the vuex api.

from vuex-class-modules.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.