[IMP] store: return data from committing a mutation

closes #29
This commit is contained in:
Alexandre Kühn
2019-04-15 10:24:08 +02:00
committed by Géry Debongnie
parent 7e7226213a
commit e005090296
2 changed files with 17 additions and 1 deletions
+2 -1
View File
@@ -74,7 +74,7 @@ export class Store extends EventBus {
this._isMutating = true; this._isMutating = true;
this.observer.allowMutations = true; this.observer.allowMutations = true;
this.mutations[type].call( const res = this.mutations[type].call(
null, null,
{ {
commit: this.commit.bind(this), commit: this.commit.bind(this),
@@ -103,6 +103,7 @@ export class Store extends EventBus {
}); });
} }
this._commitLevel--; this._commitLevel--;
return res;
} }
} }
+15
View File
@@ -95,6 +95,21 @@ describe("basic use", () => {
expect(store.state.n).toBe(11); expect(store.state.n).toBe(11);
}); });
test("return data from committing a mutation", () => {
const state = { n: 1 };
const mutations = {
inc({ state }) {
return ++state.n;
},
};
const store = new Store({ state, mutations });
expect(store.state.n).toBe(1);
const res = store.commit("inc");
expect(store.state.n).toBe(2);
expect(res).toBe(2);
});
test("dispatch allow synchronizing between actions", async () => { test("dispatch allow synchronizing between actions", async () => {
const state = { n: 1 }; const state = { n: 1 };
const mutations = { const mutations = {