-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feat/548-hide-elements-api
- Loading branch information
Showing
7 changed files
with
91 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* Helper for calling navigate that will append search query to path, | ||
* if present, before appending an optional hash. | ||
* | ||
* Either search or hash may be passed as null|undefined, but if they | ||
* are present must either be the empty string or start with their | ||
* standard delimeter. | ||
* | ||
* @param {Function} navigate | ||
* @param {string} path | ||
* @param {object} options | ||
*/ | ||
export function navWith(navigate, path, options = { | ||
search: location.search, | ||
hash: location.hash, | ||
}) { | ||
const search = options.search || '' | ||
if (search !== '' && !search.startsWith('?')) { | ||
throw new Error(`Given search must start with ? Got: ${search}`) | ||
} | ||
const hash = options.hash || '' | ||
if (hash !== '' && !hash.startsWith('#')) { | ||
throw new Error(`Given hash must start with # Got: ${hash}`) | ||
} | ||
navigate(`${path}${search}${hash}`) | ||
} | ||
|
||
|
||
/** | ||
* Helper for calling navigate that will remove a named parameter from search. | ||
* | ||
* @param {Function} navigate | ||
* @param {string} path | ||
* @param {string} paramName | ||
*/ | ||
export function navWithSearchParamRemoved(navigate, path, paramName) { | ||
if (typeof(paramName) !== 'string' || paramName.length < 1) { | ||
throw new Error(`Must provide a non-empty string param name. Got "${paramName}"`) | ||
} | ||
const sp = new URLSearchParams(location.search) | ||
sp.delete(paramName) | ||
navWith(navigate, path, { | ||
search: `?${sp.toString()}`, | ||
hash: location.hash, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters