-
Notifications
You must be signed in to change notification settings - Fork 472
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
[Svelte] Improve typescript types + minor fixes #1881
Changes from 5 commits
858f520
aac53d4
cafa16e
e14cfb8
ea6cb40
19c0efc
eb00eea
0c3809f
5187a68
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,8 +5,7 @@ | |
"description": "The Svelte adapter for Inertia.js", | ||
"contributors": [ | ||
"Jonathan Reinink <[email protected]>", | ||
"Pedro Borges <[email protected]>", | ||
"Dmytro Morozov <[email protected]>" | ||
"Pedro Borges <[email protected]>" | ||
], | ||
"homepage": "https://inertiajs.com/", | ||
"repository": { | ||
|
@@ -35,16 +34,17 @@ | |
"svelte": "^3.20.0 || ^4.0.0" | ||
}, | ||
"devDependencies": { | ||
"axios": "^1.6.8", | ||
"@sveltejs/adapter-auto": "^3.2.0", | ||
"@sveltejs/kit": "^2.5.5", | ||
"@sveltejs/package": "^2.3.0", | ||
"@sveltejs/vite-plugin-svelte": "^3.0.2", | ||
"publint": "^0.2.7", | ||
"svelte": "^4.2.12", | ||
"svelte-check": "^3.6.8", | ||
"@sveltejs/kit": "^2.5.7", | ||
"@sveltejs/package": "^2.3.1", | ||
"@sveltejs/vite-plugin-svelte": "^3.1.0", | ||
"publint": "^0.1.16", | ||
"svelte": "^4.2.16", | ||
"svelte-check": "^3.7.1", | ||
"tslib": "^2.6.2", | ||
"typescript": "^5.4.3", | ||
"vite": "^5.2.7" | ||
"typescript": "^5.4.5", | ||
"vite": "^5.2.11" | ||
}, | ||
"exports": { | ||
".": { | ||
|
@@ -56,16 +56,9 @@ | |
"svelte": "./dist/server.js" | ||
} | ||
}, | ||
"import": "./dist/index.js", | ||
"svelte": "./dist/index.js", | ||
"types": "./dist/index.d.ts", | ||
"type": "module", | ||
"typesVersions": { | ||
">4.0": { | ||
".": [ | ||
"./dist/index.d.ts" | ||
] | ||
} | ||
}, | ||
"dependencies": { | ||
"@inertiajs/core": "1.2.0", | ||
"lodash": "^4.5.0" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
<script context="module" lang="ts"> | ||
import type { PageProps } from '@inertiajs/core' | ||
import type { InertiaComponentType } from '../types' | ||
import type { ComponentType } from 'svelte' | ||
|
||
type RenderProps = { | ||
component: InertiaComponentType | ||
component: ComponentType | ||
props?: PageProps | ||
children?: RenderProps[] | ||
} | null | ||
|
||
export const h = (component: InertiaComponentType, props?: PageProps, children?: RenderProps[]): RenderProps => { | ||
export const h = (component: ComponentType, props?: PageProps, children?: RenderProps[]): RenderProps => { | ||
return { | ||
component, | ||
...(props ? { props } : {}), | ||
|
@@ -20,21 +20,18 @@ | |
<script lang="ts"> | ||
import store from '../store' | ||
|
||
export let component: InertiaComponentType | ||
export let component: ComponentType | ||
export let props: PageProps = {} | ||
export let children: RenderProps[] = [] | ||
|
||
let prev = component | ||
let key = new Date().getTime() | ||
|
||
function updateKey(component: InertiaComponentType) { | ||
if (prev !== component) { | ||
prev = component | ||
key = new Date().getTime() | ||
let prevComponent: ComponentType | ||
let key: number | ||
$: { | ||
jamesst20 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (prevComponent !== component) { | ||
key = Date.now() | ||
prevComponent = component | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prior to the typescript merge we had
and with the typescript merge we are now having
While it looks like to be the same, it ain't. Everything between ${...} is reactive and is able to trigger state update unlike when it's wrapped into a method. Maybe it doesn't matter, however I don't see any justification for that change |
||
|
||
$: updateKey(component) | ||
</script> | ||
|
||
{#if $store.component} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,15 @@ | ||
<script lang="ts"> | ||
<script context="module" lang="ts"> | ||
import type { Page } from '@inertiajs/core' | ||
export type SSRProps = { id: string; initialPage: Page } | ||
</script> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No changes here. Exporting the types to use in createInertiaApp for the SSR instead of casting to any for better typing. |
||
|
||
<script lang="ts"> | ||
import App from './App.svelte' | ||
|
||
export let id: string | ||
export let initialPage: Page | ||
interface $$Props extends SSRProps {} | ||
|
||
export let id: $$Props['id'] | ||
export let initialPage: $$Props['initialPage'] | ||
</script> | ||
|
||
<div data-server-rendered="true" {id} data-page={JSON.stringify(initialPage)}> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,8 @@ | ||
import type { PageProps } from '@inertiajs/core' | ||
import type { ComponentType } from 'svelte' | ||
|
||
export type ComponentResolver = (name: string) => ComponentType | Promise<ComponentType> | ||
export type ComponentResolver = (name: string) => ResolvedComponent | Promise<ResolvedComponent> | ||
|
||
export interface InertiaComponentType extends ComponentType { | ||
default: InertiaComponentType | ||
layout: InertiaComponentType | ||
props: PageProps | ||
export type ResolvedComponent = { | ||
default?: ComponentType | ||
layout?: ComponentType | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does nothing