Skip to content

Commit 1a733f0

Browse files
committed
ref: Reorganise lib code
- Move shared code into src/lib, leaving only features at the top level - Move the throttle queue into a class to help with testing & multi-storage support later - Add stubs for debounce queue
1 parent 803d3e0 commit 1a733f0

33 files changed

+476
-303
lines changed

packages/nuqs/src/adapters/custom.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export { renderQueryString } from '../url-encoding'
1+
export { renderQueryString } from '../lib/url-encoding'
22
export {
33
createAdapterProvider as unstable_createAdapterProvider,
44
type AdapterContext as unstable_AdapterContext

packages/nuqs/src/adapters/lib/context.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createContext, createElement, useContext, type ReactNode } from 'react'
2-
import { error } from '../../errors'
2+
import { error } from '../../lib/errors'
33
import type { UseAdapterHook } from './defs'
44

55
export type AdapterContext = {

packages/nuqs/src/adapters/lib/patch-history.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Emitter } from 'mitt'
2-
import { debug } from '../../debug'
3-
import { error } from '../../errors'
2+
import { debug } from '../../lib/debug'
3+
import { error } from '../../lib/errors'
44

55
export type SearchParamsSyncEmitter = Emitter<{ update: URLSearchParams }>
66

packages/nuqs/src/adapters/lib/react-router.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import mitt from 'mitt'
22
import { startTransition, useCallback, useEffect, useState } from 'react'
3-
import { renderQueryString } from '../../url-encoding'
3+
import { renderQueryString } from '../../lib/url-encoding'
44
import { createAdapterProvider } from './context'
55
import type { AdapterInterface, AdapterOptions } from './defs'
66
import {

packages/nuqs/src/adapters/next/impl.app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useRouter, useSearchParams } from 'next/navigation'
22
import { startTransition, useCallback, useOptimistic } from 'react'
3-
import { debug } from '../../debug'
3+
import { debug } from '../../lib/debug'
44
import type { AdapterInterface, UpdateUrlFunction } from '../lib/defs'
55
import { renderURL } from './shared'
66

packages/nuqs/src/adapters/next/impl.pages.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useSearchParams } from 'next/navigation.js'
22
import type { NextRouter } from 'next/router'
33
import { useCallback } from 'react'
4-
import { debug } from '../../debug'
4+
import { debug } from '../../lib/debug'
55
import { createAdapterProvider } from '../lib/context'
66
import type { AdapterInterface, UpdateUrlFunction } from '../lib/defs'
77
import { renderURL } from './shared'

packages/nuqs/src/adapters/next/shared.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { renderQueryString } from '../../url-encoding'
1+
import { renderQueryString } from '../../lib/url-encoding'
22

33
export function renderURL(base: string, search: URLSearchParams) {
44
const hashlessBase = base.split('#')[0] ?? ''

packages/nuqs/src/adapters/react.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import mitt from 'mitt'
22
import { useEffect, useState } from 'react'
3-
import { renderQueryString } from '../url-encoding'
3+
import { renderQueryString } from '../lib/url-encoding'
44
import { createAdapterProvider } from './lib/context'
5-
import type { AdapterOptions } from './lib/defs'
5+
import type { AdapterInterface, AdapterOptions } from './lib/defs'
66
import { patchHistory, type SearchParamsSyncEmitter } from './lib/patch-history'
77

88
const emitter: SearchParamsSyncEmitter = mitt()
@@ -16,7 +16,7 @@ function updateUrl(search: URLSearchParams, options: AdapterOptions) {
1616
emitter.emit('update', search)
1717
}
1818

19-
function useNuqsReactAdapter() {
19+
function useNuqsReactAdapter(): AdapterInterface {
2020
const [searchParams, setSearchParams] = useState(() => {
2121
if (typeof location === 'undefined') {
2222
return new URLSearchParams()

packages/nuqs/src/adapters/testing.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { createElement, type ReactNode } from 'react'
2-
import { resetQueue } from '../update-queue'
3-
import { renderQueryString } from '../url-encoding'
2+
import { globalThrottleQueue } from '../lib/queues/throttle'
3+
import { renderQueryString } from '../lib/url-encoding'
44
import { context } from './lib/context'
55
import type { AdapterInterface, AdapterOptions } from './lib/defs'
66

@@ -25,7 +25,7 @@ export function NuqsTestingAdapter({
2525
...props
2626
}: TestingAdapterProps) {
2727
if (resetUrlUpdateQueueOnMount) {
28-
resetQueue()
28+
globalThrottleQueue.reset()
2929
}
3030
const useAdapter = (): AdapterInterface => ({
3131
searchParams: new URLSearchParams(props.searchParams),

packages/nuqs/src/cache.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// @ts-ignore
22
import { cache } from 'react'
33
import type { SearchParams, UrlKeys } from './defs'
4-
import { error } from './errors'
4+
import { error } from './lib/errors'
55
import { createLoader } from './loader'
66
import type { inferParserType, ParserMap } from './parsers'
77

0 commit comments

Comments
 (0)