create-foldkit-app 0.31.1 → 0.32.0-canary.0053b7691fcd
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/templates/base/FOLDKIT.md +5 -3
- package/dist/templates/examples/api-cache/package.json +7 -7
- package/dist/templates/examples/api-cache/src/data.ts +14 -14
- package/dist/templates/examples/api-cache/src/main.ts +36 -33
- package/dist/templates/examples/auth/package.json +7 -7
- package/dist/templates/examples/auth/src/command.ts +3 -3
- package/dist/templates/examples/auth/src/domain/session.ts +8 -6
- package/dist/templates/examples/auth/src/main.ts +11 -11
- package/dist/templates/examples/auth/src/message.ts +3 -3
- package/dist/templates/examples/auth/src/model.ts +2 -2
- package/dist/templates/examples/auth/src/page/loggedIn/view.ts +3 -3
- package/dist/templates/examples/auth/src/page/loggedOut/page/login.ts +37 -52
- package/dist/templates/examples/auth/src/page/loggedOut/update.ts +3 -3
- package/dist/templates/examples/auth/src/page/loggedOut/view.ts +3 -3
- package/dist/templates/examples/auth/src/route.ts +2 -2
- package/dist/templates/examples/auth/src/update.ts +35 -35
- package/dist/templates/examples/auth/src/view.ts +6 -6
- package/dist/templates/examples/canvas-art/package.json +7 -7
- package/dist/templates/examples/canvas-art/src/main.ts +22 -30
- package/dist/templates/examples/charting/package.json +7 -7
- package/dist/templates/examples/charting/src/command.ts +3 -3
- package/dist/templates/examples/charting/src/domain.ts +53 -48
- package/dist/templates/examples/charting/src/echarts.ts +6 -6
- package/dist/templates/examples/charting/src/githubApi.ts +33 -34
- package/dist/templates/examples/charting/src/http.ts +7 -7
- package/dist/templates/examples/charting/src/message.ts +6 -6
- package/dist/templates/examples/charting/src/model.ts +6 -6
- package/dist/templates/examples/charting/src/npmApi.ts +19 -15
- package/dist/templates/examples/charting/src/subscription.ts +5 -5
- package/dist/templates/examples/charting/src/telemetry.test.ts +18 -12
- package/dist/templates/examples/charting/src/telemetry.ts +11 -18
- package/dist/templates/examples/charting/src/update.ts +10 -10
- package/dist/templates/examples/charting/src/view/chart.ts +44 -46
- package/dist/templates/examples/counter/package.json +7 -7
- package/dist/templates/examples/counter/src/main.ts +2 -2
- package/dist/templates/examples/counters/package.json +7 -7
- package/dist/templates/examples/counters/src/counter.ts +2 -2
- package/dist/templates/examples/counters/src/main.ts +8 -8
- package/dist/templates/examples/crash-view/package.json +7 -7
- package/dist/templates/examples/embedding/package.json +7 -7
- package/dist/templates/examples/embedding/src/main.ts +10 -7
- package/dist/templates/examples/form/package.json +7 -7
- package/dist/templates/examples/form/src/main.ts +76 -87
- package/dist/templates/examples/generative-art/package.json +7 -7
- package/dist/templates/examples/generative-art/src/command.ts +7 -2
- package/dist/templates/examples/generative-art/src/message.ts +14 -14
- package/dist/templates/examples/generative-art/src/model.ts +21 -21
- package/dist/templates/examples/generative-art/src/update.ts +7 -7
- package/dist/templates/examples/interrupting-commands/package.json +7 -7
- package/dist/templates/examples/interrupting-commands/src/main.ts +36 -36
- package/dist/templates/examples/job-application/package.json +7 -7
- package/dist/templates/examples/job-application/src/domain/proficiencyLevel.ts +2 -2
- package/dist/templates/examples/job-application/src/domain/pronounOption.ts +2 -2
- package/dist/templates/examples/job-application/src/domain/step.ts +11 -11
- package/dist/templates/examples/job-application/src/main.ts +5 -5
- package/dist/templates/examples/job-application/src/message.ts +2 -2
- package/dist/templates/examples/job-application/src/model.ts +5 -5
- package/dist/templates/examples/job-application/src/step/attachments.ts +21 -20
- package/dist/templates/examples/job-application/src/step/coverLetter.ts +4 -4
- package/dist/templates/examples/job-application/src/step/education/education.ts +9 -9
- package/dist/templates/examples/job-application/src/step/education/entry.ts +23 -22
- package/dist/templates/examples/job-application/src/step/personalInfo.ts +30 -38
- package/dist/templates/examples/job-application/src/step/skills/entry.ts +8 -8
- package/dist/templates/examples/job-application/src/step/skills/skills.ts +9 -9
- package/dist/templates/examples/job-application/src/step/workHistory/entry.ts +19 -19
- package/dist/templates/examples/job-application/src/step/workHistory/workHistory.ts +9 -9
- package/dist/templates/examples/job-application/src/update.ts +7 -7
- package/dist/templates/examples/job-application/src/view/attachments.ts +5 -5
- package/dist/templates/examples/job-application/src/view/datePicker.ts +3 -3
- package/dist/templates/examples/job-application/src/view/education.ts +31 -32
- package/dist/templates/examples/job-application/src/view/field.ts +12 -13
- package/dist/templates/examples/job-application/src/view/index.ts +28 -22
- package/dist/templates/examples/job-application/src/view/workHistory.ts +40 -41
- package/dist/templates/examples/kanban/package.json +8 -8
- package/dist/templates/examples/kanban/src/command.ts +4 -4
- package/dist/templates/examples/kanban/src/domain/card.ts +6 -6
- package/dist/templates/examples/kanban/src/domain/column.ts +9 -9
- package/dist/templates/examples/kanban/src/main.ts +4 -4
- package/dist/templates/examples/kanban/src/message.ts +6 -6
- package/dist/templates/examples/kanban/src/model.ts +11 -9
- package/dist/templates/examples/kanban/src/update.ts +5 -5
- package/dist/templates/examples/managed-resource-layer/package.json +7 -7
- package/dist/templates/examples/managed-resource-layer/src/main.ts +30 -31
- package/dist/templates/examples/map/package.json +8 -8
- package/dist/templates/examples/map/src/locations.ts +7 -7
- package/dist/templates/examples/map/src/main.ts +89 -93
- package/dist/templates/examples/map/src/vite-env.d.ts +1 -0
- package/dist/templates/examples/pixel-art/package.json +7 -7
- package/dist/templates/examples/pixel-art/src/command.ts +12 -5
- package/dist/templates/examples/pixel-art/src/main.ts +4 -4
- package/dist/templates/examples/pixel-art/src/message.ts +7 -7
- package/dist/templates/examples/pixel-art/src/model.ts +34 -29
- package/dist/templates/examples/pixel-art/src/scene.test.ts +3 -3
- package/dist/templates/examples/pixel-art/src/story.test.ts +3 -3
- package/dist/templates/examples/pixel-art/src/subscription.ts +2 -2
- package/dist/templates/examples/pixel-art/src/update.ts +62 -57
- package/dist/templates/examples/query-sync/package.json +7 -7
- package/dist/templates/examples/query-sync/src/main.ts +101 -103
- package/dist/templates/examples/route-transitions/package.json +7 -7
- package/dist/templates/examples/route-transitions/src/data.ts +6 -6
- package/dist/templates/examples/route-transitions/src/main.ts +47 -61
- package/dist/templates/examples/route-transitions/src/route.ts +3 -3
- package/dist/templates/examples/routing/package.json +7 -7
- package/dist/templates/examples/routing/src/fileTree.ts +10 -8
- package/dist/templates/examples/routing/src/main.ts +47 -51
- package/dist/templates/examples/routing/src/page/people.ts +94 -108
- package/dist/templates/examples/routing/src/route.ts +7 -7
- package/dist/templates/examples/shopping-cart/package.json +7 -7
- package/dist/templates/examples/shopping-cart/src/main.ts +32 -38
- package/dist/templates/examples/shopping-cart/src/page/products.ts +10 -10
- package/dist/templates/examples/shopping-cart/src/route.ts +6 -4
- package/dist/templates/examples/slow-warnings/package.json +7 -7
- package/dist/templates/examples/slow-warnings/src/main.ts +35 -43
- package/dist/templates/examples/snake/package.json +7 -7
- package/dist/templates/examples/snake/src/domain/snake.ts +2 -2
- package/dist/templates/examples/snake/src/main.ts +39 -47
- package/dist/templates/examples/ssg/package.json +6 -8
- package/dist/templates/examples/ssg/src/main.ts +69 -79
- package/dist/templates/examples/ssg/src/route.ts +2 -2
- package/dist/templates/examples/ssr/package.json +8 -9
- package/dist/templates/examples/ssr/src/cookie.ts +3 -3
- package/dist/templates/examples/ssr/src/main.ts +10 -10
- package/dist/templates/examples/state-machine/package.json +7 -7
- package/dist/templates/examples/state-machine/src/main.ts +57 -53
- package/dist/templates/examples/state-machine/src/view.ts +57 -66
- package/dist/templates/examples/stopwatch/package.json +7 -7
- package/dist/templates/examples/stopwatch/src/main.ts +10 -10
- package/dist/templates/examples/todo/package.json +7 -7
- package/dist/templates/examples/todo/src/main.ts +70 -71
- package/dist/templates/examples/ui-showcase/package.json +7 -7
- package/dist/templates/examples/ui-showcase/src/main.ts +61 -54
- package/dist/templates/examples/ui-showcase/src/scene.test.ts +11 -0
- package/dist/templates/examples/ui-showcase/src/ui/init.ts +2 -0
- package/dist/templates/examples/ui-showcase/src/ui/message.ts +17 -15
- package/dist/templates/examples/ui-showcase/src/ui/model.ts +50 -44
- package/dist/templates/examples/ui-showcase/src/ui/toast.ts +4 -4
- package/dist/templates/examples/ui-showcase/src/ui/update.ts +108 -84
- package/dist/templates/examples/ui-showcase/src/ui/view/calendar.ts +3 -3
- package/dist/templates/examples/ui-showcase/src/ui/view/datePicker.ts +3 -3
- package/dist/templates/examples/ui-showcase/src/ui/view/fileDrop.ts +5 -5
- package/dist/templates/examples/ui-showcase/src/ui/view/hoverIntent.ts +78 -0
- package/dist/templates/examples/ui-showcase/src/ui/view/index.ts +1 -0
- package/dist/templates/examples/ui-showcase/src/ui/view/menu.ts +14 -14
- package/dist/templates/examples/ui-showcase/src/ui/view/tabs.ts +6 -6
- package/dist/templates/examples/ui-showcase/src/ui/view/toast.ts +7 -7
- package/dist/templates/examples/ui-showcase/src/ui/view/virtualList.ts +6 -6
- package/dist/templates/examples/view-transitions/package.json +7 -7
- package/dist/templates/examples/view-transitions/src/artwork.ts +7 -7
- package/dist/templates/examples/view-transitions/src/main.ts +34 -45
- package/dist/templates/examples/view-transitions/src/route.ts +3 -3
- package/dist/templates/examples/weather/package.json +7 -7
- package/dist/templates/examples/weather/src/main.ts +42 -42
- package/dist/templates/examples/weather/src/story.test.ts +5 -5
- package/dist/templates/examples/web-components/package.json +7 -7
- package/dist/templates/examples/web-components/src/main.ts +16 -16
- package/dist/templates/examples/websocket-chat/package.json +7 -7
- package/dist/templates/examples/websocket-chat/src/main.ts +52 -62
- package/dist/templates/release.json +19 -19
- package/dist/templates/rendering/ssg/README.md +8 -7
- package/dist/templates/rendering/ssg/package.json +2 -2
- package/dist/templates/rendering/ssg/src/main.ts +65 -74
- package/dist/templates/rendering/ssg/src/route.ts +2 -2
- package/dist/templates/rendering/ssg/tsconfig.json +1 -1
- package/dist/templates/rendering/ssg/vite.config.ts +22 -1
- package/dist/templates/rendering/ssr/README.md +10 -7
- package/dist/templates/rendering/ssr/package.json +2 -2
- package/dist/templates/rendering/ssr/server/main.ts +15 -15
- package/dist/templates/rendering/ssr/src/cookie.ts +3 -3
- package/dist/templates/rendering/ssr/src/main.ts +10 -10
- package/dist/templates/rendering/ssr/vite.config.ts +22 -1
- package/package.json +5 -5
- package/dist/templates/rendering/ssg/scripts/build.mjs +0 -27
- package/dist/templates/rendering/ssg/scripts/prerender.ts +0 -120
- package/dist/templates/rendering/ssr/scripts/build.mjs +0 -23
|
@@ -74,7 +74,7 @@ Use `evo()` from `foldkit/struct` for immutable model updates. Never spread or `
|
|
|
74
74
|
|
|
75
75
|
### View
|
|
76
76
|
|
|
77
|
-
Every view receives `h`, the typed Html builder, as its last parameter (`view: (model, h) => ...`; `Submodel.defineView` passes the child's own). Never construct a builder; reach for `h.div`, `h.OnClick`, etc. off the parameter, and give extracted view helpers an `h: HtmlBuilder<Message>` last parameter that callers thread through. Only where no builder is in scope, typically module scope, use `inertHtml` from `foldkit/html`, aliased `ih` so the two builders stay distinguishable. Use `h.empty` (not `null`) for conditional rendering, `
|
|
77
|
+
Every view receives `h`, the typed Html builder, as its last parameter (`view: (model, h) => ...`; `Submodel.defineView` passes the child's own). Never construct a builder; reach for `h.div`, `h.OnClick`, etc. off the parameter, and give extracted view helpers an `h: HtmlBuilder<Message>` last parameter that callers thread through. Only where no builder is in scope, typically module scope, use `inertHtml` from `foldkit/html`, aliased `ih` so the two builders stay distinguishable. Use `h.empty` (not `null`) for conditional rendering, the union's own exhaustive `match` (`EditorMode.match(model.mode, {...})`) for discriminated unions, and `Array.match` for lists that may be empty.
|
|
78
78
|
|
|
79
79
|
Keys are for mapped list items only: key each row by a stable Model identifier (`h.keyed('li')(item.id, [], [...])`), never by array position, and never derive a key from displayed data. Never key branches; the build gives each view function's output its own identity, so branch switches replace DOM automatically. When switching an inline same-tag ternary must reset DOM state, extract each arm into its own named view function.
|
|
80
80
|
|
|
@@ -84,9 +84,11 @@ Omit the children argument when an element has none: `h.div([h.Class('divider')]
|
|
|
84
84
|
|
|
85
85
|
Define a Command with `Command.define(name, { args, messages, execute })`; omit `args` when the Command takes none. Assign definitions to PascalCase constants. Never inline in pipe chains. Name the effect `execute` performs, not the later Model transition caused when update handles its result: a timer that only waits before update starts a dismissal is `WaitBeforeDismissal`, not `DismissAfter`. Commands catch all errors via `Effect.catch(() => Effect.succeed(Message.FailedX(...)))` so side effects never crash the app. Definitions live colocated with the update function that returns them.
|
|
86
86
|
|
|
87
|
+
Command args contain values already present in the Model or Message. Calling `Date.now()`, `crypto.randomUUID()`, or another source of time or randomness while preparing a Command happens before the Command executes, whether the call appears directly in the args object or its result is assigned to a local variable first. Obtain those values in `execute` and return them in the result Message.
|
|
88
|
+
|
|
87
89
|
For the with-args shape, see `repos/foldkit/examples/weather/src/main.ts` or `repos/foldkit/examples/kanban/src/command.ts`. For an argless DOM-side-effect Command, the argless form in `kanban/src/command.ts` (`FocusAddCardInput`) is the canonical reference.
|
|
88
90
|
|
|
89
|
-
For DOM operations (focus, scroll, modals, scroll lock), Foldkit ships a `Dom` module. For time, randomness, UUIDs, and delays, use Effect's
|
|
91
|
+
For DOM operations (focus, scroll, modals, scroll lock), Foldkit ships a `Dom` module. For time, randomness, UUIDs, and delays, use Effect's APIs directly (`Clock`, `Random`, `Crypto.Crypto`, `Effect.sleep`). Provide the platform Crypto layer when using `Crypto.Crypto`. Don't reach for raw `document.querySelector`, `setTimeout`, `Date.now()`, or `Math.random()`.
|
|
90
92
|
|
|
91
93
|
### File Organization
|
|
92
94
|
|
|
@@ -126,7 +128,7 @@ Declare the whole Message union with `defineMessageUnion()`, then put `type Mess
|
|
|
126
128
|
```ts
|
|
127
129
|
const Message = defineMessageUnion({
|
|
128
130
|
ClickedSubmit: {},
|
|
129
|
-
UpdatedEmail: { value:
|
|
131
|
+
UpdatedEmail: { value: Schema.String },
|
|
130
132
|
})
|
|
131
133
|
type Message = typeof Message.Type
|
|
132
134
|
```
|
|
@@ -17,13 +17,13 @@
|
|
|
17
17
|
"devDependencies": {
|
|
18
18
|
"@foldkit/devtools": "workspace:*",
|
|
19
19
|
"@foldkit/vite-plugin": "workspace:*",
|
|
20
|
-
"@tailwindcss/vite": "^4.3.
|
|
20
|
+
"@tailwindcss/vite": "^4.3.3",
|
|
21
21
|
"@trivago/prettier-plugin-sort-imports": "^6.0.2",
|
|
22
|
-
"happy-dom": "^20.
|
|
23
|
-
"prettier": "^3.
|
|
24
|
-
"tailwindcss": "^4.3.
|
|
25
|
-
"typescript": "^
|
|
26
|
-
"vite": "^8.
|
|
27
|
-
"vitest": "^4.1.
|
|
22
|
+
"happy-dom": "^20.11.13",
|
|
23
|
+
"prettier": "^3.9.6",
|
|
24
|
+
"tailwindcss": "^4.3.3",
|
|
25
|
+
"typescript": "^7.0.2",
|
|
26
|
+
"vite": "^8.2.2",
|
|
27
|
+
"vitest": "^4.1.11"
|
|
28
28
|
}
|
|
29
29
|
}
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import { Array, Duration, Effect, Option, Random, Schema
|
|
1
|
+
import { Array, Duration, Effect, Option, Random, Schema } from 'effect'
|
|
2
2
|
|
|
3
|
-
export const Post =
|
|
4
|
-
id:
|
|
5
|
-
title:
|
|
6
|
-
excerpt:
|
|
3
|
+
export const Post = Schema.Struct({
|
|
4
|
+
id: Schema.String,
|
|
5
|
+
title: Schema.String,
|
|
6
|
+
excerpt: Schema.String,
|
|
7
7
|
})
|
|
8
8
|
export type Post = typeof Post.Type
|
|
9
9
|
|
|
10
|
-
export const PostDetail =
|
|
11
|
-
id:
|
|
12
|
-
title:
|
|
13
|
-
author:
|
|
14
|
-
body:
|
|
10
|
+
export const PostDetail = Schema.Struct({
|
|
11
|
+
id: Schema.String,
|
|
12
|
+
title: Schema.String,
|
|
13
|
+
author: Schema.String,
|
|
14
|
+
body: Schema.String,
|
|
15
15
|
})
|
|
16
16
|
export type PostDetail = typeof PostDetail.Type
|
|
17
17
|
|
|
18
|
-
export const Stats =
|
|
19
|
-
activeUsers:
|
|
20
|
-
requestsPerSecond:
|
|
21
|
-
cacheHitRatePercent:
|
|
18
|
+
export const Stats = Schema.Struct({
|
|
19
|
+
activeUsers: Schema.Number,
|
|
20
|
+
requestsPerSecond: Schema.Number,
|
|
21
|
+
cacheHitRatePercent: Schema.Number,
|
|
22
22
|
})
|
|
23
23
|
export type Stats = typeof Stats.Type
|
|
24
24
|
|
|
@@ -4,9 +4,9 @@ import {
|
|
|
4
4
|
Duration,
|
|
5
5
|
Effect,
|
|
6
6
|
HashMap,
|
|
7
|
-
Match
|
|
7
|
+
Match,
|
|
8
8
|
Option,
|
|
9
|
-
Schema
|
|
9
|
+
Schema,
|
|
10
10
|
Stream,
|
|
11
11
|
pipe,
|
|
12
12
|
} from 'effect'
|
|
@@ -32,36 +32,39 @@ export const TABS_ID = 'api-cache-tabs'
|
|
|
32
32
|
|
|
33
33
|
// MODEL
|
|
34
34
|
|
|
35
|
-
const FetchedPosts =
|
|
35
|
+
const FetchedPosts = Schema.Struct({
|
|
36
|
+
posts: Schema.Array(Post),
|
|
37
|
+
fetchedAt: Schema.Number,
|
|
38
|
+
})
|
|
36
39
|
|
|
37
|
-
const FetchedPostDetail =
|
|
40
|
+
const FetchedPostDetail = Schema.Struct({
|
|
38
41
|
detail: PostDetail,
|
|
39
|
-
fetchedAt:
|
|
42
|
+
fetchedAt: Schema.Number,
|
|
40
43
|
})
|
|
41
44
|
|
|
42
|
-
const FetchedStats =
|
|
45
|
+
const FetchedStats = Schema.Struct({ stats: Stats, fetchedAt: Schema.Number })
|
|
43
46
|
|
|
44
|
-
export const PostsData = AsyncData.Schema(FetchedPosts,
|
|
45
|
-
export const PostDetailData = AsyncData.Schema(FetchedPostDetail,
|
|
46
|
-
export const StatsData = AsyncData.Schema(FetchedStats,
|
|
47
|
+
export const PostsData = AsyncData.Schema(FetchedPosts, Schema.String)
|
|
48
|
+
export const PostDetailData = AsyncData.Schema(FetchedPostDetail, Schema.String)
|
|
49
|
+
export const StatsData = AsyncData.Schema(FetchedStats, Schema.String)
|
|
47
50
|
|
|
48
51
|
type PostsData = typeof PostsData.schema.Type
|
|
49
52
|
type PostDetailData = typeof PostDetailData.schema.Type
|
|
50
53
|
type StatsData = typeof StatsData.schema.Type
|
|
51
54
|
|
|
52
|
-
const Tab =
|
|
55
|
+
const Tab = Schema.Literals(['Posts', 'Stats'])
|
|
53
56
|
type Tab = typeof Tab.Type
|
|
54
57
|
|
|
55
58
|
const tabValues: ReadonlyArray<Tab> = Tab.literals
|
|
56
59
|
|
|
57
60
|
export const AppTabs = Tabs.create<Tab>()
|
|
58
61
|
|
|
59
|
-
export const Model =
|
|
62
|
+
export const Model = Schema.Struct({
|
|
60
63
|
tabs: Tabs.Model,
|
|
61
64
|
activeTab: Tab,
|
|
62
65
|
posts: PostsData.schema,
|
|
63
|
-
postDetailById:
|
|
64
|
-
maybeSelectedPostId:
|
|
66
|
+
postDetailById: Schema.HashMap(Schema.String, PostDetailData.schema),
|
|
67
|
+
maybeSelectedPostId: Schema.Option(Schema.String),
|
|
65
68
|
stats: StatsData.schema,
|
|
66
69
|
})
|
|
67
70
|
export type Model = typeof Model.Type
|
|
@@ -70,20 +73,20 @@ export type Model = typeof Model.Type
|
|
|
70
73
|
|
|
71
74
|
export const Message = defineMessageUnion({
|
|
72
75
|
GotTabsMessage: { message: Tabs.Message },
|
|
73
|
-
ClickedPost: { postId:
|
|
76
|
+
ClickedPost: { postId: Schema.String },
|
|
74
77
|
ClickedBackToPosts: {},
|
|
75
78
|
ClickedInvalidatePosts: {},
|
|
76
79
|
ClickedRetryPosts: {},
|
|
77
|
-
ClickedRetryPostDetail: { postId:
|
|
80
|
+
ClickedRetryPostDetail: { postId: Schema.String },
|
|
78
81
|
ClickedRefreshStats: {},
|
|
79
82
|
ClickedRetryStats: {},
|
|
80
83
|
TickedRevalidateStats: {},
|
|
81
|
-
SettledFetchPosts: { result:
|
|
84
|
+
SettledFetchPosts: { result: Schema.Result(FetchedPosts, Schema.String) },
|
|
82
85
|
SettledFetchPostDetail: {
|
|
83
|
-
postId:
|
|
84
|
-
result:
|
|
86
|
+
postId: Schema.String,
|
|
87
|
+
result: Schema.Result(FetchedPostDetail, Schema.String),
|
|
85
88
|
},
|
|
86
|
-
SettledFetchStats: { result:
|
|
89
|
+
SettledFetchStats: { result: Schema.Result(FetchedStats, Schema.String) },
|
|
87
90
|
})
|
|
88
91
|
|
|
89
92
|
export type Message = typeof Message.Type
|
|
@@ -122,27 +125,27 @@ const setPostDetail = (postId: string, postDetail: PostDetailData) =>
|
|
|
122
125
|
const activateTab = (model: Model, tab: Tab): UpdateReturn => {
|
|
123
126
|
const modelWithActiveTab = evo(model, { activeTab: () => tab })
|
|
124
127
|
|
|
125
|
-
return
|
|
126
|
-
|
|
127
|
-
|
|
128
|
+
return Match.value(tab).pipe(
|
|
129
|
+
Match.withReturnType<UpdateReturn>(),
|
|
130
|
+
Match.when('Posts', () =>
|
|
128
131
|
applyPostsTransition(
|
|
129
132
|
modelWithActiveTab,
|
|
130
133
|
AsyncData.loadIfMissing(modelWithActiveTab.posts),
|
|
131
134
|
),
|
|
132
135
|
),
|
|
133
|
-
|
|
136
|
+
Match.when('Stats', () =>
|
|
134
137
|
applyStatsTransition(
|
|
135
138
|
modelWithActiveTab,
|
|
136
139
|
AsyncData.loadIfMissing(modelWithActiveTab.stats),
|
|
137
140
|
),
|
|
138
141
|
),
|
|
139
|
-
|
|
142
|
+
Match.exhaustive,
|
|
140
143
|
)
|
|
141
144
|
}
|
|
142
145
|
|
|
143
|
-
const foldTabsOutMessage =
|
|
144
|
-
|
|
145
|
-
|
|
146
|
+
const foldTabsOutMessage = Match.type<Tabs.OutMessage<Tab>>().pipe(
|
|
147
|
+
Match.withReturnType<Update.Step<Model, Message>>(),
|
|
148
|
+
Match.tagsExhaustive({
|
|
146
149
|
Selected:
|
|
147
150
|
({ value }) =>
|
|
148
151
|
model =>
|
|
@@ -249,7 +252,7 @@ export const FetchPosts = Command.define('FetchPosts', {
|
|
|
249
252
|
})
|
|
250
253
|
|
|
251
254
|
export const FetchPostDetail = Command.define('FetchPostDetail', {
|
|
252
|
-
args: { postId:
|
|
255
|
+
args: { postId: Schema.String },
|
|
253
256
|
messages: [Message.SettledFetchPostDetail],
|
|
254
257
|
execute: ({ postId }) =>
|
|
255
258
|
pipe(
|
|
@@ -280,7 +283,7 @@ export const FetchStats = Command.define('FetchStats', {
|
|
|
280
283
|
|
|
281
284
|
export const subscriptions = Subscription.make<Model, Message>()(entry => ({
|
|
282
285
|
revalidateStats: entry(
|
|
283
|
-
{ isObservingStats:
|
|
286
|
+
{ isObservingStats: Schema.Boolean },
|
|
284
287
|
{
|
|
285
288
|
modelToDependencies: model => ({
|
|
286
289
|
isObservingStats:
|
|
@@ -350,10 +353,10 @@ export const view = (model: Model, h: HtmlBuilder<Message>): Document => ({
|
|
|
350
353
|
tabInfo.value,
|
|
351
354
|
[...tabInfo.panel, h.Class('flex flex-col gap-4')],
|
|
352
355
|
[
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
356
|
+
Match.value(tabInfo.value).pipe(
|
|
357
|
+
Match.when('Posts', () => postsTabView(model, h)),
|
|
358
|
+
Match.when('Stats', () => statsTabView(model, h)),
|
|
359
|
+
Match.exhaustive,
|
|
357
360
|
),
|
|
358
361
|
],
|
|
359
362
|
),
|
|
@@ -18,13 +18,13 @@
|
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"@foldkit/devtools": "workspace:*",
|
|
20
20
|
"@foldkit/vite-plugin": "workspace:*",
|
|
21
|
-
"@tailwindcss/vite": "^4.3.
|
|
21
|
+
"@tailwindcss/vite": "^4.3.3",
|
|
22
22
|
"@trivago/prettier-plugin-sort-imports": "^6.0.2",
|
|
23
|
-
"happy-dom": "^20.
|
|
24
|
-
"prettier": "^3.
|
|
25
|
-
"tailwindcss": "^4.3.
|
|
26
|
-
"typescript": "^
|
|
27
|
-
"vite": "^8.
|
|
28
|
-
"vitest": "^4.1.
|
|
23
|
+
"happy-dom": "^20.11.13",
|
|
24
|
+
"prettier": "^3.9.6",
|
|
25
|
+
"tailwindcss": "^4.3.3",
|
|
26
|
+
"typescript": "^7.0.2",
|
|
27
|
+
"vite": "^8.2.2",
|
|
28
|
+
"vitest": "^4.1.11"
|
|
29
29
|
}
|
|
30
30
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Console, Effect, Schema
|
|
1
|
+
import { Console, Effect, Schema } from 'effect'
|
|
2
2
|
import { KeyValueStore } from 'effect/unstable/persistence'
|
|
3
3
|
import { Command } from 'foldkit'
|
|
4
4
|
|
|
@@ -16,7 +16,7 @@ export const SaveSession = Command.define('SaveSession', {
|
|
|
16
16
|
const store = yield* KeyValueStore.KeyValueStore
|
|
17
17
|
yield* store.set(
|
|
18
18
|
SESSION_STORAGE_KEY,
|
|
19
|
-
|
|
19
|
+
Schema.encodeSync(SessionJsonString)(session),
|
|
20
20
|
)
|
|
21
21
|
return Message.SucceededSaveSession()
|
|
22
22
|
}).pipe(
|
|
@@ -42,7 +42,7 @@ export const ClearSession = Command.define('ClearSession', {
|
|
|
42
42
|
})
|
|
43
43
|
|
|
44
44
|
export const LogError = Command.define('LogError', {
|
|
45
|
-
args: { entries:
|
|
45
|
+
args: { entries: Schema.Array(Schema.Unknown) },
|
|
46
46
|
messages: [Message.CompletedLogError],
|
|
47
47
|
execute: ({ entries }) =>
|
|
48
48
|
Console.error(...entries).pipe(Effect.as(Message.CompletedLogError())),
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { Schema
|
|
1
|
+
import { Schema } from 'effect'
|
|
2
2
|
|
|
3
|
-
export const Session =
|
|
4
|
-
userId:
|
|
5
|
-
email:
|
|
6
|
-
name:
|
|
3
|
+
export const Session = Schema.Struct({
|
|
4
|
+
userId: Schema.String,
|
|
5
|
+
email: Schema.String,
|
|
6
|
+
name: Schema.String,
|
|
7
7
|
})
|
|
8
8
|
|
|
9
9
|
export type Session = typeof Session.Type
|
|
10
10
|
|
|
11
|
-
export const SessionJsonString =
|
|
11
|
+
export const SessionJsonString = Schema.fromJsonString(
|
|
12
|
+
Schema.toCodecJson(Session),
|
|
13
|
+
)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Effect, Match
|
|
1
|
+
import { Effect, Match, Option, Schema } from 'effect'
|
|
2
2
|
import { KeyValueStore } from 'effect/unstable/persistence'
|
|
3
3
|
import { Runtime, type Update } from 'foldkit'
|
|
4
4
|
import { Url } from 'foldkit/url'
|
|
@@ -14,8 +14,8 @@ import { RedirectToDashboard, RedirectToLogin } from './update'
|
|
|
14
14
|
|
|
15
15
|
// FLAGS
|
|
16
16
|
|
|
17
|
-
export const Flags =
|
|
18
|
-
maybeSession:
|
|
17
|
+
export const Flags = Schema.Struct({
|
|
18
|
+
maybeSession: Schema.Option(Session),
|
|
19
19
|
})
|
|
20
20
|
|
|
21
21
|
export const flags: Effect.Effect<Flags> = Effect.gen(function* () {
|
|
@@ -24,7 +24,7 @@ export const flags: Effect.Effect<Flags> = Effect.gen(function* () {
|
|
|
24
24
|
Option.fromNullishOr(yield* store.get(SESSION_STORAGE_KEY)),
|
|
25
25
|
)
|
|
26
26
|
|
|
27
|
-
const decodeSession =
|
|
27
|
+
const decodeSession = Schema.decodeEffect(SessionJsonString)
|
|
28
28
|
const session = yield* decodeSession(sessionJson)
|
|
29
29
|
|
|
30
30
|
return Flags.make({ maybeSession: Option.some(session) })
|
|
@@ -40,7 +40,7 @@ export type Flags = typeof Flags.Type
|
|
|
40
40
|
// INIT
|
|
41
41
|
|
|
42
42
|
type InitReturn = Update.Return<Model, Message>
|
|
43
|
-
const withInitReturn =
|
|
43
|
+
const withInitReturn = Match.withReturnType<InitReturn>()
|
|
44
44
|
|
|
45
45
|
export const init: Runtime.RoutingApplicationInit<Model, Message, Flags> = (
|
|
46
46
|
flags: Flags,
|
|
@@ -50,24 +50,24 @@ export const init: Runtime.RoutingApplicationInit<Model, Message, Flags> = (
|
|
|
50
50
|
|
|
51
51
|
return Option.match(flags.maybeSession, {
|
|
52
52
|
onNone: () =>
|
|
53
|
-
|
|
53
|
+
Match.value(route).pipe(
|
|
54
54
|
withInitReturn,
|
|
55
|
-
|
|
55
|
+
Match.tag('Home', 'Login', 'NotFound', route => ({
|
|
56
56
|
model: LoggedOut.init(route),
|
|
57
57
|
})),
|
|
58
|
-
|
|
58
|
+
Match.orElse(() => ({
|
|
59
59
|
model: LoggedOut.init(AppRoute.Login()),
|
|
60
60
|
commands: [RedirectToLogin()],
|
|
61
61
|
})),
|
|
62
62
|
),
|
|
63
63
|
|
|
64
64
|
onSome: session =>
|
|
65
|
-
|
|
65
|
+
Match.value(route).pipe(
|
|
66
66
|
withInitReturn,
|
|
67
|
-
|
|
67
|
+
Match.tag('Dashboard', 'Settings', 'NotFound', route => ({
|
|
68
68
|
model: LoggedIn.init(route, session),
|
|
69
69
|
})),
|
|
70
|
-
|
|
70
|
+
Match.orElse(() => ({
|
|
71
71
|
model: LoggedIn.init(AppRoute.Dashboard(), session),
|
|
72
72
|
commands: [RedirectToDashboard()],
|
|
73
73
|
})),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Schema
|
|
1
|
+
import { Schema } from 'effect'
|
|
2
2
|
import { defineMessageUnion } from 'foldkit/message'
|
|
3
3
|
import { UrlRequest } from 'foldkit/navigation'
|
|
4
4
|
import { Url } from 'foldkit/url'
|
|
@@ -12,9 +12,9 @@ export const Message = defineMessageUnion({
|
|
|
12
12
|
ClickedLink: { request: UrlRequest },
|
|
13
13
|
ChangedUrl: { url: Url },
|
|
14
14
|
SucceededSaveSession: {},
|
|
15
|
-
FailedSaveSession: { error:
|
|
15
|
+
FailedSaveSession: { error: Schema.String },
|
|
16
16
|
SucceededClearSession: {},
|
|
17
|
-
FailedClearSession: { error:
|
|
17
|
+
FailedClearSession: { error: Schema.String },
|
|
18
18
|
GotLoggedOutMessage: { message: LoggedOut.Message },
|
|
19
19
|
GotLoggedInMessage: { message: LoggedIn.Message },
|
|
20
20
|
})
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Schema
|
|
1
|
+
import { Schema } from 'effect'
|
|
2
2
|
|
|
3
3
|
import { LoggedIn, LoggedOut } from './page'
|
|
4
4
|
|
|
5
|
-
export const Model =
|
|
5
|
+
export const Model = Schema.Union([LoggedOut.Model, LoggedIn.Model])
|
|
6
6
|
|
|
7
7
|
export type Model = typeof Model.Type
|
|
8
8
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { clsx } from 'clsx'
|
|
2
|
-
import { Match
|
|
2
|
+
import { Match } from 'effect'
|
|
3
3
|
import { Submodel } from 'foldkit'
|
|
4
4
|
import { Html, HtmlBuilder } from 'foldkit/html'
|
|
5
5
|
|
|
@@ -72,8 +72,8 @@ export const view = Submodel.defineView<Model, Message>((model, h) =>
|
|
|
72
72
|
h.main(
|
|
73
73
|
[h.Class('py-8')],
|
|
74
74
|
[
|
|
75
|
-
|
|
76
|
-
|
|
75
|
+
Match.value(model.route).pipe(
|
|
76
|
+
Match.tagsExhaustive({
|
|
77
77
|
Dashboard: () => Dashboard.view(model.session, h),
|
|
78
78
|
Settings: () => Settings.view(model.session, h),
|
|
79
79
|
NotFound: ({ path }) =>
|
|
@@ -1,15 +1,6 @@
|
|
|
1
1
|
import { clsx } from 'clsx'
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
Duration,
|
|
5
|
-
Effect,
|
|
6
|
-
Match as M,
|
|
7
|
-
Option,
|
|
8
|
-
Schema as S,
|
|
9
|
-
String,
|
|
10
|
-
pipe,
|
|
11
|
-
} from 'effect'
|
|
12
|
-
import { Command, Submodel, type Update } from 'foldkit'
|
|
2
|
+
import { Array, Duration, Effect, Option, Schema, String, pipe } from 'effect'
|
|
3
|
+
import { Command, FieldValidation, Submodel, type Update } from 'foldkit'
|
|
13
4
|
import {
|
|
14
5
|
Field,
|
|
15
6
|
Invalid,
|
|
@@ -30,10 +21,10 @@ import { homeRouter } from '../../../route'
|
|
|
30
21
|
|
|
31
22
|
// MODEL
|
|
32
23
|
|
|
33
|
-
export const Model =
|
|
34
|
-
email: Field(
|
|
35
|
-
password: Field(
|
|
36
|
-
isSubmitting:
|
|
24
|
+
export const Model = Schema.Struct({
|
|
25
|
+
email: Field(Schema.String),
|
|
26
|
+
password: Field(Schema.String),
|
|
27
|
+
isSubmitting: Schema.Boolean,
|
|
37
28
|
})
|
|
38
29
|
|
|
39
30
|
export type Model = typeof Model.Type
|
|
@@ -47,11 +38,11 @@ export const initModel = (): Model => ({
|
|
|
47
38
|
// MESSAGE
|
|
48
39
|
|
|
49
40
|
export const Message = defineMessageUnion({
|
|
50
|
-
ChangedEmail: { value:
|
|
51
|
-
ChangedPassword: { value:
|
|
41
|
+
ChangedEmail: { value: Schema.String },
|
|
42
|
+
ChangedPassword: { value: Schema.String },
|
|
52
43
|
SubmittedForm: {},
|
|
53
44
|
SucceededSimulateAuthRequest: { session: Session },
|
|
54
|
-
FailedSimulateAuthRequest: { error:
|
|
45
|
+
FailedSimulateAuthRequest: { error: Schema.String },
|
|
55
46
|
})
|
|
56
47
|
|
|
57
48
|
export type Message = typeof Message.Type
|
|
@@ -87,7 +78,7 @@ const isFormValid = (model: Model): boolean =>
|
|
|
87
78
|
// UPDATE
|
|
88
79
|
|
|
89
80
|
export const SimulateAuthRequest = Command.define('SimulateAuthRequest', {
|
|
90
|
-
args: { email:
|
|
81
|
+
args: { email: Schema.String, password: Schema.String },
|
|
91
82
|
messages: [
|
|
92
83
|
Message.SucceededSimulateAuthRequest,
|
|
93
84
|
Message.FailedSimulateAuthRequest,
|
|
@@ -168,14 +159,12 @@ export const update = (model: Model, message: Message) =>
|
|
|
168
159
|
// VIEW
|
|
169
160
|
|
|
170
161
|
const fieldToBorderClass = (field: Field<string>) =>
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
}),
|
|
178
|
-
)
|
|
162
|
+
FieldValidation.match(field, {
|
|
163
|
+
onNotValidated: () => 'border-gray-300',
|
|
164
|
+
onValidating: () => 'border-blue-300',
|
|
165
|
+
onValid: () => 'border-green-500',
|
|
166
|
+
onInvalid: () => 'border-red-500',
|
|
167
|
+
})
|
|
179
168
|
|
|
180
169
|
const fieldView = (
|
|
181
170
|
id: string,
|
|
@@ -213,34 +202,30 @@ const fieldView = (
|
|
|
213
202
|
],
|
|
214
203
|
[labelText],
|
|
215
204
|
),
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
}),
|
|
225
|
-
),
|
|
205
|
+
FieldValidation.match(field, {
|
|
206
|
+
onNotValidated: () => h.empty,
|
|
207
|
+
onValidating: () =>
|
|
208
|
+
h.span([h.Class('text-blue-600 text-sm')], ['...']),
|
|
209
|
+
onValid: () =>
|
|
210
|
+
h.span([h.Class('text-green-600 text-sm')], ['✓']),
|
|
211
|
+
onInvalid: () => h.empty,
|
|
212
|
+
}),
|
|
226
213
|
],
|
|
227
214
|
),
|
|
228
215
|
h.input([...attributes.input, h.Class(inputClass)]),
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
}),
|
|
243
|
-
),
|
|
216
|
+
FieldValidation.match(field, {
|
|
217
|
+
onNotValidated: () => h.empty,
|
|
218
|
+
onValidating: () => h.empty,
|
|
219
|
+
onValid: () => h.empty,
|
|
220
|
+
onInvalid: ({ errors }) =>
|
|
221
|
+
h.div(
|
|
222
|
+
[
|
|
223
|
+
...attributes.description,
|
|
224
|
+
h.Class('text-red-600 text-sm mt-1'),
|
|
225
|
+
],
|
|
226
|
+
[Array.headNonEmpty(errors)],
|
|
227
|
+
),
|
|
228
|
+
}),
|
|
244
229
|
],
|
|
245
230
|
),
|
|
246
231
|
},
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Match
|
|
1
|
+
import { Match, Option } from 'effect'
|
|
2
2
|
import { Update } from 'foldkit'
|
|
3
3
|
import { evo } from 'foldkit/struct'
|
|
4
4
|
|
|
@@ -12,8 +12,8 @@ const foldLogin = Update.foldChild({
|
|
|
12
12
|
write: (model, nextLoginModel) =>
|
|
13
13
|
evo(model, { loginModel: () => nextLoginModel }),
|
|
14
14
|
toParentMessage: message => Message.GotLoginMessage({ message }),
|
|
15
|
-
toParentOutMessage:
|
|
16
|
-
|
|
15
|
+
toParentOutMessage: Match.type<Login.OutMessage>().pipe(
|
|
16
|
+
Match.tagsExhaustive({
|
|
17
17
|
SucceededLogin: ({ session }) => OutMessage.SucceededLogin({ session }),
|
|
18
18
|
}),
|
|
19
19
|
),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Match
|
|
1
|
+
import { Match } from 'effect'
|
|
2
2
|
import { Submodel } from 'foldkit'
|
|
3
3
|
|
|
4
4
|
import { notFoundView } from '../../notFoundView'
|
|
@@ -12,8 +12,8 @@ export const view = Submodel.defineView<Model, Message>((model, h) =>
|
|
|
12
12
|
h.div(
|
|
13
13
|
[h.Class('py-8')],
|
|
14
14
|
[
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
Match.value(model.route).pipe(
|
|
16
|
+
Match.tagsExhaustive({
|
|
17
17
|
Home: () => Home.view(h),
|
|
18
18
|
Login: () =>
|
|
19
19
|
h.submodel({
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Schema
|
|
1
|
+
import { Schema, pipe } from 'effect'
|
|
2
2
|
import { Route } from 'foldkit'
|
|
3
3
|
import { defineRouteUnion, literal } from 'foldkit/route'
|
|
4
4
|
|
|
@@ -7,7 +7,7 @@ export const AppRoute = defineRouteUnion({
|
|
|
7
7
|
Login: {},
|
|
8
8
|
Dashboard: {},
|
|
9
9
|
Settings: {},
|
|
10
|
-
NotFound: { path:
|
|
10
|
+
NotFound: { path: Schema.String },
|
|
11
11
|
})
|
|
12
12
|
|
|
13
13
|
export type AppRoute = typeof AppRoute.Type
|