File tree 9 files changed +80
-1
lines changed
9 files changed +80
-1
lines changed Original file line number Diff line number Diff line change 11
11
"lint" : " prettier --plugin-search-dir . --check ." ,
12
12
"format" : " prettier --plugin-search-dir . --write ."
13
13
},
14
+ "dependencies" : {
15
+ "telefunc" : " 0.1.36"
16
+ },
14
17
"devDependencies" : {
15
18
"@sveltejs/adapter-auto" : " next" ,
16
19
"@sveltejs/kit" : " next" ,
Original file line number Diff line number Diff line change
1
+ export const database = {
2
+ value : 42
3
+ } ;
Original file line number Diff line number Diff line change
1
+ import { database } from '$lib/database' ;
2
+
3
+ export { load } ;
4
+
5
+ // For the page's initial data, we use SvelteKit instead of Telefunc; see https://telefunc.com/svelte-kit#initial-page-data
6
+ const load : import ( './$types' ) . PageServerLoad = async ( ) => {
7
+ const { value } = database ;
8
+ return {
9
+ value
10
+ } ;
11
+ } ;
Original file line number Diff line number Diff line change
1
+ <script >
2
+ import Counter from ' ./Counter.svelte' ;
3
+ /** @type {import('./$types').PageData} */
4
+ export let data;
5
+ </script >
6
+
1
7
<h1 >Welcome to SvelteKit</h1 >
2
8
<p >Visit <a href =" https://kit.svelte.dev" >kit.svelte.dev</a > to read the documentation</p >
9
+ <p ><Counter count ={data .value } /></p >
10
+ <p >Refresh the page and observe that the counter value is preserved.</p >
Original file line number Diff line number Diff line change
1
+ <script lang =" ts" >
2
+ import { onCounterIncrement } from ' ./Counter.telefunc' ;
3
+ export let count: number ;
4
+ </script >
5
+
6
+ <div class =" counter" >
7
+ <span >Counter: {count }</span >
8
+ <button on:click ={async () => {count = await onCounterIncrement (- 1 )}}>-1</button >
9
+ <button on:click ={async () => {count = await onCounterIncrement (+ 1 )}}>+1</button >
10
+ <button on:click ={async () => {count = await onCounterIncrement (- 10 )}}>-10</button >
11
+ <button on:click ={async () => {count = await onCounterIncrement (+ 10 )}}>+10</button >
12
+ </div >
Original file line number Diff line number Diff line change
1
+ import { database } from '$lib/database' ;
2
+
3
+ export { onCounterIncrement } ;
4
+
5
+ // Telefunc ensures that `diff` is a `number` at runtime, see https://telefunc.com/shield#typescript
6
+ async function onCounterIncrement ( diff : number ) {
7
+ database . value = database . value + diff ;
8
+ return database . value ;
9
+ }
Original file line number Diff line number Diff line change
1
+ import { telefunc } from 'telefunc' ;
2
+ import type { RequestHandler } from './$types' ;
3
+
4
+ const GET : RequestHandler = async ( event ) => {
5
+ const response = await telefunc ( {
6
+ url : event . request . url ,
7
+ method : event . request . method ,
8
+ body : await event . request . text ( ) ,
9
+ context : {
10
+ // We pass the `context` object here, see https://telefunc.com/getContext
11
+ someContext : 'hello'
12
+ }
13
+ } ) ;
14
+ return new Response ( response . body , {
15
+ headers : new Headers ( { contentType : response . contentType } ) ,
16
+ status : response . statusCode
17
+ } ) ;
18
+ } ;
19
+
20
+ export { GET , GET as POST } ;
Original file line number Diff line number Diff line change
1
+ import 'telefunc' ;
2
+
3
+ declare module 'telefunc' {
4
+ namespace Telefunc {
5
+ interface Context {
6
+ /* Globally define the type of the `context` object here, see https://telefunc.com/getContext#typescript
7
+ * For example:
8
+ user: null | { id: number, name: string }
9
+ */
10
+ }
11
+ }
12
+ }
Original file line number Diff line number Diff line change 1
1
import { sveltekit } from '@sveltejs/kit/vite' ;
2
2
import type { UserConfig } from 'vite' ;
3
+ import { telefunc } from 'telefunc/vite' ;
3
4
4
5
const config : UserConfig = {
5
- plugins : [ sveltekit ( ) ]
6
+ plugins : [ sveltekit ( ) , telefunc ( ) ]
6
7
} ;
7
8
8
9
export default config ;
You can’t perform that action at this time.
0 commit comments