Skip to content

Commit d8f922a

Browse files
committed
fix
1 parent f9d500b commit d8f922a

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

.changeset/loud-crabs-raise.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'zustand-x': patch
3+
---
4+
5+
Fixes #102

packages/zustand-x/src/tests/createStore.spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,24 @@ describe('zustandX', () => {
248248
extendedStore.set('validName', 'foo ');
249249
expect(extendedStore.get('name')).toBe('foo foo');
250250
});
251+
252+
it('should pass all parameters to actions', () => {
253+
const another = createStore(
254+
{
255+
value: '',
256+
},
257+
{
258+
name: 'test-params',
259+
}
260+
).extendActions(({ set }) => ({
261+
setValue: (a: string, b: string, c: string) => {
262+
set('value', `${a}-${b}-${c}`);
263+
},
264+
}));
265+
266+
another.set('setValue', 'a', 'b', 'c');
267+
expect(another.get('value')).toBe('a-b-c');
268+
});
251269
});
252270

253271
describe('when extending selectors', () => {

packages/zustand-x/src/utils/extendActions.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,17 @@ export const extendActions = <
2525
actions,
2626
set: <K extends keyof (StateType | TActions)>(
2727
key: K,
28-
value: K extends keyof TActions
29-
? Parameters<TActions[K]>[0]
28+
...args: K extends keyof TActions
29+
? Parameters<TActions[K]>
3030
: K extends keyof StateType
31-
? StateType[K]
31+
? [StateType[K]]
3232
: never
3333
) => {
3434
if (key in actions) {
3535
const action = actions[key as keyof typeof actions];
36-
return action(value);
36+
return action(...args);
3737
}
38-
return api.set(key as any, value);
38+
return api.set(key as any, args[0]);
3939
},
4040
};
4141
};

0 commit comments

Comments
 (0)