From c6005d88415260a5f1c3f205f27678672f4a817c Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Sat, 28 Aug 2021 13:08:33 -0700 Subject: [PATCH] [docs] add docs for sequence --- documentation/docs/04-hooks.md | 2 ++ documentation/docs/05-modules.md | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/documentation/docs/04-hooks.md b/documentation/docs/04-hooks.md index 580f19b15f24..5ed2a5b55438 100644 --- a/documentation/docs/04-hooks.md +++ b/documentation/docs/04-hooks.md @@ -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. diff --git a/documentation/docs/05-modules.md b/documentation/docs/05-modules.md index 6df3279cea2f..cabe5eaaaeb4 100644 --- a/documentation/docs/05-modules.md +++ b/documentation/docs/05-modules.md @@ -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); +```