Skip to content

Commit

Permalink
feat: really basic full-stack application
Browse files Browse the repository at this point in the history
  • Loading branch information
TylorS committed Oct 19, 2024
1 parent 11ac999 commit 96c4835
Show file tree
Hide file tree
Showing 16 changed files with 346 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
},
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
},
"[typescriptreact]": {
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
Expand Down
2 changes: 2 additions & 0 deletions examples/simple-fullstack/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.js
*.ts
21 changes: 21 additions & 0 deletions examples/simple-fullstack/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023-present The Contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
5 changes: 5 additions & 0 deletions examples/simple-fullstack/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# @typed/fx-tracing

> WIP
Docs: https://tylors.github.io/typed/docs/fx-tracing
34 changes: 34 additions & 0 deletions examples/simple-fullstack/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"name": "@typed/example-counter",
"private": true,
"version": "0.0.0",
"description": "",
"repository": {
"type": "git",
"url": "https://github.com/tylors/typed.git"
},
"homepage": "https://github.com/tylors/typed",
"scripts": {
"build": "vavite",
"start": "vite --config ./vite.config.mts serve --force src"
},
"keywords": [],
"author": "Typed contributors",
"license": "MIT",
"sideEffects": [],
"dependencies": {
"@effect/platform": "^0.66.2",
"@effect/platform-node": "^0.61.3",
"@typed/core": "workspace:*",
"@typed/fx": "workspace:*",
"@typed/route": "workspace:*",
"@typed/router": "workspace:*",
"@typed/template": "workspace:*",
"effect": "3.8.4"
},
"devDependencies": {
"tsx": "^4.19.1",
"vavite": "^4.1.1",
"@typed/vite-plugin": "workspace:*"
}
}
25 changes: 25 additions & 0 deletions examples/simple-fullstack/src/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import * as Fx from "@typed/fx"
import * as RefSubject from "@typed/fx/RefSubject"
import * as Route from "@typed/route"
import * as Router from "@typed/router"
import { html } from "@typed/template"

const CounterRoute = Route.literal("counter")
const Counter = Fx.gen(function*() {
const count = yield* RefSubject.of(0)

return html`<div>
<p>Count: ${count}</p>
<button onclick=${RefSubject.decrement(count)}>-</button>
<button onclick=${RefSubject.increment(count)}>+</button>
</div>`
})

const HelloRoute = Route.home
const Hello = html`<h1>Hello World</h1>`

export const router = Router
.match(CounterRoute, () => Counter)
.match(HelloRoute, () => Hello)

export const App = router.pipe(Router.redirectTo(HelloRoute))
12 changes: 12 additions & 0 deletions examples/simple-fullstack/src/browser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { fromWindow } from "@typed/core"
import { hydrateToLayer } from "@typed/template"
import { Effect, Layer } from "effect"
import { App } from "./app"

App.pipe(
hydrateToLayer,
Layer.provide(fromWindow(window)),
Layer.launch,
Effect.scoped,
Effect.runFork
)
23 changes: 23 additions & 0 deletions examples/simple-fullstack/src/server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import type { Fx, RenderEvent } from "@typed/core"
import { html } from "@typed/core"
import * as Node from "@typed/core/Node"
import type { LayoutParams } from "@typed/core/Platform"
import { toServerRouter } from "@typed/core/Platform"
import { router } from "./app"

const layout = <Content extends Fx.Fx<RenderEvent | null, any, any>>({ content, script }: LayoutParams<Content>) =>
html`<!doctype html>
<html>
<head>
<title>Simple Fullstack</title>
</head>
<body>
${content}
${script}
</body>
</html>`

toServerRouter(router, { layout, clientEntry: "browser" }).pipe(
Node.listen({ port: 3000, serverDirectory: import.meta.dirname }),
Node.run
)
31 changes: 31 additions & 0 deletions examples/simple-fullstack/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"extends": [
"../../tsconfig.base.json"
],
"compilerOptions": {
"outDir": "build/esm",
"declarationDir": "build/dts",
"tsBuildInfoFile": "build/tsbuildinfo/esm.tsbuildinfo",
"rootDir": "src"
},
"include": [
"src/**/*.ts"
],
"references": [
{
"path": "../../packages/core/tsconfig.build.json"
},
{
"path": "../../packages/fx/tsconfig.build.json"
},
{
"path": "../../packages/route/tsconfig.build.json"
},
{
"path": "../../packages/router/tsconfig.build.json"
},
{
"path": "../../packages/template/tsconfig.build.json"
}
]
}
11 changes: 11 additions & 0 deletions examples/simple-fullstack/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"tsBuildInfoFile": "build/tsbuildinfo/tsconfig.tsbuildinfo"
},
"references": [
{
"path": "./tsconfig.build.json"
}
]
}
26 changes: 26 additions & 0 deletions examples/simple-fullstack/vite.config.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { makeTypedPlugin } from "@typed/vite-plugin"
import { join } from "path"
import { defineConfig } from "vite"

const foldersToExclude = ["tempo-data", "data", "dist", "node_modules"].map((folder) =>
join(import.meta.dirname, `${folder}/**`)
)

export default defineConfig({
envDir: import.meta.dirname,
server: {
host: "0.0.0.0",
watch: {
ignored: foldersToExclude
}
},
plugins: [
makeTypedPlugin({
clientEntries: {
browser: "./src/browser.ts"
},
serverEntry: "./src/server.ts",
tsconfig: "tsconfig.build.json"
})
]
})
16 changes: 16 additions & 0 deletions examples/simple-fullstack/vitest.config.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/// <reference types="vitest" />

import { dirname } from "path"
import { fileURLToPath } from "url"
import { defineConfig, mergeConfig } from "vite"
import { makeTestConfig } from "../../vitest-make-config.mjs"

const directory = dirname(fileURLToPath(import.meta.url))
const config = mergeConfig(
makeTestConfig(directory),
defineConfig({
test: {}
})
)

export default config
2 changes: 1 addition & 1 deletion packages/compiler/tsconfig.test.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
],
"references": [
{
"path": "../core/tsconfig.build.json"
"path": "../core/tsconfig.test.json"
}
]
}
Loading

0 comments on commit 96c4835

Please sign in to comment.