move all page info to app-level stores

This commit is contained in:
Rich Harris
2019-02-01 22:28:47 -05:00
parent 7ba1a0a9fa
commit 548de702ac
17 changed files with 135 additions and 154 deletions

View File

@@ -1 +1,5 @@
<h1>{params.slug.toUpperCase()}</h1>
<script>
import { page } from '@sapper/app';
</script>
<h1>{$page.params.slug.toUpperCase()}</h1>

View File

@@ -1 +1,5 @@
<h1>{JSON.stringify(query)}</h1>
<script>
import { page } from '@sapper/app';
</script>
<h1>{JSON.stringify($page.query)}</h1>

View File

@@ -7,8 +7,8 @@
</script>
<script>
import { page } from '@sapper/app';
export let slug;
export let query;
</script>
<h1>{slug} {JSON.stringify(query)}</h1>
<h1>{slug} {JSON.stringify($page.query)}</h1>

View File

@@ -2,6 +2,11 @@ import * as sapper from '@sapper/app';
window.start = () => sapper.start({
target: document.querySelector('#sapper')
}).catch(err => {
console.error(`OH NO! ${err.message}`);
throw err;
}).then(() => {
console.log(`STARTED`);
});
window.prefetchRoutes = () => sapper.prefetchRoutes();

View File

@@ -9,10 +9,10 @@
</script>
<script>
export let params;
import { page } from '@sapper/app';
export let count;
export let segment = params.z;
</script>
<span>z: {segment} {count}</span>
<span>z: {$page.params.z} {count}</span>
<a href="foo/bar/qux">click me</a>

View File

@@ -9,13 +9,13 @@
</script>
<script>
export let params;
import { page } from '@sapper/app';
export let count;
export let child;
export let segment = params.y;
</script>
<span>y: {segment} {count}</span>
<span>y: {$page.params.y} {count}</span>
<svelte:component this={child.component} {...child.props}/>
<span>child segment: {child.segment}</span>

View File

@@ -26,10 +26,18 @@ describe('layout', function() {
it('only recreates components when necessary', async () => {
await page.goto(`${base}/foo/bar/baz`);
await start();
const text1 = String(await page.evaluate(() => document.querySelector('#sapper').textContent));
assert.deepEqual(text1.split('\n').filter(Boolean), [
assert.deepEqual(text1.split('\n').filter(Boolean).map(str => str.trim()), [
'y: bar 1',
'z: baz 1',
'click me',
'child segment: baz'
]);
await start();
const text2 = String(await page.evaluate(() => document.querySelector('#sapper').textContent));
assert.deepEqual(text2.split('\n').filter(Boolean).map(str => str.trim()), [
'y: bar 1',
'z: baz 1',
'click me',
@@ -39,8 +47,8 @@ describe('layout', function() {
await page.click('[href="foo/bar/qux"]');
await wait(50);
const text2 = String(await page.evaluate(() => document.querySelector('#sapper').textContent));
assert.deepEqual(text2.split('\n').filter(Boolean), [
const text3 = String(await page.evaluate(() => document.querySelector('#sapper').textContent));
assert.deepEqual(text3.split('\n').filter(Boolean).map(str => str.trim()), [
'y: bar 1',
'z: qux 2',
'click me',

View File

@@ -1 +1,5 @@
<h1>{params.slug}</h1>
<script>
import { page } from '@sapper/app';
</script>
<h1>{$page.params.slug}</h1>