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

docs: Add documentation for updating multiple parameters at once #106

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,111 +4,111 @@

### Major Changes

- Return non-null writable for defined defaultValue and fix types for `queryParameters` ([#87](https://github.com/paoloricciuti/sveltekit-search-params/pull/87))
- Return non-null writable for defined defaultValue and fix types for `queryParameters` ([#87](https://github.com/paoloricciuti/sveltekit-search-params/pull/87))

### Patch Changes

- fix: avoid complex values default being overriden on write ([#89](https://github.com/paoloricciuti/sveltekit-search-params/pull/89))
- fix: avoid complex values default being overriden on write ([#89](https://github.com/paoloricciuti/sveltekit-search-params/pull/89))

## 2.1.2

### Patch Changes

- Fix the override setting to allow for false values ([#74](https://github.com/paoloricciuti/sveltekit-search-params/pull/74))
- Fix the override setting to allow for false values ([#74](https://github.com/paoloricciuti/sveltekit-search-params/pull/74))

## 2.1.1

### Patch Changes

- fix: allow building the app in prerendering by faking the page store during building ([#68](https://github.com/paoloricciuti/sveltekit-search-params/pull/68))
- fix: allow building the app in prerendering by faking the page store during building ([#68](https://github.com/paoloricciuti/sveltekit-search-params/pull/68))

## 2.1.0

### Minor Changes

- feat: add equalityFn option for complex objects and array ([#64](https://github.com/paoloricciuti/sveltekit-search-params/pull/64))
- feat: add equalityFn option for complex objects and array ([#64](https://github.com/paoloricciuti/sveltekit-search-params/pull/64))

## 2.0.0

### Major Changes

- breaking: remove double navigation, debounce navigate after timeout ([#60](https://github.com/paoloricciuti/sveltekit-search-params/pull/60))
feat: add showDefaults option to chose wether to show the defaults or not in the URL
- breaking: remove double navigation, debounce navigate after timeout ([#60](https://github.com/paoloricciuti/sveltekit-search-params/pull/60))
feat: add showDefaults option to chose wether to show the defaults or not in the URL

## 1.1.1

### Patch Changes

- fde7148: fix: rework how defaults works
- fde7148: fix: rework how defaults works

## 1.1.0

### Minor Changes

- 7a99cd8: feat: sorting search params before navigating
- 7a99cd8: feat: sorting search params before navigating

## 1.0.18

### Patch Changes

- ac0a8c3: extend peer dep sveltekit to 2.0
- ac0a8c3: extend peer dep sveltekit to 2.0

## 1.0.17

### Patch Changes

- cc1ad2a: rework the library to use a derived store to solve some issue
- cc1ad2a: rework the library to use a derived store to solve some issue

## 1.0.16

### Patch Changes

- b606180: fix: type ssp array
- b606180: fix: type ssp array

## 1.0.15

### Patch Changes

- 2e7f889: Allow returning undefined from encode to remove param from URL
- 2e7f889: Allow returning undefined from encode to remove param from URL

## 1.0.14

### Patch Changes

- a81535c: Fix undefined not removing params (#31)
- a81535c: Fix undefined not removing params (#31)

## 1.0.13

### Patch Changes

- 8924160: feat: support svelte 4
- 8924160: feat: support svelte 4

## 1.0.12

### Patch Changes

- 901d9c7: Add client side check before invoking goto
- 901d9c7: Add client side check before invoking goto

## 1.0.11

### Patch Changes

- 6f78e87: removed changesets as dependency and add it as dev dependency
- 6f78e87: removed changesets as dependency and add it as dev dependency

## 1.0.10

### Patch Changes

- 33276b7: fixing changeset
- 33276b7: fixing changeset

## 1.0.8

### Patch Changes

- b0b4b0a: replublish
- b0b4b0a: replublish

## 1.0.7

### Patch Changes

- 34a1e1b: the hash of the url now doesn't get's erased when the search params update
- 34a1e1b: the hash of the url now doesn't get's erased when the search params update
31 changes: 30 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ this will make the query parameter change as soon as the page is rendered on the

> **Warning**
>
> You can't run `goto` on the server so if the page is server side rendered it will still have the null value (this is to say don't relay on the assumption that the store will always be not null).
> You can't run `goto` on the server so if the page is server side rendered it will still have the null value (this is to say don't rely on the assumption that the store will always be not null).

### Helpers encodings and decodings

Expand Down Expand Up @@ -215,6 +215,35 @@ Just like with the single parameter case you can just update the store and the U

writing in the input will update the state and the URL at the same time.

### Updating multiple parameters at once

When you need to update multiple different parameters at once you will want to use the `update()` method to update the store to prevent multiple calls of `goto()`.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only happens when using queryParameters tho...can you please specify that in the documentation?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it not happen if you had multiple queryParams? Doesn't it call goto the same way?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you update multiple queryParam store in a single function it will wait a macrotask before navigating...unfortunately this is not really possible with queryParameters but you have a very nice solution for this.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah okay got it


```svelte
<script lang="ts">
import { queryParameters } from 'sveltekit-search-params';

const store = queryParameters();

const update = (value) => {
store.update((v) => {
return {
...v,
from: value.from,
to: value.to,
period: value.period,
};
});
};
</script>

<SomeComponent onUpdate={update} />
```

> **Warning**
>
> If you don't use the update and instead individually assign each property on the store you may get `sveltekit 'client.js Uncaught (in promise) Error: navigation aborted'` errors.

### Expecting some parameters

Most of the times if you need to read from query parameters you are expecting some parameters to be present. You can define the parameters you are expecting during the store creation and those will be merged with the actual query parameters despite the fact that they are present or not.
Expand Down
Loading