mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-20 22:35:09 +00:00
more tidying up
This commit is contained in:
@@ -115,7 +115,6 @@ export function scroll_state() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function navigate(target: Target, id: number, noscroll?: boolean, hash?: string): Promise<any> {
|
export async function navigate(target: Target, id: number, noscroll?: boolean, hash?: string): Promise<any> {
|
||||||
let scroll: ScrollPosition;
|
|
||||||
if (id) {
|
if (id) {
|
||||||
// popstate or initial navigation
|
// popstate or initial navigation
|
||||||
cid = id;
|
cid = id;
|
||||||
@@ -143,18 +142,16 @@ export async function navigate(target: Target, id: number, noscroll?: boolean, h
|
|||||||
prefetching = null;
|
prefetching = null;
|
||||||
|
|
||||||
const token = current_token = {};
|
const token = current_token = {};
|
||||||
|
|
||||||
const { redirect, page, props, branch } = await loaded;
|
const { redirect, page, props, branch } = await loaded;
|
||||||
|
if (token !== current_token) return; // a secondary navigation happened while we were loading
|
||||||
|
|
||||||
if (redirect) return goto(redirect.location, { replaceState: true });
|
if (redirect) return goto(redirect.location, { replaceState: true });
|
||||||
|
|
||||||
await render(branch, props, page, scroll_history[id], noscroll, hash, token);
|
await render(branch, props, page, scroll_history[id], noscroll, hash);
|
||||||
if (document.activeElement) document.activeElement.blur();
|
if (document.activeElement) document.activeElement.blur();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function render(branch: any[], props: any, page: Page, scroll: ScrollPosition, noscroll: boolean, hash: string, token: {}) {
|
async function render(branch: any[], props: any, page: Page, scroll: ScrollPosition, noscroll: boolean, hash: string) {
|
||||||
if (current_token !== token) return;
|
|
||||||
|
|
||||||
stores.page.set(page);
|
stores.page.set(page);
|
||||||
stores.preloading.set(null);
|
stores.preloading.set(null);
|
||||||
|
|
||||||
@@ -269,15 +266,12 @@ export async function hydrate_target(target: Target): Promise<{
|
|||||||
|
|
||||||
if (redirect) return { redirect };
|
if (redirect) return { redirect };
|
||||||
|
|
||||||
const page_data = {
|
const page = { path, query, params };
|
||||||
path,
|
|
||||||
query,
|
|
||||||
params
|
|
||||||
};
|
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
|
// TODO be nice if this was less of a special case
|
||||||
return {
|
return {
|
||||||
page: page_data,
|
page,
|
||||||
props: {
|
props: {
|
||||||
child: {
|
child: {
|
||||||
component: ErrorComponent,
|
component: ErrorComponent,
|
||||||
@@ -304,7 +298,7 @@ export async function hydrate_target(target: Target): Promise<{
|
|||||||
level = level.props.child;
|
level = level.props.child;
|
||||||
});
|
});
|
||||||
|
|
||||||
return { props, page: page_data, branch };
|
return { props, page, branch };
|
||||||
}
|
}
|
||||||
|
|
||||||
function load_css(chunk: string) {
|
function load_css(chunk: string) {
|
||||||
|
|||||||
Reference in New Issue
Block a user