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 docs for sequence #2317

Merged
merged 1 commit into from
Aug 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions documentation/docs/04-hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ export async function handle({ request, resolve }) {
}
```

You can add call multiple `handle` functions with [the `sequence` helper function](#modules-@sveltejs/kit/hooks).

### handleError

If an error is thrown during rendering, this function will be called with the `error` and the `request` that caused it. This allows you to send data to an error tracking service, or to customise the formatting before printing the error to the console.
Expand Down
19 changes: 19 additions & 0 deletions documentation/docs/05-modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,22 @@ import { build, files, timestamp } from '$service-worker';
- `build` is an array of URL strings representing the files generated by Vite, suitable for caching with `cache.addAll(build)`
- `files` is an array of URL strings representing the files in your `static` directory, or whatever directory is specified by [`config.kit.files.assets`](#configuration). You can exclude certain files from `static` directory using [`config.kit.serviceWorker.exclude`](#configuration)
- `timestamp` is the result of calling `Date.now()` at build time. It's useful for generating unique cache names inside your service worker, so that a later deployment of your app can invalidate old caches

### @sveltejs/kit/hooks

This modules provides a helper function to sequence multiple `handle` calls.

```js
import { sequence } from '@sveltejs/kit/hooks';

async function first({ request, resolve }) {
console.log('first');
return await resolve(request);
}
async function second({ request, resolve }) {
console.log('second');
return await resolve(request);
}

export const handle = sequence(first, second);
```