Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting a default if enumerated parameter is invalid #38

Open
Rykuno opened this issue Aug 15, 2023 · 2 comments
Open

Setting a default if enumerated parameter is invalid #38

Rykuno opened this issue Aug 15, 2023 · 2 comments

Comments

@Rykuno
Copy link

Rykuno commented Aug 15, 2023

Describe the problem

Provide an api to check validity of query keys and provide defaults if invalid.

For whatever reason some users try to modify our search params manually. We assume this mostly happens when a url not fully copied to the clipboard. Nonetheless you'll end up with a query that looks like ?sort=highes for example; where the "t" is cutoff.

At the moment we are the default parameter but that only adds a default value if the key is not present instead of checking if the value is valid it seems.

We are currently checking this in our onMount like so; but it gets verbose when there are 15 keys to check for (search heavy data app).

	onMount(() => {
		if ($store.sort !== 'highest' ?? $store.sort !== 'recent') {
			$store.sort = 'highest';
		}
	});

Describe the proposed solution

An api similar to the default feature that would not only check for a missing key, but check for its validity and set a default value if invalid.

@Rykuno Rykuno changed the title Setting a default if enumerated key does not exist Setting a default if enumerated key is invalid Aug 15, 2023
@Rykuno Rykuno changed the title Setting a default if enumerated key is invalid Setting a default if enumerated parameter is invalid Aug 15, 2023
@paoloricciuti
Copy link
Owner

Mmm i like this idea but i have to think through the api and see what's possible. I'll definitely try this out as soon as i have time

@paoloricciuti
Copy link
Owner

I just realized you can already achieve this with a custom encode and decode function

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants