Skip to content

Commit

Permalink
fix: fix action return value (#56)
Browse files Browse the repository at this point in the history
* fix: memo connect Hoc

* chore: changeset

* fix: fix action return value

* chore: changeset
  • Loading branch information
xuchaobei authored Jul 24, 2022
1 parent 7f178b7 commit 30b1167
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/loud-clouds-matter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@modern-js-reduck/store': patch
---

fix: fix action return value
25 changes: 22 additions & 3 deletions packages/store/src/__test__/onMount.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ const createCountModel = (onMountCreator: (onMount: any, use: any) => void) =>
value: 1,
},
actions: {
addValue(state) {
addValue(state, value) {
return {
...state,
// FIXME: ESlint 校验时,无法正确获取参数 state 的类型信息,识别为 any
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
value: state.value + 1,
value: state.value + value,
};
},
},
Expand Down Expand Up @@ -63,12 +63,31 @@ describe('test onMount hook', () => {

expect(state).toEqual({ value: 1 });

actions.addValue();
actions.addValue(1);

expect(use(count)[0]).toEqual({ value: 2 });
});
};
const count = createCountModel(onMountCreator);
store.use(count);
});

test('actions should return correct value', () => {
const store = createStore();
const onMountCreator = (onMount, use) => {
onMount(() => {
const [, actions] = use(count);

const result = actions.addValue(1);

expect(result).toEqual({
type: 'COUNT/ADDVALUE',
payload: 1,
extraArgs: [],
});
});
};
const count = createCountModel(onMountCreator);
store.use(count);
});
});
2 changes: 1 addition & 1 deletion packages/store/src/model/mountModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ const createDispatchActions = (

forEachAction(modelDesc, path =>
set(path, (payload: any, ...extraArgs: any[]) => {
context.store.dispatch({
return context.store.dispatch({
type: path.join('/').toUpperCase(),
payload,
extraArgs,
Expand Down

0 comments on commit 30b1167

Please sign in to comment.