imp: add env to store dispatch

This is useful to allow actions to use specific environment methods.
For example, one might want to add a rpc method to the environment.
This commit is contained in:
Alexandre Kühn
2019-03-29 11:23:44 +01:00
committed by Géry Debongnie
parent d10426c720
commit 7027ff1eb6
2 changed files with 19 additions and 2 deletions
+13
View File
@@ -41,6 +41,19 @@ describe("basic use", () => {
expect(store.state.n).toBe(15);
});
test("env is given to actions", () => {
expect.assertions(1);
const someEnv = {};
const actions = {
someaction({ env }) {
expect(env).toBe(someEnv);
}
};
const store = new Store({ state: {}, actions, env: someEnv });
store.dispatch("someaction");
});
test("multiple commits trigger one update", async () => {
let updateCounter = 0;
const state = { n: 1 };