You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
param.addEventListener('change',onChange,{ signal, passive, once });
19
-
returnparam;
20
-
}else{
21
-
returnnewSearchParam(key,fallbackValue);
22
28
}
29
+
30
+
if(onBeforeChangeinstanceofFunction){
31
+
param.addEventListener('beforechange',onBeforeChange,{ signal, passive, once });
32
+
}
33
+
returnparam;
23
34
}
24
35
25
36
/**
26
-
* Manages a specified URL search parameter as a live-updating stateful value.
37
+
* Manages search parameters in the URL with custom behavior for changes and updates.
27
38
*
28
-
* @param {string} key - The name of the URL search parameter to manage.
29
-
* @param {string|number} [fallbackValue=''] - The initial/fallback value if the search parameter is not set.
30
-
* @returns {[SearchParam, function(string|number): void]} - Returns a two-element array:
31
-
* - Returns a two-element array:
32
-
* - The first element is an object with:
33
-
* - A `toString` method, returning the current value of the URL parameter as a string.
34
-
* - A `[Symbol.toPrimitive]` method, allowing automatic conversion of the value based on the context (e.g., string or number).
35
-
* - The second element is a setter function that updates the URL search parameter to a new value, reflected immediately in the URL without reloading the page.
39
+
* @param {string} key - The name of the search parameter to manage.
40
+
* @param {string|Array} [fallbackValue=''] - The default value to use if the parameter is not present.
41
+
* @param {Object} [options={}] - Optional configuration for managing the search parameter.
42
+
* @param {function(SearchParamChangeEvent)} [options.onChange] - Callback invoked when the search parameter value changes.
43
+
* @param {function(SearchParamChangeEvent)} [options.onBeforeChange] - Callback invoked before the search parameter value changes.
0 commit comments