Skip to content

Commit 357ff47

Browse files
committed
docs
1 parent 666a148 commit 357ff47

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

packages/svelte/src/index-client.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,29 @@ if (DEV) {
4444
throw_rune_error('$bindable');
4545
}
4646

47+
/**
48+
* Returns an [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) that aborts when the current [derived](https://svelte.dev/docs/svelte/$derived) or [effect](https://svelte.dev/docs/svelte/$effect) re-runs or is destroyed.
49+
*
50+
* Must be called while a derived or effect is running.
51+
*
52+
* ```svelte
53+
* <script>
54+
* import { getAbortSignal } from 'svelte';
55+
*
56+
* let { id } = $props();
57+
*
58+
* async function getData(id) {
59+
* const response = await fetch(`/items/${id}`, {
60+
* signal: getAbortSignal()
61+
* });
62+
*
63+
* return await response.json();
64+
* }
65+
*
66+
* const data = $derived(await getData(id));
67+
* </script>
68+
* ```
69+
*/
4770
export function getAbortSignal() {
4871
if (active_reaction === null) {
4972
throw new Error('TODO getAbortSignal can only be called inside a reaction');

packages/svelte/types/index.d.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,29 @@ declare module 'svelte' {
348348
*/
349349
props: Props;
350350
});
351+
/**
352+
* Returns an [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) that aborts when the current [derived](https://svelte.dev/docs/svelte/$derived) or [effect](https://svelte.dev/docs/svelte/$effect) re-runs or is destroyed.
353+
*
354+
* Must be called while a derived or effect is running.
355+
*
356+
* ```svelte
357+
* <script>
358+
* import { getAbortSignal } from 'svelte';
359+
*
360+
* let { id } = $props();
361+
*
362+
* async function getData(id) {
363+
* const response = await fetch(`/items/${id}`, {
364+
* signal: getAbortSignal()
365+
* });
366+
*
367+
* return await response.json();
368+
* }
369+
*
370+
* const data = $derived(await getData(id));
371+
* </script>
372+
* ```
373+
*/
351374
export function getAbortSignal(): AbortSignal;
352375
/**
353376
* `onMount`, like [`$effect`](https://svelte.dev/docs/svelte/$effect), schedules a function to run as soon as the component has been mounted to the DOM.

0 commit comments

Comments
 (0)