sveltekit-search-params
Advanced tools
Comparing version 1.0.2 to 1.0.3
{ | ||
"name": "sveltekit-search-params", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"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 } from '$app/navigation'; | ||
import { goto, afterNavigate } from '$app/navigation'; | ||
import { page } from '$app/stores'; | ||
@@ -106,2 +106,8 @@ import { browser } from '$app/environment'; | ||
export function queryParameters(options, { debounceHistory = 0, pushHistory = true, } = {}) { | ||
let pushHistoryCb = null; | ||
afterNavigate(() => { | ||
if (pushHistoryCb) { | ||
pushHistoryCb(); | ||
} | ||
}); | ||
const { set: _set, subscribe } = writable(); | ||
@@ -136,5 +142,6 @@ const setRef = { value: noop }; | ||
debouncedTimeouts.set("queryParameters", setTimeout(() => { | ||
const updatedPage = get(page); | ||
const updatedQuery = new URLSearchParams(updatedPage.url.searchParams); | ||
goto(`?${updatedQuery.toString()}`, GOTO_OPTIONS_PUSH); | ||
pushHistoryCb = () => { | ||
goto("", GOTO_OPTIONS_PUSH); | ||
pushHistoryCb = null; | ||
}; | ||
}, debounceHistory)); | ||
@@ -177,2 +184,8 @@ } | ||
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(); | ||
@@ -202,5 +215,6 @@ const setRef = { value: noop }; | ||
debouncedTimeouts.set(name, setTimeout(() => { | ||
const updatedPage = get(page); | ||
const updatedQuery = new URLSearchParams(updatedPage.url.searchParams); | ||
goto(`?${updatedQuery.toString()}`, GOTO_OPTIONS_PUSH); | ||
pushHistoryCb = () => { | ||
goto("", GOTO_OPTIONS_PUSH); | ||
pushHistoryCb = null; | ||
}; | ||
}, debounceHistory)); | ||
@@ -207,0 +221,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
30752
333