[IMP] store: positional arguments with dispatch/commit

This commit is contained in:
Alexandre Kühn
2019-06-26 18:11:11 +02:00
committed by Géry Debongnie
parent 1b12cf9b91
commit 0095bfa61f
3 changed files with 55 additions and 9 deletions
+23 -2
View File
@@ -86,6 +86,20 @@ object, or modifying an array with the `arr[i] = newValue` syntax). See the
Mutations are the only way to modify the state. Changing the state outside a
mutation is not allowed (and should throw an error). Mutations are synchronous.
```js
const mutations = {
setLoginState({ state }, loginState) {
state.loginState = loginState;
}
};
```
Mutations are called with the `commit` method on the store, and can receive an arbitrary number of arguments.
```js
store.commit("setLoginState", "error");
```
### Actions
Actions are used to coordinate state changes. It is also useful whenever some
@@ -94,10 +108,10 @@ in an action.
```js
const actions = {
async login({ commit }) {
async login({ commit }, info) {
commit("setLoginState", "pending");
try {
const loginInfo = await doSomeRPC("/login/", "someinfo");
const loginInfo = await doSomeRPC("/login/", info);
commit("setLoginState", loginInfo);
} catch {
commit("setLoginState", "error");
@@ -106,6 +120,13 @@ const actions = {
};
```
Actions are called with the `dispatch` method on the store, and can receive an
arbitrary number of arguments.
```js
store.dispatch("login", someInfo);
```
### Getters
Usually, data contained in the store will be stored in a normalized way. For