-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathApp.svelte
58 lines (50 loc) · 1.75 KB
/
App.svelte
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<script>
import Loadable from '../../Loadable.svelte'
const getDelayedLoader =
(delay = 3000) =>
() =>
new Promise((resolve) =>
setTimeout(() => resolve(import('./AsyncComponent.svelte')), delay),
)
const getFailureLoader =
(delay = 3000) =>
() =>
new Promise((resolve, reject) =>
setTimeout(() => reject(new Error('Some error')), delay),
)
</script>
<h1>This one will work</h1>
<Loadable loader={() => import('./AsyncComponent.svelte')} delay="300">
<div slot="loading">Loading and blessed to succeed...</div>
</Loadable>
<h1>This one will not</h1>
<Loadable loader={getFailureLoader(5000)} timeout="3000">
<div slot="loading">Loading but doomed to failed...</div>
<div slot="timeout">This is taking a while...</div>
<div slot="error" let:error let:retry>
{error}
<br />
<button on:click={retry}>Try again</button>
</div>
</Loadable>
<h1>This one will work with custom props by using the "default" slots</h1>
<Loadable loader={getDelayedLoader()} let:component>
<div slot="loading">Loading and blessed to succeed...</div>
<svelte:component this={component} customProp={true} />
</Loadable>
<h1>
This one will work with custom props by passing props to the Loadable
component
</h1>
<Loadable loader={getDelayedLoader()} customProp={true}>
<div slot="loading">Loading and blessed to succeed...</div>
</Loadable>
<h1>This one will timeout</h1>
<Loadable loader={getDelayedLoader(7000)} timeout="3000">
<div slot="loading">Loading...</div>
<div slot="timeout">This is taking a little bit too long...</div>
</Loadable>
<h1>This one will work</h1>
<Loadable loader={() => import('./AsyncComponent.svelte')} delay="300">
<div slot="loading">Loading and blessed to succeed...</div>
</Loadable>