Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

independent page type #4076

Merged
merged 8 commits into from
Feb 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/serious-panthers-sing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

Expose Navigation type
5 changes: 5 additions & 0 deletions .changeset/stupid-beds-prove.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

add new `Page` type
13 changes: 4 additions & 9 deletions packages/kit/types/ambient.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ declare module '$app/paths' {

declare module '$app/stores' {
import { Readable, Writable } from 'svelte/store';
type Navigating = { from: URL; to: URL };
import { Navigation, Page } from '@sveltejs/kit';

/**
* A convenience function around `getContext` that returns `{ navigating, page, session }`.
Expand All @@ -117,22 +117,17 @@ declare module '$app/stores' {
session: Writable<App.Session>;
updated: typeof updated;
};

/**
* A readable store whose value contains page data.
*/
export const page: Readable<{
url: URL;
params: Record<string, string>;
stuff: App.Stuff;
status: number;
error: Error | null;
}>;
export const page: Readable<Page>;
/**
* A readable store.
* When navigating starts, its value is `{ from: URL, to: URL }`
* When navigating finishes, its value reverts to `null`.
*/
export const navigating: Readable<Navigating | null>;
export const navigating: Readable<Navigation | null>;
/**
* A writable store whose initial value is whatever was returned from `getSession`.
* It can be written to, but this will not cause changes to persist on the server — this is something you must implement yourself.
Expand Down
13 changes: 13 additions & 0 deletions packages/kit/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,19 @@ export interface LoadOutput<Props = Record<string, any>> {
maxage?: number;
}

export interface Navigation {
from: URL;
to: URL;
}

export interface Page<Params extends Record<string, string> = Record<string, string>> {
url: URL;
params: Params;
stuff: App.Stuff;
status: number;
error: Error | null;
}

export interface Prerendered {
pages: Map<
string,
Expand Down