basic action test
This commit is contained in:
parent
f5cdc4207a
commit
13eeb86e05
@ -4,16 +4,6 @@ import { action } from './actions.js';
|
|||||||
|
|
||||||
import { Updux } from './Updux.js';
|
import { Updux } from './Updux.js';
|
||||||
|
|
||||||
test('basic action', () => {
|
|
||||||
const foo = action('foo', (thing) => ({ thing }));
|
|
||||||
|
|
||||||
expect(foo('bar')).toEqual({
|
|
||||||
type: 'foo',
|
|
||||||
payload: {
|
|
||||||
thing: 'bar',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Updux config accepts actions', () => {
|
test('Updux config accepts actions', () => {
|
||||||
const foo = new Updux({
|
const foo = new Updux({
|
||||||
|
@ -1,4 +1,18 @@
|
|||||||
import Updux, { createAction } from './index.js';
|
import Updux, { createAction, withPayload } from './index.js';
|
||||||
|
|
||||||
|
test('basic action', () => {
|
||||||
|
const foo = createAction(
|
||||||
|
'foo',
|
||||||
|
withPayload((thing: string) => ({ thing })),
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(foo('bar')).toEqual({
|
||||||
|
type: 'foo',
|
||||||
|
payload: {
|
||||||
|
thing: 'bar',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
test('subduxes actions', () => {
|
test('subduxes actions', () => {
|
||||||
const bar = createAction<number>('bar');
|
const bar = createAction<number>('bar');
|
||||||
|
@ -2,6 +2,14 @@ import { createAction } from '@reduxjs/toolkit';
|
|||||||
|
|
||||||
export { createAction } from '@reduxjs/toolkit';
|
export { createAction } from '@reduxjs/toolkit';
|
||||||
|
|
||||||
export const withPayload =
|
interface WithPayload {
|
||||||
<P>() =>
|
(): <P>(input: P) => { payload: P };
|
||||||
(payload: P) => ({ payload });
|
<P, A extends any[]>(prepare: (...args: A) => P): (...input: A) => {
|
||||||
|
payload: P;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export const withPayload: WithPayload = ((prepare) =>
|
||||||
|
(...input) => ({
|
||||||
|
payload: prepare ? prepare(...input) : input,
|
||||||
|
})) as any;
|
||||||
|
Loading…
Reference in New Issue
Block a user