-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
call on_destroy if unmounted called immediately before on_mount
- Loading branch information
Showing
7 changed files
with
113 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* INTERNAL, DO NOT USE. Code may change at any time. | ||
*/ | ||
export interface Fragment { | ||
key: string | null; | ||
first: null; | ||
/* create */ c: () => void; | ||
/* claim */ l: (nodes: any) => void; | ||
/* hydrate */ h: () => void; | ||
/* mount */ m: (target: HTMLElement, anchor: any) => void; | ||
/* update */ p: (ctx: any, dirty: any) => void; | ||
/* measure */ r: () => void; | ||
/* fix */ f: () => void; | ||
/* animate */ a: () => void; | ||
/* intro */ i: (local: any) => void; | ||
/* outro */ o: (local: any) => void; | ||
/* destroy */ d: (detaching: 0 | 1) => void; | ||
} | ||
|
||
export type FragmentFactory = (ctx: any) => Fragment; |
13 changes: 13 additions & 0 deletions
13
test/runtime/samples/await-mount-and-unmount-immediately/Component.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<script> | ||
import { onMount } from 'svelte'; | ||
export let logs; | ||
export let state; | ||
onMount(() => { | ||
logs.push(`mount ${state}`); | ||
return () => { | ||
logs.push(`unmount ${state}`); | ||
}; | ||
}); | ||
</script> | ||
|
||
{state} |
11 changes: 11 additions & 0 deletions
11
test/runtime/samples/await-mount-and-unmount-immediately/_config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export default { | ||
html: 'Loading...', | ||
async test({ assert, component, target, window }) { | ||
const button = target.querySelector('button'); | ||
|
||
await component.test(); | ||
|
||
assert.htmlEqual(target.innerHTML, '1'); | ||
assert.deepEqual(component.logs, ['mount 0', 'unmount 0', 'mount 1']); | ||
} | ||
}; |
36 changes: 36 additions & 0 deletions
36
test/runtime/samples/await-mount-and-unmount-immediately/main.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<script> | ||
import { tick } from 'svelte'; | ||
import Component from './Component.svelte'; | ||
let promise; | ||
let resolve; | ||
let value = 0; | ||
export let logs = []; | ||
async function new_promise() { | ||
promise = new Promise(r => { | ||
resolve = r; | ||
}); | ||
} | ||
async function resolve_promise() { | ||
await Promise.resolve(); | ||
resolve(value++); | ||
} | ||
export async function test() { | ||
resolve_promise(); | ||
await Promise.resolve(); | ||
new_promise(); | ||
resolve_promise(); | ||
return tick(); | ||
} | ||
new_promise(); | ||
</script> | ||
|
||
{#await promise} | ||
Loading... | ||
{:then state} | ||
<Component {state} {logs} /> | ||
{/await} |