@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 07:15 UTC

main
ts 52 lines 1.39 KB
Raw
1 import { Match as M, Schema as S } from "effect";
2 import type { Update } from "foldkit";
3 import type { Document, HtmlBuilder } from "foldkit/html";
4 import { defineMessageUnion } from "foldkit/message";
5
6 // MODEL
7
8 export const Model = S.Struct({ count: S.Number });
9 export type Model = typeof Model.Type;
10
11 // FLAGS — what the server read from the request, handed back to the
12 // browser so hydration rebuilds the same first Model.
13
14 export const Flags = S.Struct({ initialCount: S.Number });
15 export type Flags = typeof Flags.Type;
16
17 // MESSAGE
18
19 export const Message = defineMessageUnion({
20 ClickedIncrement: {},
21 });
22 export const { ClickedIncrement } = Message;
23 export type Message = typeof Message.Type;
24
25 // UPDATE
26
27 export const update = (model: Model, message: Message): Update.Return<Model, Message> =>
28 M.value(message).pipe(
29 M.withReturnType<Update.Return<Model, Message>>(),
30 M.tagsExhaustive({
31 ClickedIncrement: () => ({ model: { count: model.count + 1 } }),
32 }),
33 );
34
35 // INIT
36
37 export const init = (flags: Flags): Update.Return<Model, Message> => ({
38 model: { count: flags.initialCount },
39 });
40
41 // VIEW
42
43 export const view = (model: Model, h: HtmlBuilder<Message>): Document => ({
44 title: `Counter: ${model.count}`,
45 body: h.div(
46 [h.Id("app")],
47 [
48 h.p([h.Id("count")], [model.count.toString()]),
49 h.button([h.Id("increment"), h.OnClick(ClickedIncrement())], ["+"]),
50 ],
51 ),
52 });