Skip to content

Commit c97e5dd

Browse files
committed
refactor(v0): remove unnecessary generics from usePagination
PaginationContext, createPagination, createPaginationContext, and usePagination no longer use generic type parameters that were never parameterized by consumers. Simplifies the API without changing behavior.
1 parent 86162cd commit c97e5dd

File tree

1 file changed

+18
-27
lines changed
  • packages/0/src/composables/usePagination

1 file changed

+18
-27
lines changed

packages/0/src/composables/usePagination/index.ts

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export type PaginationTicket =
3333
| { type: 'page', value: number }
3434
| { type: 'ellipsis', value: string }
3535

36-
export interface PaginationContext<Z extends PaginationTicket = PaginationTicket> {
36+
export interface PaginationContext {
3737
/** Current page (1-indexed) */
3838
page: ShallowRef<number>
3939
/** Items per page */
@@ -45,7 +45,7 @@ export interface PaginationContext<Z extends PaginationTicket = PaginationTicket
4545
/** Ellipsis character, or false if disabled */
4646
ellipsis: string | false
4747
/** Visible page numbers and ellipsis for rendering */
48-
items: ComputedRef<Z[]>
48+
items: ComputedRef<PaginationTicket[]>
4949
/** Start index of items on current page (0-indexed) */
5050
pageStart: ComputedRef<number>
5151
/** End index of items on current page (exclusive, 0-indexed) */
@@ -105,10 +105,7 @@ export interface PaginationContextOptions extends PaginationOptions {
105105
* // Mutating pagination.page or the passed ref syncs both
106106
* ```
107107
*/
108-
export function createPagination<
109-
Z extends PaginationTicket = PaginationTicket,
110-
E extends PaginationContext<Z> = PaginationContext<Z>,
111-
> (_options: PaginationOptions = {}): E {
108+
export function createPagination (_options: PaginationOptions = {}): PaginationContext {
112109
const {
113110
page: _page = 1,
114111
itemsPerPage: _itemsPerPage = 10,
@@ -158,19 +155,19 @@ export function createPagination<
158155
const pageStart = computed(() => (page.value - 1) * toValue(_itemsPerPage))
159156
const pageStop = computed(() => Math.min(pageStart.value + toValue(_itemsPerPage), toValue(_size)))
160157

161-
function toPage (value: number): Z {
162-
return { type: 'page', value } as Z
158+
function toPage (value: number): PaginationTicket {
159+
return { type: 'page', value }
163160
}
164161

165-
function toEllipsis (): Z | false {
166-
return ellipsis === false ? false : { type: 'ellipsis', value: ellipsis } as Z
162+
function toEllipsis (): PaginationTicket | false {
163+
return ellipsis === false ? false : { type: 'ellipsis', value: ellipsis }
167164
}
168165

169-
function filter (array: (Z | false)[]): Z[] {
170-
return array.filter(Boolean) as Z[]
166+
function filter (array: (PaginationTicket | false)[]): PaginationTicket[] {
167+
return array.filter((item): item is PaginationTicket => item !== false)
171168
}
172169

173-
const items = computed<Z[]>(() => {
170+
const items = computed<PaginationTicket[]>(() => {
174171
const pageCount = pages.value
175172
const visible = toValue(_visible)
176173
const current = page.value
@@ -241,7 +238,7 @@ export function createPagination<
241238
get pages () {
242239
return pages.value
243240
},
244-
} as E
241+
}
245242
}
246243

247244
/**
@@ -269,19 +266,16 @@ export function createPagination<
269266
* pagination.next()
270267
* ```
271268
*/
272-
export function createPaginationContext<
273-
Z extends PaginationTicket = PaginationTicket,
274-
E extends PaginationContext<Z> = PaginationContext<Z>,
275-
> (_options: PaginationContextOptions = {}): ContextTrinity<E> {
269+
export function createPaginationContext (_options: PaginationContextOptions = {}): ContextTrinity<PaginationContext> {
276270
const { namespace = 'v0:pagination', ...options } = _options
277-
const [usePaginationContext, _providePaginationContext] = createContext<E>(namespace)
278-
const context = createPagination<Z, E>(options)
271+
const [usePaginationContext, _providePaginationContext] = createContext<PaginationContext>(namespace)
272+
const context = createPagination(options)
279273

280-
function providePaginationContext (_context: E = context, app?: App): E {
274+
function providePaginationContext (_context: PaginationContext = context, app?: App): PaginationContext {
281275
return _providePaginationContext(_context, app)
282276
}
283277

284-
return createTrinity<E>(usePaginationContext, providePaginationContext, context)
278+
return createTrinity<PaginationContext>(usePaginationContext, providePaginationContext, context)
285279
}
286280

287281
/**
@@ -304,9 +298,6 @@ export function createPaginationContext<
304298
* </template>
305299
* ```
306300
*/
307-
export function usePagination<
308-
Z extends PaginationTicket = PaginationTicket,
309-
E extends PaginationContext<Z> = PaginationContext<Z>,
310-
> (namespace = 'v0:pagination'): E {
311-
return useContext<E>(namespace)
301+
export function usePagination (namespace = 'v0:pagination'): PaginationContext {
302+
return useContext<PaginationContext>(namespace)
312303
}

0 commit comments

Comments
 (0)