mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
imp: give reference to dispatch function in actions
This commit is contained in:
committed by
Géry Debongnie
parent
7027ff1eb6
commit
3340401f54
+3
-2
@@ -91,8 +91,9 @@ export class Store extends EventBus {
|
||||
this.actions[action](
|
||||
{
|
||||
commit: this.commit.bind(this),
|
||||
state: this.state,
|
||||
env: this.env
|
||||
dispatch: this.dispatch.bind(this),
|
||||
env: this.env,
|
||||
state: this.state
|
||||
},
|
||||
payload
|
||||
);
|
||||
|
||||
@@ -41,6 +41,28 @@ describe("basic use", () => {
|
||||
expect(store.state.n).toBe(15);
|
||||
});
|
||||
|
||||
test("can dispatch an action in an action", () => {
|
||||
const state = { n: 1 };
|
||||
const mutations = {
|
||||
inc(state, delta) {
|
||||
state.n += delta;
|
||||
}
|
||||
};
|
||||
const actions = {
|
||||
inc({ commit }, delta) {
|
||||
commit("inc", delta);
|
||||
},
|
||||
inc100({ dispatch }) {
|
||||
dispatch("inc", 100);
|
||||
}
|
||||
};
|
||||
const store = new Store({ state, mutations, actions });
|
||||
|
||||
expect(store.state.n).toBe(1);
|
||||
store.dispatch("inc100");
|
||||
expect(store.state.n).toBe(101);
|
||||
});
|
||||
|
||||
test("env is given to actions", () => {
|
||||
expect.assertions(1);
|
||||
const someEnv = {};
|
||||
|
||||
Reference in New Issue
Block a user