Skip to content

Commit

Permalink
chore: rename
Browse files Browse the repository at this point in the history
  • Loading branch information
Wxh16144 committed Dec 22, 2022
1 parent c3df6b6 commit 104a917
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
@@ -1,8 +1,7 @@
/* eslint-disable no-redeclare */
export function mergeProps<A, B>(a: A, b: B): B & A;
export function mergeProps<A, B, C>(a: A, b: B, c: C): C & B & A;
export function mergeProps(...list: any[]) {
const result = { ...list[0] };
type RecordType = Record<string, any>;

function extendsObject<T extends RecordType>(...list: T[]) {
const result: RecordType = { ...list[0] };

for (let i = 1; i < list.length; i++) {
const obj = list[i];
Expand All @@ -18,3 +17,5 @@ export function mergeProps(...list: any[]) {

return result;
}

export default extendsObject;
4 changes: 2 additions & 2 deletions components/list/index.tsx
Expand Up @@ -12,7 +12,7 @@ import type { SpinProps } from '../spin';
import Spin from '../spin';
import type { Breakpoint } from '../_util/responsiveObserve';
import { responsiveArray } from '../_util/responsiveObserve';
import { mergeProps } from '../_util/withDefaultProps';
import extendsObject from '../_util/extendsObject';
import Item from './Item';

// CSSINJS
Expand Down Expand Up @@ -191,7 +191,7 @@ function List<T>({
hashId,
);

const paginationProps = mergeProps(
const paginationProps = extendsObject<PaginationConfig>(
defaultPaginationProps,
{
total: dataSource.length,
Expand Down
12 changes: 8 additions & 4 deletions components/table/hooks/usePagination.ts
@@ -1,7 +1,7 @@
import { useState } from 'react';
import type { PaginationProps } from '../../pagination';
import type { TablePaginationConfig } from '../interface';
import { mergeProps } from '../../_util/withDefaultProps';
import extendsObject from '../../_util/extendsObject';

export const DEFAULT_PAGE_SIZE = 10;

Expand Down Expand Up @@ -44,9 +44,13 @@ export default function usePagination(
}));

// ============ Basic Pagination Config ============
const mergedPagination = mergeProps(innerPagination, paginationObj, {
total: paginationTotal > 0 ? paginationTotal : total,
});
const mergedPagination = extendsObject<Partial<TablePaginationConfig>>(
innerPagination,
paginationObj,
{
total: paginationTotal > 0 ? paginationTotal : total,
},
);

// Reset `current` if data length or pageSize changed
const maxPage = Math.ceil((paginationTotal || total) / mergedPagination.pageSize!);
Expand Down

0 comments on commit 104a917

Please sign in to comment.