-
Notifications
You must be signed in to change notification settings - Fork 44
Adding svelte helper #1172
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
base: main
Are you sure you want to change the base?
Adding svelte helper #1172
Changes from all commits
be4527b
9a12679
1a7b324
a9d7782
8a5487a
c479a95
c822e9d
8781746
18e6f11
52520ef
7dce6a7
9777f5f
27ca702
dfd5929
0faf1df
729aef4
85e765b
9a4591c
61e5125
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
node_modules | ||
|
||
# Output | ||
.output | ||
.vercel | ||
.netlify | ||
.wrangler | ||
/.svelte-kit | ||
/build | ||
|
||
# OS | ||
.DS_Store | ||
Thumbs.db | ||
|
||
# Env | ||
.env | ||
.env.* | ||
!.env.example | ||
!.env.test | ||
|
||
# Vite | ||
vite.config.js.timestamp-* | ||
vite.config.ts.timestamp-* |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
engine-strict=true |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# sv | ||
|
||
Everything you need to build a Svelte project, powered by [`sv`](https://github.com/sveltejs/cli). | ||
|
||
## Creating a project | ||
|
||
If you're seeing this, you've probably already done this step. Congrats! | ||
|
||
```sh | ||
# create a new project in the current directory | ||
npx sv create | ||
|
||
# create a new project in my-app | ||
npx sv create my-app | ||
``` | ||
|
||
## Developing | ||
|
||
Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server: | ||
|
||
```sh | ||
npm run dev | ||
|
||
# or start the server and open the app in a new browser tab | ||
npm run dev -- --open | ||
``` | ||
|
||
## Building | ||
|
||
To create a production version of your app: | ||
|
||
```sh | ||
npm run build | ||
``` | ||
|
||
You can preview the production build with `npm run preview`. | ||
|
||
> To deploy your app, you may need to install an [adapter](https://svelte.dev/docs/kit/adapters) for your target environment. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { registry } from "./registry"; | ||
|
||
export type Registry = typeof registry; | ||
|
||
registry.runServer({ | ||
cors: { | ||
origin: "http://localhost:5173", | ||
}, | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { actor, setup } from "@rivetkit/actor"; | ||
|
||
export const counter = actor({ | ||
onAuth: () => { | ||
// Configure auth here | ||
}, | ||
state: { count: 0 }, | ||
actions: { | ||
increment: (c, x: number) => { | ||
console.log("incrementing by", x); | ||
c.state.count += x; | ||
c.broadcast("newCount", c.state.count); | ||
return c.state.count; | ||
}, | ||
reset: (c) => { | ||
c.state.count = 0; | ||
c.broadcast("newCount", c.state.count); | ||
return c.state.count; | ||
}, | ||
}, | ||
}); | ||
|
||
export const registry = setup({ | ||
use: { counter }, | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"name": "svelte-rivetkit-example", | ||
"private": true, | ||
"version": "0.0.1", | ||
"type": "module", | ||
"scripts": { | ||
"dev": "run-p dev:web dev:api", | ||
"dev:web": "vite dev", | ||
"dev:api": "tsx --watch backend/index.ts", | ||
"build": "vite build", | ||
"preview": "vite preview", | ||
"prepare": "svelte-kit sync || echo ''", | ||
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json", | ||
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch" | ||
}, | ||
"devDependencies": { | ||
"@rivetkit/actor": "workspace:*", | ||
"@rivetkit/svelte": "workspace:*", | ||
"@sveltejs/adapter-auto": "^6.0.0", | ||
"@sveltejs/kit": "^2.22.0", | ||
"@sveltejs/vite-plugin-svelte": "^6.0.0", | ||
"@types/node": "^22.13.9", | ||
"svelte": "^5.0.0", | ||
"svelte-check": "^4.0.0", | ||
"typescript": "^5.0.0", | ||
"vite": "^7.0.4", | ||
"npm-run-all": "^4.1.5", | ||
"tsx": "^3.12.7" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// See https://svelte.dev/docs/kit/types#app.d.ts | ||
// for information about these interfaces | ||
declare global { | ||
namespace App { | ||
// interface Error {} | ||
// interface Locals {} | ||
// interface PageData {} | ||
// interface PageState {} | ||
// interface Platform {} | ||
} | ||
} | ||
|
||
export {}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
%sveltekit.head% | ||
</head> | ||
<body data-sveltekit-preload-data="hover"> | ||
<div style="display: contents">%sveltekit.body%</div> | ||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { createClient, createRivetKit } from "@rivetkit/svelte"; | ||
import type { Registry } from "../../backend"; | ||
|
||
const client = createClient<Registry>(`http://localhost:8080`); | ||
export const { useActor } = createRivetKit(client); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
// place files you want to import through the `$lib` alias in this folder. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const ssr = false; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<script lang="ts"> | ||
import favicon from '$lib/assets/favicon.svg'; | ||
let { children } = $props(); | ||
</script> | ||
|
||
<svelte:head> | ||
<link rel="icon" href={favicon} /> | ||
</svelte:head> | ||
|
||
{@render children?.()} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<script lang="ts"> | ||
import { useActor } from "../lib/actor-client"; | ||
|
||
let eventSub: any; | ||
let count = $state(0); | ||
const counter = useActor({ name: 'counter', key: ['test-counter'] }); | ||
|
||
$effect(()=>{ | ||
console.log('status', counter?.isConnected); | ||
eventSub=counter?.useEvent('newCount', (x: number) => { | ||
console.log('new count event', x); | ||
count=x; | ||
}); | ||
return () => { | ||
eventSub?.unsubscribe(); | ||
}; | ||
//also works | ||
// counter.connection?.on('newCount', (x: number) => { | ||
// console.log('new count event', x); | ||
// count=x; | ||
// }) | ||
}) | ||
const increment = () => { | ||
counter?.connection?.increment(1); | ||
|
||
}; | ||
const reset = () => { | ||
counter?.connection?.reset(); | ||
|
||
}; | ||
|
||
// $inspect is for debugging, but ensure it's used correctly | ||
$inspect('useActor is connected', counter?.isConnected); | ||
</script> | ||
|
||
<div> | ||
<h1>Counter: {count}</h1> | ||
<button onclick={increment}>Increment</button> | ||
<button onclick={reset}>Reset</button> | ||
</div> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# allow crawling everything by default | ||
User-agent: * | ||
Disallow: |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import adapter from "@sveltejs/adapter-auto"; | ||
import { vitePreprocess } from "@sveltejs/vite-plugin-svelte"; | ||
|
||
/** @type {import('@sveltejs/kit').Config} */ | ||
const config = { | ||
// Consult https://svelte.dev/docs/kit/integrations | ||
// for more information about preprocessors | ||
preprocess: vitePreprocess(), | ||
|
||
kit: { | ||
// adapter-auto only supports some environments, see https://svelte.dev/docs/kit/adapter-auto for a list. | ||
// If your environment is not supported, or you settled on a specific environment, switch out the adapter. | ||
// See https://svelte.dev/docs/kit/adapters for more information about adapters. | ||
adapter: adapter(), | ||
alias: { | ||
$: "./src", | ||
"$/*": "./src/*", | ||
$backend: "./backend", | ||
"$backend/*": "./backend/*", | ||
}, | ||
}, | ||
}; | ||
|
||
export default config; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"extends": "./.svelte-kit/tsconfig.json", | ||
"compilerOptions": { | ||
"allowJs": true, | ||
"checkJs": true, | ||
"esModuleInterop": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"resolveJsonModule": true, | ||
"skipLibCheck": true, | ||
"sourceMap": true, | ||
"strict": true, | ||
"moduleResolution": "bundler", | ||
"baseUrl": "./", | ||
"paths": { | ||
"$/": ["./src/"], | ||
"$backend/": ["./backend/"] | ||
} | ||
} | ||
// Path aliases are handled by https://svelte.dev/docs/kit/configuration#alias | ||
// except $lib which is handled by https://svelte.dev/docs/kit/configuration#files | ||
// | ||
// If you want to overwrite includes/excludes, make sure to copy over the relevant includes/excludes | ||
// from the referenced tsconfig.json - TypeScript does not merge them in | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"$schema": "https://turbo.build/schema.json", | ||
"extends": ["//"] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { sveltekit } from "@sveltejs/kit/vite"; | ||
import { defineConfig } from "vite"; | ||
|
||
export default defineConfig({ | ||
plugins: [sveltekit()], | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,5 +37,10 @@ | |
"@hono/node-ws": "^1.1.7", | ||
"esbuild": "^0.25.1" | ||
}, | ||
"packageManager": "[email protected]+sha512.2d92c86b7928dc8284f53494fb4201f983da65f0fb4f0d40baafa5cf628fa31dae3e5968f12466f17df7e97310e30f343a648baea1b9b350685dafafffdf5808" | ||
"packageManager": "[email protected]+sha512.2d92c86b7928dc8284f53494fb4201f983da65f0fb4f0d40baafa5cf628fa31dae3e5968f12466f17df7e97310e30f343a648baea1b9b350685dafafffdf5808", | ||
"pnpm": { | ||
"onlyBuiltDependencies": [ | ||
"esbuild" | ||
] | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _createStarExport(obj) { Object.keys(obj) .filter((key) => key !== "default" && key !== "__esModule") .forEach((key) => { if (exports.hasOwnProperty(key)) { return; } Object.defineProperty(exports, key, {enumerable: true, configurable: true, get: () => obj[key]}); }); }// src/client.ts | ||
var _client = require('@rivetkit/core/client'); _createStarExport(_client); | ||
//# sourceMappingURL=client.cjs.map |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export * from '@rivetkit/core/client'; | ||
import '@rivetkit/core/errors'; | ||
import '@rivetkit/core/log'; | ||
import '@rivetkit/core'; | ||
import '@rivetkit/core/test'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export * from "@rivetkit/core/client"; | ||
import "@rivetkit/core/errors"; | ||
import "@rivetkit/core/log"; | ||
import "@rivetkit/core"; | ||
import "@rivetkit/core/test"; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _createStarExport(obj) { Object.keys(obj) .filter((key) => key !== "default" && key !== "__esModule") .forEach((key) => { if (exports.hasOwnProperty(key)) { return; } Object.defineProperty(exports, key, {enumerable: true, configurable: true, get: () => obj[key]}); }); }// src/errors.ts | ||
var _errors = require('@rivetkit/core/errors'); _createStarExport(_errors); | ||
//# sourceMappingURL=errors.cjs.map |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from '@rivetkit/core/errors'; |
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.
The
onStateChange
function signature has been updated to includeprevState
, but there's a spacing inconsistency in the documentation. For consistency with other function signatures in this file, a space should be added after the first comma:Spotted by Diamond

Is this helpful? React 👍 or 👎 to let us know.