Skip to content

Commit 9e54b47

Browse files
committed
chore: Remove unused sync code
1 parent 0f012c3 commit 9e54b47

File tree

3 files changed

+2
-24
lines changed

3 files changed

+2
-24
lines changed

packages/nuqs/src/sync.ts

-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
import Mitt from 'mitt'
22

3-
export const SYNC_EVENT_KEY = Symbol('__nuqs__SYNC__')
4-
53
export type CrossHookSyncPayload = {
64
state: any
75
query: string | null
86
}
97

108
type EventMap = {
11-
[SYNC_EVENT_KEY]: URLSearchParams
129
[key: string]: CrossHookSyncPayload
1310
}
1411

packages/nuqs/src/useQueryState.ts

+1-12
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import React from 'react'
33
import { debug } from './debug'
44
import type { Options } from './defs'
55
import type { Parser } from './parsers'
6-
import { SYNC_EVENT_KEY, emitter, type CrossHookSyncPayload } from './sync'
6+
import { emitter, type CrossHookSyncPayload } from './sync'
77
import {
88
FLUSH_RATE_LIMIT_MS,
99
enqueueQueryStringUpdate,
@@ -261,21 +261,10 @@ export function useQueryState<T = string>(
261261
queryRef.current = query
262262
setInternalState(state)
263263
}
264-
function syncFromURL(search: URLSearchParams) {
265-
const query = search.get(key)
266-
if (query === queryRef.current) {
267-
return
268-
}
269-
const state = query === null ? null : safeParse(parse, query, key)
270-
debug('[nuqs `%s`] syncFromURL %O', key, state)
271-
updateInternalState({ state, query })
272-
}
273264
debug('[nuqs `%s`] subscribing to sync', key)
274-
emitter.on(SYNC_EVENT_KEY, syncFromURL)
275265
emitter.on(key, updateInternalState)
276266
return () => {
277267
debug('[nuqs `%s`] unsubscribing from sync', key)
278-
emitter.off(SYNC_EVENT_KEY, syncFromURL)
279268
emitter.off(key, updateInternalState)
280269
}
281270
}, [key])

packages/nuqs/src/useQueryStates.ts

+1-9
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import React from 'react'
77
import { debug } from './debug'
88
import type { Nullable, Options } from './defs'
99
import type { Parser } from './parsers'
10-
import { SYNC_EVENT_KEY, emitter, type CrossHookSyncPayload } from './sync'
10+
import { emitter, type CrossHookSyncPayload } from './sync'
1111
import {
1212
FLUSH_RATE_LIMIT_MS,
1313
enqueueQueryStringUpdate,
@@ -110,11 +110,6 @@ export function useQueryStates<KeyMap extends UseQueryStatesKeysMap>(
110110
stateRef.current = state
111111
setInternalState(state)
112112
}
113-
function syncFromURL(search: URLSearchParams) {
114-
const state = parseMap(keyMap, search, queryRef.current, stateRef.current)
115-
debug('[nuq+ `%s`] syncFromURL %O', keys, state)
116-
updateInternalState(state)
117-
}
118113
const handlers = Object.keys(keyMap).reduce(
119114
(handlers, key) => {
120115
handlers[key as keyof V] = ({ state, query }: CrossHookSyncPayload) => {
@@ -140,14 +135,11 @@ export function useQueryStates<KeyMap extends UseQueryStatesKeysMap>(
140135
},
141136
{} as Record<keyof V, (payload: CrossHookSyncPayload) => void>
142137
)
143-
144-
emitter.on(SYNC_EVENT_KEY, syncFromURL)
145138
for (const key of Object.keys(keyMap)) {
146139
debug('[nuq+ `%s`] Subscribing to sync for `%s`', keys, key)
147140
emitter.on(key, handlers[key]!)
148141
}
149142
return () => {
150-
emitter.off(SYNC_EVENT_KEY, syncFromURL)
151143
for (const key of Object.keys(keyMap)) {
152144
debug('[nuq+ `%s`] Unsubscribing to sync for `%s`', keys, key)
153145
emitter.off(key, handlers[key])

0 commit comments

Comments
 (0)