You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/svelte/src/index-client.js
+23Lines changed: 23 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -44,6 +44,29 @@ if (DEV) {
44
44
throw_rune_error('$bindable');
45
45
}
46
46
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
+
*/
47
70
exportfunctiongetAbortSignal(){
48
71
if(active_reaction===null){
49
72
thrownewError('TODO getAbortSignal can only be called inside a reaction');
Copy file name to clipboardExpand all lines: packages/svelte/types/index.d.ts
+23Lines changed: 23 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -348,6 +348,29 @@ declare module 'svelte' {
348
348
*/
349
349
props: Props;
350
350
});
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
+
*/
351
374
exportfunctiongetAbortSignal(): AbortSignal;
352
375
/**
353
376
* `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