Comments (4)
Alright, as the official Vue typings allow return type any
for actions, I will change the typings to that too.
from vuex-class-modules.
Hmm, I'm not convinced:
- 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)
- 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.
- 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.
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 Observable
s to Promise
s 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)
- Cannot read property 'state' of undefined HOT 8
- Request for new feature - @Onload method decorator HOT 2
- [Feature Request] Vuex Child Modules Functionality (Submodules) HOT 4
- jest typescript fails HOT 4
- How to access Store extensions in 'this' instance? HOT 2
- Allow usage in node app without babel HOT 2
- Vuex 4 (Vue 3) support HOT 2
- Error when using hmr with vite HOT 6
- Add support for unregisterModule HOT 1
- Don't know where else to say this, but...
- Status of Vue 3.x and Vuex 4.x support ? HOT 1
- Allow composition of Action, Mutation and Getter HOT 3
- fully support registerModule usage HOT 1
- Access generated mutations (generateMutationSetters: true) from module instance HOT 3
- Is there a way to register the module without namespace? HOT 2
- Vue Devtools not working HOT 4
- List of refactoring tasks HOT 2
- Question: how to persist state? HOT 3
- How to passing multiple arguments to @action HOT 2
- a question about `new constructor.prototype.constructor`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vuex-class-modules.