mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-12 03:05:12 +00:00
update some tests
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
<h1>{letter}</h1>
|
||||
<script context="module">
|
||||
export function preload() {
|
||||
return this.fetch('b.json').then(r => r.json()).then(letter => {
|
||||
return { letter };
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
preload() {
|
||||
return this.fetch('b.json').then(r => r.json()).then(letter => {
|
||||
return { letter };
|
||||
});
|
||||
}
|
||||
};
|
||||
</script>
|
||||
export let letter;
|
||||
</script>
|
||||
|
||||
<h1>{letter}</h1>
|
||||
@@ -1,19 +1,17 @@
|
||||
<button class='del' on:click='del()'>delete</button>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
oncreate() {
|
||||
window.deleted = null;
|
||||
},
|
||||
import { onMount } from 'svelte';
|
||||
|
||||
methods: {
|
||||
del() {
|
||||
fetch(`delete-test/42.json`, { method: 'DELETE' })
|
||||
.then(r => r.json())
|
||||
.then(data => {
|
||||
window.deleted = data;
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
onMount(() => {
|
||||
window.deleted = null;
|
||||
});
|
||||
|
||||
function del() {
|
||||
fetch(`delete-test/42.json`, { method: 'DELETE' })
|
||||
.then(r => r.json())
|
||||
.then(data => {
|
||||
window.deleted = data;
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<button class="del" on:click={del}>delete</button>
|
||||
@@ -1,9 +1,7 @@
|
||||
$&
|
||||
<script context="module">
|
||||
export function preload() {
|
||||
return '$&';
|
||||
}
|
||||
</script>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
preload() {
|
||||
return '$&';
|
||||
}
|
||||
};
|
||||
</script>
|
||||
$&
|
||||
@@ -1,11 +1,13 @@
|
||||
<h1>{message}</h1>
|
||||
<script context="module">
|
||||
export function preload({ query }) {
|
||||
return this.fetch(`credentials/test.json`, {
|
||||
credentials: query.creds
|
||||
}).then(r => r.json());
|
||||
}
|
||||
</script>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
preload({ query }) {
|
||||
return this.fetch(`credentials/test.json`, {
|
||||
credentials: query.creds
|
||||
}).then(r => r.json());
|
||||
}
|
||||
};
|
||||
</script>
|
||||
export let message;
|
||||
</script>
|
||||
|
||||
<h1>{message}</h1>
|
||||
@@ -1,11 +1,13 @@
|
||||
<svelte:component this={Title}/>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
oncreate() {
|
||||
import('./_components/Title.html').then(({ default: Title }) => {
|
||||
this.set({ Title });
|
||||
});
|
||||
}
|
||||
};
|
||||
</script>
|
||||
import { onMount } from 'svelte';
|
||||
|
||||
export let Title;
|
||||
|
||||
onMount(() => {
|
||||
import('./_components/Title.html').then(mod => {
|
||||
Title = mod.default;
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<svelte:component this={Title}/>
|
||||
@@ -1,11 +1,14 @@
|
||||
<h1>{slug} {JSON.stringify(query)}</h1>
|
||||
<script context="module">
|
||||
export function preload({ params }) {
|
||||
return {
|
||||
slug: params.slug
|
||||
};
|
||||
}
|
||||
</script>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
preload({ params }) {
|
||||
return {
|
||||
slug: params.slug
|
||||
};
|
||||
}
|
||||
};
|
||||
</script>
|
||||
export let slug;
|
||||
export let query;
|
||||
</script>
|
||||
|
||||
<h1>{slug} {JSON.stringify(query)}</h1>
|
||||
@@ -1,11 +1,13 @@
|
||||
<h1>{phrase}</h1>
|
||||
<script context="module">
|
||||
export function preload() {
|
||||
return this.fetch('fünke.json').then(r => r.json()).then(phrase => {
|
||||
return { phrase };
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
preload() {
|
||||
return this.fetch('fünke.json').then(r => r.json()).then(phrase => {
|
||||
return { phrase };
|
||||
});
|
||||
}
|
||||
};
|
||||
</script>
|
||||
export let phrase;
|
||||
</script>
|
||||
|
||||
<h1>{phrase}</h1>
|
||||
@@ -1,19 +1,21 @@
|
||||
<h1>{post.title}</h1>
|
||||
<script context="module">
|
||||
export function preload({ params }) {
|
||||
const { slug } = params;
|
||||
|
||||
return this.fetch(`blog/${slug}.json`).then(r => {
|
||||
return r.json().then(data => {
|
||||
if (r.status !== 200) {
|
||||
this.error(r.status, data);
|
||||
}
|
||||
|
||||
return data;
|
||||
});
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
preload({ params }) {
|
||||
const { slug } = params;
|
||||
export let post;
|
||||
</script>
|
||||
|
||||
return this.fetch(`blog/${slug}.json`).then(r => {
|
||||
return r.json().then(data => {
|
||||
if (r.status !== 200) {
|
||||
this.error(r.status, data);
|
||||
}
|
||||
|
||||
return data;
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
</script>
|
||||
<h1>{post.title}</h1>
|
||||
@@ -1,7 +1,5 @@
|
||||
<script>
|
||||
export default {
|
||||
preload() {
|
||||
this.error(420, 'Enhance your calm');
|
||||
}
|
||||
};
|
||||
<script context="module">
|
||||
export function preload() {
|
||||
this.error(420, 'Enhance your calm');
|
||||
}
|
||||
</script>
|
||||
@@ -1,7 +1,5 @@
|
||||
<script>
|
||||
export default {
|
||||
preload() {
|
||||
throw new Error('nope');
|
||||
}
|
||||
};
|
||||
<script context="module">
|
||||
export function preload() {
|
||||
throw new Error('nope');
|
||||
}
|
||||
</script>
|
||||
@@ -1,11 +1,13 @@
|
||||
<h1>{post.title}</h1>
|
||||
<script context="module">
|
||||
export function preload({ params }) {
|
||||
return this.fetch(`blog/${params.slug}.json`).then(r => r.json()).then(post => {
|
||||
return { post };
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
preload({ params }) {
|
||||
return this.fetch(`blog/${params.slug}.json`).then(r => r.json()).then(post => {
|
||||
return { post };
|
||||
});
|
||||
}
|
||||
};
|
||||
</script>
|
||||
export let post;
|
||||
</script>
|
||||
|
||||
<h1>{post.title}</h1>
|
||||
@@ -1,15 +1,17 @@
|
||||
<script context="module">
|
||||
export function preload() {
|
||||
return this.fetch('blog.json').then(r => r.json()).then(posts => {
|
||||
return { posts };
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<script>
|
||||
export let posts;
|
||||
</script>
|
||||
|
||||
<h1>blog</h1>
|
||||
|
||||
{#each posts as post}
|
||||
<p><a href="blog/{post.slug}">{post.title}</a></p>
|
||||
{/each}
|
||||
|
||||
<script>
|
||||
export default {
|
||||
preload() {
|
||||
return this.fetch('blog.json').then(r => r.json()).then(posts => {
|
||||
return { posts };
|
||||
});
|
||||
}
|
||||
};
|
||||
</script>
|
||||
{/each}
|
||||
@@ -1,11 +1,13 @@
|
||||
<h1>{letter}</h1>
|
||||
<script context="module">
|
||||
export function preload() {
|
||||
return this.fetch('b.json').then(r => r.json()).then(letter => {
|
||||
return { letter };
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
preload() {
|
||||
return this.fetch('b.json').then(r => r.json()).then(letter => {
|
||||
return { letter };
|
||||
});
|
||||
}
|
||||
};
|
||||
</script>
|
||||
export let letter;
|
||||
</script>
|
||||
|
||||
<h1>{letter}</h1>
|
||||
@@ -1,20 +1,18 @@
|
||||
<span>z: {segment} {count}</span>
|
||||
<a href="foo/bar/qux">click me</a>
|
||||
|
||||
<script>
|
||||
<script context="module">
|
||||
import counts from '../_counts.js';
|
||||
|
||||
export default {
|
||||
preload() {
|
||||
return {
|
||||
count: counts.z += 1
|
||||
};
|
||||
},
|
||||
export function preload() {
|
||||
return {
|
||||
count: counts.z += 1
|
||||
};
|
||||
}
|
||||
</script>
|
||||
|
||||
oncreate() {
|
||||
this.set({
|
||||
segment: this.get().params.z
|
||||
});
|
||||
}
|
||||
};
|
||||
</script>
|
||||
<script>
|
||||
export let params;
|
||||
export let count;
|
||||
export let segment = params.z;
|
||||
</script>
|
||||
|
||||
<span>z: {segment} {count}</span>
|
||||
<a href="foo/bar/qux">click me</a>
|
||||
@@ -1,22 +1,21 @@
|
||||
<script context="module">
|
||||
import counts from '../_counts.js';
|
||||
|
||||
export function preload() {
|
||||
return {
|
||||
count: counts.y += 1
|
||||
};
|
||||
}
|
||||
</script>
|
||||
|
||||
<script>
|
||||
export let params;
|
||||
export let count;
|
||||
export let child;
|
||||
export let segment = params.y;
|
||||
</script>
|
||||
|
||||
<span>y: {segment} {count}</span>
|
||||
<svelte:component this={child.component} {...child.props}/>
|
||||
|
||||
<span>child segment: {child.segment}</span>
|
||||
|
||||
<script>
|
||||
import counts from '../_counts.js';
|
||||
|
||||
export default {
|
||||
preload() {
|
||||
return {
|
||||
count: counts.y += 1
|
||||
};
|
||||
},
|
||||
|
||||
oncreate() {
|
||||
this.set({
|
||||
segment: this.get().params.y
|
||||
});
|
||||
}
|
||||
};
|
||||
</script>
|
||||
<span>child segment: {child.segment}</span>
|
||||
@@ -1,15 +1,19 @@
|
||||
<script context="module">
|
||||
export function preload() {
|
||||
return {
|
||||
rootPreloadFunctionRan: true
|
||||
};
|
||||
}
|
||||
</script>
|
||||
|
||||
<script>
|
||||
export let preloading;
|
||||
export let child;
|
||||
export let rootPreloadFunctionRan;
|
||||
</script>
|
||||
|
||||
{#if preloading}
|
||||
<progress class='preloading-progress' value=0.5/>
|
||||
{/if}
|
||||
|
||||
<svelte:component this={child.component} {rootPreloadFunctionRan} {...child.props}/>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
preload() {
|
||||
return {
|
||||
rootPreloadFunctionRan: true
|
||||
};
|
||||
}
|
||||
};
|
||||
</script>
|
||||
<svelte:component this={child.component} {rootPreloadFunctionRan} {...child.props}/>
|
||||
@@ -1,17 +1,19 @@
|
||||
<h1>{foo.bar()}</h1>
|
||||
<script context="module">
|
||||
export function preload() {
|
||||
class Foo {
|
||||
bar() {
|
||||
return 42;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
foo: new Foo()
|
||||
};
|
||||
}
|
||||
</script>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
preload() {
|
||||
class Foo {
|
||||
bar() {
|
||||
return 42;
|
||||
}
|
||||
}
|
||||
export let foo;
|
||||
</script>
|
||||
|
||||
return {
|
||||
foo: new Foo()
|
||||
};
|
||||
}
|
||||
};
|
||||
</script>
|
||||
<h1>{foo.bar()}</h1>
|
||||
@@ -1,11 +1,13 @@
|
||||
<h1>{set.has('x')}</h1>
|
||||
<script context="module">
|
||||
export function preload() {
|
||||
return {
|
||||
set: new Set(['x'])
|
||||
};
|
||||
}
|
||||
</script>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
preload() {
|
||||
return {
|
||||
set: new Set(['x'])
|
||||
};
|
||||
}
|
||||
};
|
||||
</script>
|
||||
export let set;
|
||||
</script>
|
||||
|
||||
<h1>{set.has('x')}</h1>
|
||||
@@ -1,15 +1,13 @@
|
||||
<h1>This page should never render</h1>
|
||||
<script context="module">
|
||||
export function preload() {
|
||||
return new Promise(fulfil => {
|
||||
if (typeof window !== 'undefined') {
|
||||
window.fulfil = fulfil;
|
||||
} else {
|
||||
fulfil({});
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
preload() {
|
||||
return new Promise(fulfil => {
|
||||
if (typeof window !== 'undefined') {
|
||||
window.fulfil = fulfil;
|
||||
} else {
|
||||
fulfil({});
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
</script>
|
||||
<h1>This page should never render</h1>
|
||||
@@ -1,9 +1,7 @@
|
||||
<h1>unredirected</h1>
|
||||
<script context="module">
|
||||
export function preload() {
|
||||
this.redirect(301, 'redirect-to');
|
||||
}
|
||||
</script>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
preload() {
|
||||
this.redirect(301, 'redirect-to');
|
||||
}
|
||||
};
|
||||
</script>
|
||||
<h1>unredirected</h1>
|
||||
@@ -1,9 +1,7 @@
|
||||
<h1>unredirected</h1>
|
||||
<script context="module">
|
||||
export function preload() {
|
||||
this.redirect(301, 'https://example.com');
|
||||
}
|
||||
</script>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
preload() {
|
||||
this.redirect(301, 'https://example.com');
|
||||
}
|
||||
};
|
||||
</script>
|
||||
<h1>unredirected</h1>
|
||||
@@ -1,9 +1,7 @@
|
||||
<h1>unredirected</h1>
|
||||
<script context="module">
|
||||
export function preload() {
|
||||
this.redirect(301, '/');
|
||||
}
|
||||
</script>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
preload() {
|
||||
this.redirect(301, '/');
|
||||
}
|
||||
};
|
||||
</script>
|
||||
<h1>unredirected</h1>
|
||||
@@ -1,3 +1,13 @@
|
||||
<script>
|
||||
import { onMount } from 'svelte';
|
||||
|
||||
export let barLink = false;
|
||||
|
||||
onMount(() => {
|
||||
barLink = true
|
||||
});
|
||||
</script>
|
||||
|
||||
<a href="tall-page#foo">scroll to foo</a>
|
||||
<div style="height: 9999px"></div>
|
||||
|
||||
@@ -7,18 +17,4 @@
|
||||
{#if barLink}
|
||||
<a href="another-tall-page#bar">link</a>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
barLink: false
|
||||
};
|
||||
},
|
||||
|
||||
oncreate() {
|
||||
this.set({ barLink: true })
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</div>
|
||||
Reference in New Issue
Block a user