mirror of https://github.com/sveltejs/svelte
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
951 B
59 lines
951 B
1 year ago
|
import { onMount } from '$runtime/index';
|
||
|
|
||
|
// sync and no return
|
||
|
onMount(() => {
|
||
|
console.log('mounted');
|
||
|
});
|
||
|
|
||
|
// sync and return value
|
||
|
onMount(() => {
|
||
|
return 'done';
|
||
|
});
|
||
|
|
||
|
// sync and return sync
|
||
|
onMount(() => {
|
||
|
return () => {
|
||
|
return 'done';
|
||
|
};
|
||
|
});
|
||
|
|
||
|
// sync and return async
|
||
|
onMount(() => {
|
||
|
return async () => {
|
||
|
const res = await fetch('');
|
||
|
return res;
|
||
|
};
|
||
|
});
|
||
|
|
||
|
// async and no return
|
||
|
onMount(async () => {
|
||
|
await fetch('');
|
||
|
});
|
||
|
|
||
|
// async and return value
|
||
|
onMount(async () => {
|
||
|
const res = await fetch('');
|
||
|
return res;
|
||
|
});
|
||
|
|
||
|
// @ts-expect-error async and return sync
|
||
|
onMount(async () => {
|
||
|
return () => {
|
||
|
return 'done';
|
||
|
};
|
||
|
});
|
||
|
|
||
|
// @ts-expect-error async and return async
|
||
|
onMount(async () => {
|
||
|
return async () => {
|
||
|
const res = await fetch('');
|
||
|
return res;
|
||
|
};
|
||
|
});
|
||
|
|
||
|
// @ts-expect-error async and return any
|
||
|
onMount(async () => {
|
||
|
const a: any = null as any;
|
||
|
return a;
|
||
|
});
|