sveltekit-search-params
Advanced tools
Comparing version 0.1.7 to 0.1.8
{ | ||
"name": "sveltekit-search-params", | ||
"version": "0.1.7", | ||
"version": "0.1.8", | ||
"repository": "git+https://github.com/paoloricciuti/sveltekit-search-params.git", | ||
@@ -5,0 +5,0 @@ "author": "Paolo Ricciuti", |
@@ -74,2 +74,4 @@ /* eslint-disable @typescript-eslint/no-empty-function */ | ||
}; | ||
const batchedUpdates = new Set(); | ||
let batchTimeout; | ||
export function queryParameters(options) { | ||
@@ -82,17 +84,27 @@ const { set: _set, subscribe, update } = writable(); | ||
const query = new URLSearchParams($page.url.searchParams); | ||
for (const field of Object.keys(value)) { | ||
if (!value[field] == undefined) { | ||
query.delete(field); | ||
continue; | ||
const toBatch = (query) => { | ||
for (const field of Object.keys(value)) { | ||
if (!value[field] == undefined) { | ||
query.delete(field); | ||
continue; | ||
} | ||
let fnToCall = (value) => value.toString(); | ||
const optionsKey = options?.[field]; | ||
if (typeof optionsKey !== "boolean" && typeof optionsKey?.encode === 'function') { | ||
fnToCall = optionsKey.encode; | ||
} | ||
query.set(field, fnToCall(value[field])); | ||
} | ||
let fnToCall = (value) => value.toString(); | ||
const optionsKey = options?.[field]; | ||
if (typeof optionsKey !== "boolean" && typeof optionsKey?.encode === 'function') { | ||
fnToCall = optionsKey.encode; | ||
} | ||
query.set(field, fnToCall(value[field])); | ||
} | ||
goto(`?${query}`, { | ||
keepFocus: true, | ||
noScroll: true | ||
}; | ||
batchedUpdates.add(toBatch); | ||
clearTimeout(batchTimeout); | ||
batchTimeout = setTimeout(() => { | ||
batchedUpdates.forEach((batched) => { | ||
batched(query); | ||
}); | ||
goto(`?${query}`, { | ||
keepFocus: true, | ||
noScroll: true, | ||
}); | ||
batchedUpdates.clear(); | ||
}); | ||
@@ -126,12 +138,22 @@ }; | ||
setRef.value = (value) => { | ||
const toBatch = (query) => { | ||
if (value == undefined) { | ||
query.delete(name); | ||
} | ||
else { | ||
query.set(name, encode(value)); | ||
} | ||
}; | ||
batchedUpdates.add(toBatch); | ||
clearTimeout(batchTimeout); | ||
const query = new URLSearchParams($page.url.searchParams); | ||
if (value == undefined) { | ||
query.delete(name); | ||
} | ||
else { | ||
query.set(name, encode(value)); | ||
} | ||
goto(`?${query}`, { | ||
keepFocus: true, | ||
noScroll: true, | ||
batchTimeout = setTimeout(() => { | ||
batchedUpdates.forEach((batched) => { | ||
batched(query); | ||
}); | ||
goto(`?${query}`, { | ||
keepFocus: true, | ||
noScroll: true, | ||
}); | ||
batchedUpdates.clear(); | ||
}); | ||
@@ -138,0 +160,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
19469
233
7667
8