@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 46 lines 1.16 KB
Raw
1 import { Match as M, Schema as S } from "effect";
2 import type { Runtime, 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 // MESSAGE
12
13 export const Message = defineMessageUnion({
14 ClickedIncrement: {},
15 });
16 export const { ClickedIncrement } = Message;
17 export type Message = typeof Message.Type;
18
19 // UPDATE
20
21 export const update = (model: Model, message: Message): Update.Return<Model, Message> =>
22 M.value(message).pipe(
23 M.withReturnType<Update.Return<Model, Message>>(),
24 M.tagsExhaustive({
25 ClickedIncrement: () => ({ model: { count: model.count + 1 } }),
26 }),
27 );
28
29 // INIT
30
31 export const init: Runtime.ApplicationInit<Model, Message> = () => ({
32 model: { count: 0 },
33 });
34
35 // VIEW
36
37 export const view = (model: Model, h: HtmlBuilder<Message>): Document => ({
38 title: `Counter: ${model.count}`,
39 body: h.div(
40 [h.Id("app")],
41 [
42 h.p([h.Id("count")], [model.count.toString()]),
43 h.button([h.Id("increment"), h.OnClick(ClickedIncrement())], ["+"]),
44 ],
45 ),
46 });