Compare commits
3 Commits
1557a14879
...
08f04e09d4
| Author | SHA1 | Date | |
|---|---|---|---|
| 08f04e09d4 | |||
| 9f1fc1c179 | |||
| 29ab81bfc1 |
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -1 +1,2 @@
|
||||||
node_modules/
|
node_modules/
|
||||||
|
.claude/
|
||||||
|
|
@ -25,7 +25,7 @@
|
||||||
|
|
||||||
"kleur": ["kleur@4.1.5", "", {}, "sha512-o+NO+8WrRiQEE4/7nwRJhN1HWpVmJm511pBHUxPLtp0BUISzlBplORYSmTclCnJvQq2tKu/sgl3xVpkc7ZWuQQ=="],
|
"kleur": ["kleur@4.1.5", "", {}, "sha512-o+NO+8WrRiQEE4/7nwRJhN1HWpVmJm511pBHUxPLtp0BUISzlBplORYSmTclCnJvQq2tKu/sgl3xVpkc7ZWuQQ=="],
|
||||||
|
|
||||||
"pyre": ["pyre@file:..", { "dependencies": { "hype": "git+https://git.nose.space/defunkt/hype" }, "devDependencies": { "@types/bun": "latest" }, "peerDependencies": { "hono": "*", "typescript": "^5" } }],
|
"pyre": ["pyre@file:..", { "dependencies": { "hype": "git+https://git.nose.space/defunkt/hype" }, "devDependencies": { "@types/bun": "latest" }, "peerDependencies": { "typescript": "^5" } }],
|
||||||
|
|
||||||
"typescript": ["typescript@5.9.3", "", { "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" } }, "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw=="],
|
"typescript": ["typescript@5.9.3", "", { "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" } }, "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw=="],
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,6 @@
|
||||||
import { render } from 'hono/jsx/dom'
|
import { render } from 'hono/jsx/dom' // needed to use the same hono/jsx as the frontend
|
||||||
import { setup } from 'pyre/client'
|
import { setup } from 'pyre/client'
|
||||||
import type { Game } from '../types'
|
import type { Game } from '../types'
|
||||||
import Board from './board'
|
import Board from './board'
|
||||||
|
|
||||||
const root = document.getElementById('root')!
|
setup<Game>(render, game => <Board game={game} />)
|
||||||
|
|
||||||
setup<Game>(game => {
|
|
||||||
render(game ? <Board game={game} /> : <h1>Loading...</h1>, root)
|
|
||||||
})
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
"module": "src/index.ts",
|
"module": "src/index.ts",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"exports": {
|
"exports": {
|
||||||
"./client": "./src/client.ts",
|
"./client": "./src/client/index.ts",
|
||||||
"./server": "./src/server/index.tsx"
|
"./server": "./src/server/index.tsx"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|
@ -16,7 +16,6 @@
|
||||||
"hype": "git+https://git.nose.space/defunkt/hype"
|
"hype": "git+https://git.nose.space/defunkt/hype"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "bun run src/server/index.tsx",
|
"check": "bunx tsc --noEmit"
|
||||||
"dev": "bun run --hot src/server/index.tsx"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
export { setup } from '#setup'
|
|
||||||
export { send, gameId } from '#websocket'
|
|
||||||
export { sessionId } from '#session'
|
|
||||||
3
src/client/index.ts
Normal file
3
src/client/index.ts
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
export { setup } from './setup'
|
||||||
|
export { send, gameId } from './websocket'
|
||||||
|
export { sessionId } from './session'
|
||||||
|
|
@ -1,13 +0,0 @@
|
||||||
import { initWebsocket, onUpdate } from '#websocket'
|
|
||||||
|
|
||||||
export function setup<G>(onRender: (game: G | undefined) => void) {
|
|
||||||
let game: G | undefined = undefined
|
|
||||||
|
|
||||||
onUpdate((newGame: G) => {
|
|
||||||
game = newGame
|
|
||||||
onRender(game)
|
|
||||||
})
|
|
||||||
|
|
||||||
initWebsocket()
|
|
||||||
onRender(game)
|
|
||||||
}
|
|
||||||
18
src/client/setup.tsx
Normal file
18
src/client/setup.tsx
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
import { type Child, render as renderJsx } from 'hono/jsx/dom'
|
||||||
|
import { initWebsocket, onUpdate } from './websocket'
|
||||||
|
|
||||||
|
const root = document.getElementById('root')!
|
||||||
|
|
||||||
|
export function setup<G>(render: typeof renderJsx, onRender: (game: G) => Child) {
|
||||||
|
let game: G | undefined = undefined
|
||||||
|
|
||||||
|
onUpdate((newGame: G) => {
|
||||||
|
game = newGame
|
||||||
|
render(game ? onRender(game) : <Loading />, root)
|
||||||
|
})
|
||||||
|
|
||||||
|
initWebsocket()
|
||||||
|
render(game ? onRender(game) : <Loading />, root)
|
||||||
|
}
|
||||||
|
|
||||||
|
const Loading = () => <h1>Loading...</h1>
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import type { Message } from '@types'
|
import type { Message } from '../shared/types'
|
||||||
import { sessionId } from '#session'
|
import { sessionId } from './session'
|
||||||
|
|
||||||
const MAX_RETRIES = 5
|
const MAX_RETRIES = 5
|
||||||
let retries = 0
|
let retries = 0
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ const GIT_HASH = process.env.RENDER_GIT_COMMIT?.slice(0, 7)
|
||||||
export default () => <>
|
export default () => <>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<title>hype</title>
|
<title>🔥 pyre</title>
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<meta name="color-scheme" content="light dark" />
|
<meta name="color-scheme" content="light dark" />
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import type { Message } from '@types'
|
import type { Message } from '../shared/types'
|
||||||
import { send, sendTo } from '$websocket'
|
import { send, sendTo } from './websocket'
|
||||||
|
|
||||||
// set by setup, called by server
|
// set by setup, called by server
|
||||||
export let dispatch = (ws: any, msg: Message) => { }
|
export let dispatch = (ws: any, msg: Message) => { }
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
import { writeFileSync as writeFile, readFileSync as readFile, existsSync as exists } from 'fs'
|
import { writeFileSync as writeFile, readFileSync as readFile, existsSync as exists } from 'fs'
|
||||||
import { watch } from 'fs'
|
import { watch } from 'fs'
|
||||||
import { join } from 'path'
|
import { join } from 'path'
|
||||||
import { parseActions } from '$actionParser'
|
import { parseActions } from './actionParser'
|
||||||
import { normalize } from '$action'
|
import { normalize } from './action'
|
||||||
|
|
||||||
const srcDir = join(process.cwd(), 'src')
|
const srcDir = join(process.cwd(), 'src')
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,14 @@
|
||||||
import { upgradeWebSocket, websocket } from 'hono/bun'
|
import { upgradeWebSocket, websocket } from 'hono/bun'
|
||||||
import { Hype } from 'hype'
|
import { Hype } from 'hype'
|
||||||
import type { Message } from '@types'
|
import type { Message } from '../shared/types'
|
||||||
import { send, addWebsocket, removeWebsocket, closeWebsockets } from '$websocket'
|
import { send, addWebsocket, removeWebsocket, closeWebsockets } from './websocket'
|
||||||
import { dispatch, onPart } from '$action'
|
import { dispatch, onPart } from './action'
|
||||||
import IndexPage from '../pages/index'
|
import IndexPage from '../pages/index'
|
||||||
|
|
||||||
export { setup } from '$action'
|
export { setup } from './action'
|
||||||
export type { Context } from '$action'
|
export type { Context } from './action'
|
||||||
|
|
||||||
import '$actionCodegen'
|
import './actionCodegen'
|
||||||
|
|
||||||
const app = new Hype({ layout: false })
|
const app = new Hype({ layout: false })
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import type { Message } from '@types'
|
import type { Message } from '../shared/types'
|
||||||
|
|
||||||
const wsConnections = new Map<string, any>()
|
const wsConnections = new Map<string, any>()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,11 +19,6 @@
|
||||||
"noUnusedLocals": false,
|
"noUnusedLocals": false,
|
||||||
"noUnusedParameters": false,
|
"noUnusedParameters": false,
|
||||||
"noPropertyAccessFromIndexSignature": false,
|
"noPropertyAccessFromIndexSignature": false,
|
||||||
"baseUrl": ".",
|
"baseUrl": "."
|
||||||
"paths": {
|
|
||||||
"$*": ["src/server/*"],
|
|
||||||
"#*": ["src/client/*"],
|
|
||||||
"@*": ["src/shared/*"]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user