sveltekit-search-params
Advanced tools
Comparing version 1.0.3 to 1.0.4
{ | ||
"name": "sveltekit-search-params", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"repository": "git+https://github.com/paoloricciuti/sveltekit-search-params.git", | ||
@@ -5,0 +5,0 @@ "author": "Paolo Ricciuti", |
/* eslint-disable @typescript-eslint/no-empty-function */ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
import { writable, get } from 'svelte/store'; | ||
import { goto, afterNavigate } from '$app/navigation'; | ||
import { browser } from '$app/environment'; | ||
import { goto } from '$app/navigation'; | ||
import { page } from '$app/stores'; | ||
import { browser } from '$app/environment'; | ||
import { decompressFromEncodedURIComponent, compressToEncodedURIComponent } from "./lz-string/index.js"; | ||
import { get, writable } from 'svelte/store'; | ||
import { compressToEncodedURIComponent, decompressFromEncodedURIComponent } from "./lz-string/index.js"; | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
@@ -106,8 +106,2 @@ function noop(value) { } | ||
export function queryParameters(options, { debounceHistory = 0, pushHistory = true, } = {}) { | ||
let pushHistoryCb = null; | ||
afterNavigate(() => { | ||
if (pushHistoryCb) { | ||
pushHistoryCb(); | ||
} | ||
}); | ||
const { set: _set, subscribe } = writable(); | ||
@@ -134,14 +128,11 @@ const setRef = { value: noop }; | ||
clearTimeout(batchTimeout); | ||
batchTimeout = setTimeout(() => { | ||
batchTimeout = setTimeout(async () => { | ||
batchedUpdates.forEach((batched) => { | ||
batched(query); | ||
}); | ||
goto(`?${query}`, GOTO_OPTIONS); | ||
clearTimeout(debouncedTimeouts.get("queryParameters")); | ||
await goto(`?${query}`, GOTO_OPTIONS); | ||
if (pushHistory) { | ||
debouncedTimeouts.set("queryParameters", setTimeout(() => { | ||
pushHistoryCb = () => { | ||
goto("", GOTO_OPTIONS_PUSH); | ||
pushHistoryCb = null; | ||
}; | ||
goto("", GOTO_OPTIONS_PUSH); | ||
}, debounceHistory)); | ||
@@ -184,8 +175,2 @@ } | ||
export function queryParam(name, { encode: encode = DEFAULT_ENCODER_DECODER.encode, decode: decode = DEFAULT_ENCODER_DECODER.decode, defaultValue } = DEFAULT_ENCODER_DECODER, { debounceHistory = 0, pushHistory = true, } = {}) { | ||
let pushHistoryCb = null; | ||
afterNavigate(() => { | ||
if (pushHistoryCb) { | ||
pushHistoryCb(); | ||
} | ||
}); | ||
const { set: _set, subscribe } = writable(); | ||
@@ -207,14 +192,11 @@ const setRef = { value: noop }; | ||
const query = new URLSearchParams($page.url.searchParams); | ||
batchTimeout = setTimeout(() => { | ||
batchTimeout = setTimeout(async () => { | ||
batchedUpdates.forEach((batched) => { | ||
batched(query); | ||
}); | ||
goto(`?${query}`, GOTO_OPTIONS); | ||
clearTimeout(debouncedTimeouts.get(name)); | ||
await goto(`?${query}`, GOTO_OPTIONS); | ||
if (pushHistory) { | ||
debouncedTimeouts.set(name, setTimeout(() => { | ||
pushHistoryCb = () => { | ||
goto("", GOTO_OPTIONS_PUSH); | ||
pushHistoryCb = null; | ||
}; | ||
goto("", GOTO_OPTIONS_PUSH); | ||
}, debounceHistory)); | ||
@@ -221,0 +203,0 @@ } |
31310
11
315