create-foldkit-app 0.29.0 → 0.29.1
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/AGENTS.md +5 -112
- package/dist/templates/base/FOLDKIT.md +144 -0
- package/dist/templates/examples/api-cache/src/main.ts +36 -40
- package/dist/templates/examples/auth/src/main.ts +16 -15
- package/dist/templates/examples/auth/src/page/loggedIn/update.ts +10 -11
- package/dist/templates/examples/auth/src/page/loggedOut/page/login.ts +44 -55
- package/dist/templates/examples/auth/src/page/loggedOut/update.ts +8 -12
- package/dist/templates/examples/auth/src/update.ts +67 -73
- package/dist/templates/examples/canvas-art/src/main.ts +32 -31
- package/dist/templates/examples/charting/src/init.test.ts +6 -3
- package/dist/templates/examples/charting/src/init.ts +4 -4
- package/dist/templates/examples/charting/src/update.ts +34 -38
- package/dist/templates/examples/counter/src/main.ts +13 -13
- package/dist/templates/examples/counters/src/counter.ts +9 -8
- package/dist/templates/examples/counters/src/main.ts +20 -26
- package/dist/templates/examples/crash-view/src/main.ts +5 -3
- package/dist/templates/examples/embedding/src/main.ts +11 -9
- package/dist/templates/examples/form/src/main.ts +79 -89
- package/dist/templates/examples/generative-art/src/main.ts +6 -4
- package/dist/templates/examples/generative-art/src/update.ts +26 -23
- package/dist/templates/examples/interrupting-commands/src/main.ts +68 -66
- package/dist/templates/examples/job-application/src/main.ts +3 -4
- package/dist/templates/examples/job-application/src/step/attachments.ts +16 -19
- package/dist/templates/examples/job-application/src/step/coverLetter.ts +5 -5
- package/dist/templates/examples/job-application/src/step/education/education.ts +12 -17
- package/dist/templates/examples/job-application/src/step/education/entry.ts +29 -42
- package/dist/templates/examples/job-application/src/step/personalInfo.ts +35 -44
- package/dist/templates/examples/job-application/src/step/skills/entry.ts +15 -21
- package/dist/templates/examples/job-application/src/step/skills/skills.ts +12 -17
- package/dist/templates/examples/job-application/src/step/workHistory/entry.ts +41 -58
- package/dist/templates/examples/job-application/src/step/workHistory/workHistory.ts +12 -17
- package/dist/templates/examples/job-application/src/update.ts +26 -29
- package/dist/templates/examples/kanban/src/main.ts +3 -4
- package/dist/templates/examples/kanban/src/update.ts +31 -31
- package/dist/templates/examples/managed-resource-layer/src/main.ts +30 -34
- package/dist/templates/examples/map/src/main.ts +48 -56
- package/dist/templates/examples/pixel-art/src/comparison.bench.test.ts +34 -13
- package/dist/templates/examples/pixel-art/src/main.bench.ts +3 -3
- package/dist/templates/examples/pixel-art/src/main.ts +3 -4
- package/dist/templates/examples/pixel-art/src/update.ts +109 -100
- package/dist/templates/examples/query-sync/src/main.ts +27 -25
- package/dist/templates/examples/route-transitions/src/main.ts +46 -43
- package/dist/templates/examples/route-transitions/src/story.test.ts +11 -11
- package/dist/templates/examples/routing/src/main.ts +16 -14
- package/dist/templates/examples/routing/src/page/people.ts +23 -28
- package/dist/templates/examples/shopping-cart/src/main.ts +41 -42
- package/dist/templates/examples/shopping-cart/src/page/products.ts +28 -35
- package/dist/templates/examples/slow-warnings/src/main.ts +23 -32
- package/dist/templates/examples/snake/src/main.ts +135 -143
- package/dist/templates/examples/ssg/src/main.ts +20 -17
- package/dist/templates/examples/ssr/src/main.ts +20 -24
- package/dist/templates/examples/state-machine/src/main.ts +24 -11
- package/dist/templates/examples/state-machine/src/story.test.ts +2 -2
- package/dist/templates/examples/stopwatch/src/main.ts +42 -50
- package/dist/templates/examples/todo/src/main.ts +152 -160
- package/dist/templates/examples/ui-showcase/src/main.ts +53 -54
- package/dist/templates/examples/ui-showcase/src/scene.test.ts +2 -2
- package/dist/templates/examples/ui-showcase/src/story.test.ts +2 -2
- package/dist/templates/examples/ui-showcase/src/ui/init.ts +6 -7
- package/dist/templates/examples/ui-showcase/src/ui/update.ts +265 -336
- package/dist/templates/examples/view-transitions/src/main.ts +18 -17
- package/dist/templates/examples/weather/src/main.ts +33 -40
- package/dist/templates/examples/web-components/src/main.ts +14 -17
- package/dist/templates/examples/websocket-chat/src/main.ts +44 -50
- package/dist/templates/release.json +8 -8
- package/dist/templates/rendering/ssg/src/main.ts +20 -17
- package/dist/templates/rendering/ssr/src/main.ts +20 -24
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Array, Effect, Match as M, Option, Schema as S, String } from 'effect'
|
|
2
|
-
import { Command, Runtime } from 'foldkit'
|
|
2
|
+
import { Command, Runtime, type Update } from 'foldkit'
|
|
3
3
|
import { Document, Html, HtmlBuilder } from 'foldkit/html'
|
|
4
4
|
import { defineMessageUnion } from 'foldkit/message'
|
|
5
5
|
import { UrlRequest, load, pushUrl } from 'foldkit/navigation'
|
|
@@ -36,7 +36,7 @@ export type Message = typeof Message.Type
|
|
|
36
36
|
|
|
37
37
|
export const init: Runtime.RoutingApplicationInit<Model, Message> = (
|
|
38
38
|
url: Url,
|
|
39
|
-
) =>
|
|
39
|
+
) => ({ model: { route: urlToAppRoute(url), filterText: '' } })
|
|
40
40
|
|
|
41
41
|
// COMMAND
|
|
42
42
|
|
|
@@ -56,35 +56,36 @@ const LoadExternal = Command.define('LoadExternal', {
|
|
|
56
56
|
|
|
57
57
|
// UPDATE
|
|
58
58
|
|
|
59
|
-
type UpdateReturn =
|
|
59
|
+
type UpdateReturn = Update.Return<Model, Message>
|
|
60
60
|
const withUpdateReturn = M.withReturnType<UpdateReturn>()
|
|
61
61
|
|
|
62
62
|
export const update = (model: Model, message: Message) =>
|
|
63
63
|
Message.match<UpdateReturn>(message, {
|
|
64
|
-
CompletedNavigateInternal: () =>
|
|
65
|
-
CompletedLoadExternal: () =>
|
|
64
|
+
CompletedNavigateInternal: () => ({ model }),
|
|
65
|
+
CompletedLoadExternal: () => ({ model }),
|
|
66
66
|
|
|
67
67
|
ClickedLink: ({ request }) =>
|
|
68
68
|
M.value(request).pipe(
|
|
69
69
|
withUpdateReturn,
|
|
70
70
|
M.tagsExhaustive({
|
|
71
|
-
Internal: ({ url }) =>
|
|
71
|
+
Internal: ({ url }) => ({
|
|
72
72
|
model,
|
|
73
|
-
[NavigateInternal({ url: urlToString(url) })],
|
|
74
|
-
|
|
75
|
-
External: ({ href }) =>
|
|
73
|
+
commands: [NavigateInternal({ url: urlToString(url) })],
|
|
74
|
+
}),
|
|
75
|
+
External: ({ href }) => ({
|
|
76
|
+
model,
|
|
77
|
+
commands: [LoadExternal({ href })],
|
|
78
|
+
}),
|
|
76
79
|
}),
|
|
77
80
|
),
|
|
78
81
|
|
|
79
|
-
ChangedUrl: ({ url }) =>
|
|
80
|
-
evo(model, { route: () => urlToAppRoute(url) }),
|
|
81
|
-
|
|
82
|
-
],
|
|
82
|
+
ChangedUrl: ({ url }) => ({
|
|
83
|
+
model: evo(model, { route: () => urlToAppRoute(url) }),
|
|
84
|
+
}),
|
|
83
85
|
|
|
84
|
-
UpdatedFilterText: ({ filterText }) =>
|
|
85
|
-
evo(model, { filterText: () => filterText }),
|
|
86
|
-
|
|
87
|
-
],
|
|
86
|
+
UpdatedFilterText: ({ filterText }) => ({
|
|
87
|
+
model: evo(model, { filterText: () => filterText }),
|
|
88
|
+
}),
|
|
88
89
|
})
|
|
89
90
|
|
|
90
91
|
// NOTE: every arm past the guard is a navigation, so none return `false`.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Array, Effect, Match as M, Option, Schema as S, String } from 'effect'
|
|
2
2
|
import { HttpClient, HttpClientRequest } from 'effect/unstable/http'
|
|
3
|
-
import { AsyncData, Command, Http, Runtime } from 'foldkit'
|
|
3
|
+
import { AsyncData, Command, Http, Runtime, type Update } from 'foldkit'
|
|
4
4
|
import { Document, Html, HtmlBuilder } from 'foldkit/html'
|
|
5
5
|
import { defineMessageUnion } from 'foldkit/message'
|
|
6
6
|
import { evo } from 'foldkit/struct'
|
|
@@ -40,53 +40,46 @@ export const Message = defineMessageUnion({
|
|
|
40
40
|
export type Message = typeof Message.Type
|
|
41
41
|
|
|
42
42
|
export const update = (model: Model, message: Message) =>
|
|
43
|
-
Message.match<
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
return [
|
|
58
|
-
evo(model, {
|
|
59
|
-
weather: () => WeatherAsyncData.Loading(),
|
|
60
|
-
}),
|
|
61
|
-
[FetchWeather({ zipCode: model.zipCodeInput })],
|
|
62
|
-
]
|
|
63
|
-
},
|
|
64
|
-
|
|
65
|
-
SucceededFetchWeather: ({ weather }) => [
|
|
66
|
-
evo(model, {
|
|
67
|
-
weather: () => WeatherAsyncData.Success({ data: weather }),
|
|
68
|
-
}),
|
|
69
|
-
[],
|
|
70
|
-
],
|
|
71
|
-
|
|
72
|
-
FailedFetchWeather: ({ error }) => [
|
|
73
|
-
evo(model, {
|
|
74
|
-
weather: () => WeatherAsyncData.Failure({ error }),
|
|
43
|
+
Message.match<Update.Return<Model, Message>>(message, {
|
|
44
|
+
UpdatedZipCodeInput: ({ value }) => ({
|
|
45
|
+
model: evo(model, {
|
|
46
|
+
zipCodeInput: () => value,
|
|
47
|
+
}),
|
|
48
|
+
}),
|
|
49
|
+
|
|
50
|
+
SubmittedWeatherForm: () => {
|
|
51
|
+
if (AsyncData.isPending(model.weather)) {
|
|
52
|
+
return { model }
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
model: evo(model, {
|
|
56
|
+
weather: () => WeatherAsyncData.Loading(),
|
|
75
57
|
}),
|
|
76
|
-
[],
|
|
77
|
-
|
|
58
|
+
commands: [FetchWeather({ zipCode: model.zipCodeInput })],
|
|
59
|
+
}
|
|
78
60
|
},
|
|
79
|
-
|
|
61
|
+
|
|
62
|
+
SucceededFetchWeather: ({ weather }) => ({
|
|
63
|
+
model: evo(model, {
|
|
64
|
+
weather: () => WeatherAsyncData.Success({ data: weather }),
|
|
65
|
+
}),
|
|
66
|
+
}),
|
|
67
|
+
|
|
68
|
+
FailedFetchWeather: ({ error }) => ({
|
|
69
|
+
model: evo(model, {
|
|
70
|
+
weather: () => WeatherAsyncData.Failure({ error }),
|
|
71
|
+
}),
|
|
72
|
+
}),
|
|
73
|
+
})
|
|
80
74
|
|
|
81
75
|
// INIT
|
|
82
76
|
|
|
83
|
-
export const init: Runtime.ApplicationInit<Model, Message> = () =>
|
|
84
|
-
{
|
|
77
|
+
export const init: Runtime.ApplicationInit<Model, Message> = () => ({
|
|
78
|
+
model: {
|
|
85
79
|
zipCodeInput: '',
|
|
86
80
|
weather: WeatherAsyncData.Idle(),
|
|
87
81
|
},
|
|
88
|
-
|
|
89
|
-
]
|
|
82
|
+
})
|
|
90
83
|
|
|
91
84
|
// COMMAND
|
|
92
85
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { clsx } from 'clsx'
|
|
2
2
|
import { Schema as S } from 'effect'
|
|
3
|
-
import {
|
|
3
|
+
import { CustomElement, Runtime, type Update } from 'foldkit'
|
|
4
4
|
import { Document, Html, HtmlBuilder } from 'foldkit/html'
|
|
5
5
|
import { defineMessageUnion } from 'foldkit/message'
|
|
6
6
|
import { evo } from 'foldkit/struct'
|
|
@@ -34,30 +34,27 @@ const DEFAULT_CONTENT = 'https://foldkit.dev'
|
|
|
34
34
|
const DEFAULT_FILL_COLOR = '#1e1b4b'
|
|
35
35
|
const DEFAULT_BACKGROUND_COLOR = '#fef3c7'
|
|
36
36
|
|
|
37
|
-
export const init: Runtime.ApplicationInit<Model, Message> = () =>
|
|
38
|
-
{
|
|
37
|
+
export const init: Runtime.ApplicationInit<Model, Message> = () => ({
|
|
38
|
+
model: {
|
|
39
39
|
content: DEFAULT_CONTENT,
|
|
40
40
|
fillColor: DEFAULT_FILL_COLOR,
|
|
41
41
|
backgroundColor: DEFAULT_BACKGROUND_COLOR,
|
|
42
42
|
},
|
|
43
|
-
|
|
44
|
-
]
|
|
43
|
+
})
|
|
45
44
|
|
|
46
45
|
// UPDATE
|
|
47
46
|
|
|
48
|
-
type UpdateReturn = readonly [Model, ReadonlyArray<Command.Command<Message>>]
|
|
49
|
-
|
|
50
47
|
export const update = (model: Model, message: Message) =>
|
|
51
|
-
Message.match<
|
|
52
|
-
UpdatedContent: ({ value }) =>
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
48
|
+
Message.match<Update.Return<Model, Message>>(message, {
|
|
49
|
+
UpdatedContent: ({ value }) => ({
|
|
50
|
+
model: evo(model, { content: () => value }),
|
|
51
|
+
}),
|
|
52
|
+
ChangedFillColor: ({ value }) => ({
|
|
53
|
+
model: evo(model, { fillColor: () => value }),
|
|
54
|
+
}),
|
|
55
|
+
ChangedBackgroundColor: ({ value }) => ({
|
|
56
|
+
model: evo(model, { backgroundColor: () => value }),
|
|
57
|
+
}),
|
|
61
58
|
})
|
|
62
59
|
|
|
63
60
|
// WEB COMPONENT
|
|
@@ -10,7 +10,13 @@ import {
|
|
|
10
10
|
Stream,
|
|
11
11
|
String,
|
|
12
12
|
} from 'effect'
|
|
13
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
Command,
|
|
15
|
+
ManagedResource,
|
|
16
|
+
Runtime,
|
|
17
|
+
Subscription,
|
|
18
|
+
type Update,
|
|
19
|
+
} from 'foldkit'
|
|
14
20
|
import { Document, Html, HtmlBuilder } from 'foldkit/html'
|
|
15
21
|
import { defineMessageUnion } from 'foldkit/message'
|
|
16
22
|
import { ts } from 'foldkit/schema'
|
|
@@ -81,102 +87,90 @@ export type Message = typeof Message.Type
|
|
|
81
87
|
|
|
82
88
|
// UPDATE
|
|
83
89
|
|
|
90
|
+
type UpdateReturn = Update.Return<Model, Message, ChatSocketService>
|
|
91
|
+
|
|
84
92
|
export const update = (model: Model, message: Message) =>
|
|
85
|
-
Message.match<
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
ClickedConnect: () => [
|
|
89
|
-
evo(model, {
|
|
93
|
+
Message.match<UpdateReturn>(message, {
|
|
94
|
+
ClickedConnect: () => ({
|
|
95
|
+
model: evo(model, {
|
|
90
96
|
connection: () => ConnectionConnecting(),
|
|
91
97
|
}),
|
|
92
|
-
|
|
93
|
-
],
|
|
98
|
+
}),
|
|
94
99
|
|
|
95
|
-
Connected: () =>
|
|
96
|
-
evo(model, {
|
|
100
|
+
Connected: () => ({
|
|
101
|
+
model: evo(model, {
|
|
97
102
|
connection: () => ConnectionConnected(),
|
|
98
103
|
}),
|
|
99
|
-
|
|
100
|
-
],
|
|
104
|
+
}),
|
|
101
105
|
|
|
102
|
-
Disconnected: () =>
|
|
103
|
-
evo(model, {
|
|
106
|
+
Disconnected: () => ({
|
|
107
|
+
model: evo(model, {
|
|
104
108
|
connection: () => ConnectionDisconnected(),
|
|
105
109
|
messages: () => [],
|
|
106
110
|
}),
|
|
107
|
-
|
|
108
|
-
],
|
|
111
|
+
}),
|
|
109
112
|
|
|
110
|
-
FailedConnect: ({ error }) =>
|
|
111
|
-
evo(model, {
|
|
113
|
+
FailedConnect: ({ error }) => ({
|
|
114
|
+
model: evo(model, {
|
|
112
115
|
connection: () => ConnectionError({ error }),
|
|
113
116
|
}),
|
|
114
|
-
|
|
115
|
-
],
|
|
117
|
+
}),
|
|
116
118
|
|
|
117
|
-
UpdatedMessageInput: ({ value }) =>
|
|
118
|
-
evo(model, {
|
|
119
|
+
UpdatedMessageInput: ({ value }) => ({
|
|
120
|
+
model: evo(model, {
|
|
119
121
|
messageInput: () => value,
|
|
120
122
|
}),
|
|
121
|
-
|
|
122
|
-
],
|
|
123
|
+
}),
|
|
123
124
|
|
|
124
125
|
SubmittedMessage: () => {
|
|
125
126
|
const trimmedMessage = model.messageInput.trim()
|
|
126
127
|
|
|
127
128
|
if (String.isEmpty(trimmedMessage)) {
|
|
128
|
-
return
|
|
129
|
+
return { model }
|
|
129
130
|
}
|
|
130
131
|
|
|
131
132
|
return M.value(model.connection).pipe(
|
|
132
|
-
M.withReturnType<
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
ReadonlyArray<Command.Command<Message, never, ChatSocketService>>,
|
|
136
|
-
]
|
|
137
|
-
>(),
|
|
138
|
-
M.tag('ConnectionConnected', () => [
|
|
139
|
-
evo(model, {
|
|
133
|
+
M.withReturnType<UpdateReturn>(),
|
|
134
|
+
M.tag('ConnectionConnected', () => ({
|
|
135
|
+
model: evo(model, {
|
|
140
136
|
messageInput: () => '',
|
|
141
137
|
}),
|
|
142
|
-
[SendMessage({ text: trimmedMessage })],
|
|
143
|
-
|
|
144
|
-
M.orElse(() =>
|
|
138
|
+
commands: [SendMessage({ text: trimmedMessage })],
|
|
139
|
+
})),
|
|
140
|
+
M.orElse(() => ({ model })),
|
|
145
141
|
)
|
|
146
142
|
},
|
|
147
143
|
|
|
148
|
-
SucceededSendMessage: ({ text }) =>
|
|
144
|
+
SucceededSendMessage: ({ text }) => ({
|
|
149
145
|
model,
|
|
150
|
-
[TimestampSentMessage({ text })],
|
|
151
|
-
|
|
146
|
+
commands: [TimestampSentMessage({ text })],
|
|
147
|
+
}),
|
|
152
148
|
|
|
153
|
-
ReceivedMessage: ({ text }) =>
|
|
149
|
+
ReceivedMessage: ({ text }) => ({
|
|
154
150
|
model,
|
|
155
|
-
[TimestampReceivedMessage({ text })],
|
|
156
|
-
|
|
151
|
+
commands: [TimestampReceivedMessage({ text })],
|
|
152
|
+
}),
|
|
157
153
|
|
|
158
154
|
TimestampedMessage: ({ text, zoned, isSent }) => {
|
|
159
155
|
const newMessage = ChatMessage.make({ text, zoned, isSent })
|
|
160
156
|
|
|
161
|
-
return
|
|
162
|
-
evo(model, {
|
|
157
|
+
return {
|
|
158
|
+
model: evo(model, {
|
|
163
159
|
messages: messages => [...messages, newMessage],
|
|
164
160
|
}),
|
|
165
|
-
|
|
166
|
-
]
|
|
161
|
+
}
|
|
167
162
|
},
|
|
168
163
|
})
|
|
169
164
|
|
|
170
165
|
// INIT
|
|
171
166
|
|
|
172
|
-
export const init: Runtime.ApplicationInit<Model, Message> = () =>
|
|
173
|
-
{
|
|
167
|
+
export const init: Runtime.ApplicationInit<Model, Message> = () => ({
|
|
168
|
+
model: {
|
|
174
169
|
connection: ConnectionDisconnected(),
|
|
175
170
|
messages: [],
|
|
176
171
|
messageInput: '',
|
|
177
172
|
},
|
|
178
|
-
|
|
179
|
-
]
|
|
173
|
+
})
|
|
180
174
|
|
|
181
175
|
// COMMAND
|
|
182
176
|
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schemaVersion": 1,
|
|
3
3
|
"channel": "stable",
|
|
4
|
-
"sourceCommit": "
|
|
4
|
+
"sourceCommit": "aafef6783aece18b85bf54919353a70b4e895e19",
|
|
5
5
|
"packages": {
|
|
6
|
-
"create-foldkit-app": "0.29.
|
|
7
|
-
"@foldkit/devtools": "0.
|
|
6
|
+
"create-foldkit-app": "0.29.1",
|
|
7
|
+
"@foldkit/devtools": "0.151.0",
|
|
8
8
|
"@foldkit/devtools-mcp": "0.17.0",
|
|
9
|
-
"foldkit": "0.
|
|
9
|
+
"foldkit": "0.151.0",
|
|
10
10
|
"@foldkit/markdown": "0.6.0",
|
|
11
|
-
"@foldkit/oxlint-plugin": "0.
|
|
12
|
-
"@foldkit/ui": "0.
|
|
11
|
+
"@foldkit/oxlint-plugin": "0.8.0",
|
|
12
|
+
"@foldkit/ui": "0.151.0",
|
|
13
13
|
"@foldkit/vite-plugin": "0.17.0"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@foldkit/devtools": "0.
|
|
16
|
+
"@foldkit/devtools": "0.151.0",
|
|
17
17
|
"@foldkit/vite-plugin": "0.17.0",
|
|
18
18
|
"@foldkit/devtools-mcp": "0.17.0",
|
|
19
|
-
"@foldkit/oxlint-plugin": "0.
|
|
19
|
+
"@foldkit/oxlint-plugin": "0.8.0",
|
|
20
20
|
"@trivago/prettier-plugin-sort-imports": "^6.0.2",
|
|
21
21
|
"@types/node": "^25.9.3",
|
|
22
22
|
"happy-dom": "^20.10.4",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Effect, Match as M, Schema as S, pipe } from 'effect'
|
|
2
|
-
import { Command, Runtime } from 'foldkit'
|
|
2
|
+
import { Command, Runtime, type Update } from 'foldkit'
|
|
3
3
|
import { type Document, type Html, type HtmlBuilder } from 'foldkit/html'
|
|
4
4
|
import { defineMessageUnion } from 'foldkit/message'
|
|
5
5
|
import { UrlRequest, load, pushUrl } from 'foldkit/navigation'
|
|
@@ -30,10 +30,9 @@ export type Message = typeof Message.Type
|
|
|
30
30
|
|
|
31
31
|
// INIT
|
|
32
32
|
|
|
33
|
-
export const init: Runtime.RoutingApplicationInit<Model, Message> = url =>
|
|
34
|
-
{ route: urlToAppRoute(url), count: 0 },
|
|
35
|
-
|
|
36
|
-
]
|
|
33
|
+
export const init: Runtime.RoutingApplicationInit<Model, Message> = url => ({
|
|
34
|
+
model: { route: urlToAppRoute(url), count: 0 },
|
|
35
|
+
})
|
|
37
36
|
|
|
38
37
|
// COMMAND
|
|
39
38
|
|
|
@@ -53,29 +52,33 @@ const LoadExternal = Command.define('LoadExternal', {
|
|
|
53
52
|
|
|
54
53
|
// UPDATE
|
|
55
54
|
|
|
56
|
-
type UpdateReturn =
|
|
55
|
+
type UpdateReturn = Update.Return<Model, Message>
|
|
57
56
|
const withUpdateReturn = M.withReturnType<UpdateReturn>()
|
|
58
57
|
|
|
59
58
|
export const update = (model: Model, message: Message) =>
|
|
60
59
|
Message.match<UpdateReturn>(message, {
|
|
61
|
-
ClickedIncrement: () =>
|
|
60
|
+
ClickedIncrement: () => ({
|
|
61
|
+
model: evo(model, { count: count => count + 1 }),
|
|
62
|
+
}),
|
|
62
63
|
ClickedLink: ({ request }) =>
|
|
63
64
|
M.value(request).pipe(
|
|
64
65
|
withUpdateReturn,
|
|
65
66
|
M.tagsExhaustive({
|
|
66
|
-
Internal: ({ url }) =>
|
|
67
|
+
Internal: ({ url }) => ({
|
|
67
68
|
model,
|
|
68
|
-
[NavigateInternal({ url: urlToString(url) })],
|
|
69
|
-
|
|
70
|
-
External: ({ href }) =>
|
|
69
|
+
commands: [NavigateInternal({ url: urlToString(url) })],
|
|
70
|
+
}),
|
|
71
|
+
External: ({ href }) => ({
|
|
72
|
+
model,
|
|
73
|
+
commands: [LoadExternal({ href })],
|
|
74
|
+
}),
|
|
71
75
|
}),
|
|
72
76
|
),
|
|
73
|
-
ChangedUrl: ({ url }) =>
|
|
74
|
-
evo(model, { route: () => urlToAppRoute(url) }),
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
CompletedLoadExternal: () => [model, []],
|
|
77
|
+
ChangedUrl: ({ url }) => ({
|
|
78
|
+
model: evo(model, { route: () => urlToAppRoute(url) }),
|
|
79
|
+
}),
|
|
80
|
+
CompletedNavigateInternal: () => ({ model }),
|
|
81
|
+
CompletedLoadExternal: () => ({ model }),
|
|
79
82
|
})
|
|
80
83
|
|
|
81
84
|
// VIEW
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Effect, Schema as S } from 'effect'
|
|
2
|
-
import { Command, Runtime } from 'foldkit'
|
|
2
|
+
import { Command, Runtime, type Update } from 'foldkit'
|
|
3
3
|
import { type Document, type HtmlBuilder } from 'foldkit/html'
|
|
4
4
|
import { defineMessageUnion } from 'foldkit/message'
|
|
5
5
|
import { evo } from 'foldkit/struct'
|
|
@@ -39,26 +39,23 @@ export type Message = typeof Message.Type
|
|
|
39
39
|
// UPDATE
|
|
40
40
|
|
|
41
41
|
export const update = (model: Model, message: Message) =>
|
|
42
|
-
Message.match<
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
[PersistCount({ count: nextCount })],
|
|
50
|
-
]
|
|
51
|
-
},
|
|
52
|
-
ClickedIncrement: () => {
|
|
53
|
-
const nextCount = model.count + 1
|
|
54
|
-
return [
|
|
55
|
-
evo(model, { count: () => nextCount }),
|
|
56
|
-
[PersistCount({ count: nextCount })],
|
|
57
|
-
]
|
|
58
|
-
},
|
|
59
|
-
CompletedPersistCount: () => [model, []],
|
|
42
|
+
Message.match<Update.Return<Model, Message>>(message, {
|
|
43
|
+
ClickedDecrement: () => {
|
|
44
|
+
const nextCount = model.count - 1
|
|
45
|
+
return {
|
|
46
|
+
model: evo(model, { count: () => nextCount }),
|
|
47
|
+
commands: [PersistCount({ count: nextCount })],
|
|
48
|
+
}
|
|
60
49
|
},
|
|
61
|
-
|
|
50
|
+
ClickedIncrement: () => {
|
|
51
|
+
const nextCount = model.count + 1
|
|
52
|
+
return {
|
|
53
|
+
model: evo(model, { count: () => nextCount }),
|
|
54
|
+
commands: [PersistCount({ count: nextCount })],
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
CompletedPersistCount: () => ({ model }),
|
|
58
|
+
})
|
|
62
59
|
|
|
63
60
|
// COMMAND
|
|
64
61
|
|
|
@@ -78,14 +75,13 @@ export const PersistCount = Command.define('PersistCount', {
|
|
|
78
75
|
|
|
79
76
|
// INIT
|
|
80
77
|
|
|
81
|
-
export const init: Runtime.ApplicationInit<Model, Message, Flags> = flags =>
|
|
82
|
-
{
|
|
78
|
+
export const init: Runtime.ApplicationInit<Model, Message, Flags> = flags => ({
|
|
79
|
+
model: {
|
|
83
80
|
count: flags.initialCount,
|
|
84
81
|
renderedAt: flags.renderedAt,
|
|
85
82
|
renderedOn: flags.renderedOn,
|
|
86
83
|
},
|
|
87
|
-
|
|
88
|
-
]
|
|
84
|
+
})
|
|
89
85
|
|
|
90
86
|
// VIEW
|
|
91
87
|
|