Skip to content

Commit

Permalink
fixed #28
Browse files Browse the repository at this point in the history
  • Loading branch information
monkindey committed Nov 23, 2021
1 parent 42f8463 commit 56af7c9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
30 changes: 30 additions & 0 deletions packages/use-table/__tests__/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,4 +197,34 @@ describe('useTable#plugin', () => {
expect((result.current as any).name).toEqual('foo');
expect((result.current as any).title).toEqual(undefined);
});

it('transformer', async () => {
const dataSource = [{ name: 'ahooks' }];
const TOTAL = 25;
const usePlugin = () => {
return {
middlewares: (ctx, next) => {
ctx.params.test = 1;
return next();
},
props: () => ({
name: 'foo',
}),
};
};

const { waitForNextUpdate } = renderHook(() => {
const plugin = usePlugin();
return useTable(() => service({ dataSource, total: TOTAL }), {
transformer: (p) => {
expect(p).toEqual({ current: 1, pageSize: 20, test: 1 });
return { ...p };
},
plugins: [plugin],
});
});

await waitForNextUpdate();
await waitForNextUpdate();
});
});
2 changes: 1 addition & 1 deletion packages/use-table/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const YOUR_TURN = 'yourTurn';
export const QUERYING = 'querying';
export const DID_QUERY = 'didQuery';

export const timelines = [DID_RENDER, WILL_QUERY, WILL_TRANSFORM, YOUR_TURN, QUERYING, DID_QUERY];
export const timelines = [DID_RENDER, WILL_QUERY, YOUR_TURN, WILL_TRANSFORM, QUERYING, DID_QUERY];
export const defaults = { current: 1, pageSize: 20 };
export const methods = {
ON_REFRESH_DEPS: 'onRefreshDeps',
Expand Down

0 comments on commit 56af7c9

Please sign in to comment.