Skip to content

Commit

Permalink
independent page type (#4076)
Browse files Browse the repository at this point in the history
* separate page object to its own type

* add params generic

* add changeset

* add `export` keyword for consistency

* move Page to main types

* move Navigation type

* changeset

Co-authored-by: Rich Harris <[email protected]>
  • Loading branch information
ignatiusmb and Rich-Harris authored Feb 24, 2022
1 parent c1bf43e commit 11b4d97
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 9 deletions.
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

0 comments on commit 11b4d97

Please sign in to comment.