mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[IMP] store: positional arguments with dispatch/commit
This commit is contained in:
committed by
Géry Debongnie
parent
1b12cf9b91
commit
0095bfa61f
+23
-2
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user