mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-13 03:25:24 +00:00
give each app its own page, preloading and session stores, using context
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import { writable } from 'svelte/store.mjs';
|
||||
import App from '@sapper/internal/App.svelte';
|
||||
import { stores } from '@sapper/internal/shared';
|
||||
import { Root, root_preload, ErrorComponent, ignore, components, routes } from '@sapper/internal/manifest-client';
|
||||
import { root_preload, ErrorComponent, ignore, components, routes } from '@sapper/internal/manifest-client';
|
||||
import {
|
||||
Target,
|
||||
ScrollPosition,
|
||||
@@ -24,12 +23,16 @@ let current_token: {};
|
||||
let root_preloaded: Promise<any>;
|
||||
let current_branch = [];
|
||||
|
||||
const session = writable(initial_data && initial_data.session);
|
||||
const stores = {
|
||||
page: writable({}),
|
||||
preloading: writable(null),
|
||||
session: writable(initial_data && initial_data.session)
|
||||
};
|
||||
|
||||
let $session;
|
||||
let session_dirty: boolean;
|
||||
|
||||
session.subscribe(async value => {
|
||||
stores.session.subscribe(async value => {
|
||||
$session = value;
|
||||
|
||||
if (!ready) return;
|
||||
@@ -216,7 +219,11 @@ async function render(redirect: Redirect, branch: any[], props: any, page: Page)
|
||||
if (root_component) {
|
||||
root_component.$set(props);
|
||||
} else {
|
||||
props.session = session;
|
||||
props.stores = {
|
||||
page: { subscribe: stores.page.subscribe },
|
||||
preloading: { subscribe: stores.preloading.subscribe },
|
||||
session: stores.session
|
||||
};
|
||||
props.level0 = {
|
||||
props: await root_preloaded
|
||||
};
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
import { getContext } from 'svelte';
|
||||
import { CONTEXT_KEY, stores } from '@sapper/internal/shared';
|
||||
import { CONTEXT_KEY } from '@sapper/internal/shared';
|
||||
|
||||
export const preloading = { subscribe: stores.preloading.subscribe };
|
||||
export const page = { subscribe: stores.page.subscribe };
|
||||
|
||||
export const getSession = () => getContext(CONTEXT_KEY);
|
||||
export const stores = () => getContext(CONTEXT_KEY);
|
||||
|
||||
export { default as start } from './start/index';
|
||||
export { default as goto } from './goto/index';
|
||||
|
||||
@@ -204,10 +204,22 @@ export function get_page_handler(
|
||||
});
|
||||
|
||||
const props = {
|
||||
stores: {
|
||||
page: {
|
||||
subscribe: writable({
|
||||
path: req.path,
|
||||
query: req.query,
|
||||
params
|
||||
}).subscribe
|
||||
},
|
||||
preloading: {
|
||||
subscribe: writable(null).subscribe
|
||||
},
|
||||
session: writable(session)
|
||||
},
|
||||
segments: layout_segments,
|
||||
status: error ? status : 200,
|
||||
error: error ? error instanceof Error ? error : { message: error } : null,
|
||||
session: writable(session),
|
||||
level0: {
|
||||
props: preloaded[0]
|
||||
},
|
||||
@@ -231,12 +243,6 @@ export function get_page_handler(
|
||||
}
|
||||
}
|
||||
|
||||
stores.page.set({
|
||||
path: req.path,
|
||||
query: req.query,
|
||||
params: params
|
||||
});
|
||||
|
||||
const { html, head, css } = App.render(props);
|
||||
|
||||
const serialized = {
|
||||
|
||||
Reference in New Issue
Block a user