create-foldkit-app 0.35.1 → 0.35.2
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 +2 -2
- package/dist/templates/examples/api-cache/package.json +2 -2
- package/dist/templates/examples/api-cache/src/main.fixture.ts +4 -4
- package/dist/templates/examples/api-cache/src/main.ts +12 -12
- package/dist/templates/examples/api-cache/src/story.test.ts +6 -6
- package/dist/templates/examples/auth/package.json +2 -2
- package/dist/templates/examples/auth/src/page/loggedOut/page/login.scene.test.ts +2 -2
- package/dist/templates/examples/auth/src/page/loggedOut/page/login.story.test.ts +2 -2
- package/dist/templates/examples/auth/src/page/loggedOut/page/login.ts +5 -5
- package/dist/templates/examples/auth/src/page/loggedOut/update.ts +2 -2
- package/dist/templates/examples/auth/src/scene.test.ts +2 -2
- package/dist/templates/examples/auth/src/update.ts +3 -3
- package/dist/templates/examples/canvas-art/package.json +2 -2
- package/dist/templates/examples/canvas-art/src/main.ts +6 -6
- package/dist/templates/examples/canvas-art/src/scene.test.ts +3 -3
- package/dist/templates/examples/canvas-art/src/story.test.ts +3 -3
- package/dist/templates/examples/charting/package.json +2 -2
- package/dist/templates/examples/charting/src/main.fixture.ts +2 -2
- package/dist/templates/examples/charting/src/scene.test.ts +3 -3
- package/dist/templates/examples/charting/src/story.test.ts +2 -2
- package/dist/templates/examples/charting/src/update.ts +18 -16
- package/dist/templates/examples/counter/package.json +2 -2
- package/dist/templates/examples/counter/src/main.ts +4 -4
- package/dist/templates/examples/counters/package.json +2 -2
- package/dist/templates/examples/counters/src/counter.ts +3 -3
- package/dist/templates/examples/counters/src/main.ts +7 -5
- package/dist/templates/examples/crash-view/package.json +2 -2
- package/dist/templates/examples/embedding/package.json +2 -2
- package/dist/templates/examples/embedding/src/main.ts +5 -3
- package/dist/templates/examples/embedding/src/scene.test.ts +2 -2
- package/dist/templates/examples/embedding/src/story.test.ts +2 -2
- package/dist/templates/examples/form/package.json +2 -2
- package/dist/templates/examples/form/src/main.ts +9 -9
- package/dist/templates/examples/form/src/scene.test.ts +5 -5
- package/dist/templates/examples/form/src/story.test.ts +4 -4
- package/dist/templates/examples/generative-art/package.json +2 -2
- package/dist/templates/examples/generative-art/src/scene.test.ts +2 -2
- package/dist/templates/examples/generative-art/src/story.test.ts +3 -3
- package/dist/templates/examples/generative-art/src/update.ts +11 -11
- package/dist/templates/examples/interrupting-commands/package.json +2 -2
- package/dist/templates/examples/interrupting-commands/src/main.ts +8 -6
- package/dist/templates/examples/job-application/package.json +2 -2
- package/dist/templates/examples/job-application/src/main.fixture.ts +9 -9
- package/dist/templates/examples/job-application/src/scene.test.ts +13 -13
- package/dist/templates/examples/job-application/src/step/attachments/attachments.ts +7 -7
- package/dist/templates/examples/job-application/src/step/coverLetter/coverLetter.ts +2 -2
- package/dist/templates/examples/job-application/src/step/education/education.ts +6 -6
- package/dist/templates/examples/job-application/src/step/education/entry/entry.ts +14 -8
- package/dist/templates/examples/job-application/src/step/personalInfo/personalInfo.ts +20 -15
- package/dist/templates/examples/job-application/src/step/personalInfo/story.test.ts +2 -2
- package/dist/templates/examples/job-application/src/step/skills/entry/entry.ts +7 -5
- package/dist/templates/examples/job-application/src/step/skills/skills.ts +6 -6
- package/dist/templates/examples/job-application/src/step/workHistory/entry/entry.ts +13 -12
- package/dist/templates/examples/job-application/src/step/workHistory/workHistory.ts +6 -6
- package/dist/templates/examples/job-application/src/story.test.ts +10 -10
- package/dist/templates/examples/job-application/src/update.ts +25 -18
- package/dist/templates/examples/kanban/package.json +2 -2
- package/dist/templates/examples/kanban/src/domain/column.ts +9 -6
- package/dist/templates/examples/kanban/src/update.ts +8 -8
- package/dist/templates/examples/managed-resource-layer/package.json +2 -2
- package/dist/templates/examples/managed-resource-layer/src/main.ts +11 -7
- package/dist/templates/examples/managed-resource-layer/src/story.test.ts +3 -3
- package/dist/templates/examples/map/package.json +2 -2
- package/dist/templates/examples/map/src/main.fixture.ts +2 -2
- package/dist/templates/examples/map/src/main.ts +11 -11
- package/dist/templates/examples/map/src/scene.test.ts +4 -4
- package/dist/templates/examples/map/src/story.test.ts +4 -4
- package/dist/templates/examples/pixel-art/package.json +2 -2
- package/dist/templates/examples/pixel-art/src/comparison.bench.test.ts +2 -2
- package/dist/templates/examples/pixel-art/src/main.bench.ts +7 -3
- package/dist/templates/examples/pixel-art/src/scene.test.ts +5 -5
- package/dist/templates/examples/pixel-art/src/story.test.ts +4 -4
- package/dist/templates/examples/pixel-art/src/subscription.ts +2 -2
- package/dist/templates/examples/pixel-art/src/update.ts +49 -33
- package/dist/templates/examples/query-sync/package.json +2 -2
- package/dist/templates/examples/query-sync/src/main.ts +4 -4
- package/dist/templates/examples/query-sync/src/scene.test.ts +4 -4
- package/dist/templates/examples/query-sync/src/story.test.ts +2 -2
- package/dist/templates/examples/route-transitions/package.json +2 -2
- package/dist/templates/examples/route-transitions/src/main.ts +10 -10
- package/dist/templates/examples/route-transitions/src/story.test.ts +10 -6
- package/dist/templates/examples/routing/package.json +2 -2
- package/dist/templates/examples/routing/src/main.ts +13 -17
- package/dist/templates/examples/routing/src/page/people.ts +4 -4
- package/dist/templates/examples/shopping-cart/package.json +2 -2
- package/dist/templates/examples/shopping-cart/src/domain/cart.ts +4 -4
- package/dist/templates/examples/shopping-cart/src/main.ts +12 -12
- package/dist/templates/examples/shopping-cart/src/page/products.ts +2 -2
- package/dist/templates/examples/shopping-cart/src/scene.test.ts +10 -8
- package/dist/templates/examples/shopping-cart/src/story.test.ts +7 -7
- package/dist/templates/examples/slow-warnings/package.json +2 -2
- package/dist/templates/examples/slow-warnings/src/handleSlow.test.ts +2 -2
- package/dist/templates/examples/slow-warnings/src/main.ts +8 -8
- package/dist/templates/examples/slow-warnings/src/scene.test.ts +2 -2
- package/dist/templates/examples/slow-warnings/src/story.test.ts +2 -2
- package/dist/templates/examples/snake/package.json +2 -2
- package/dist/templates/examples/snake/src/main.ts +10 -10
- package/dist/templates/examples/snake/src/scene.test.ts +10 -5
- package/dist/templates/examples/snake/src/story.test.ts +6 -6
- package/dist/templates/examples/ssg/package.json +2 -2
- package/dist/templates/examples/ssg/src/main.ts +3 -3
- package/dist/templates/examples/ssr/package.json +4 -4
- package/dist/templates/examples/ssr/src/main.ts +3 -3
- package/dist/templates/examples/state-machine/package.json +2 -2
- package/dist/templates/examples/state-machine/src/main.ts +14 -10
- package/dist/templates/examples/stopwatch/package.json +2 -2
- package/dist/templates/examples/stopwatch/src/main.ts +5 -5
- package/dist/templates/examples/stopwatch/src/story.test.ts +2 -2
- package/dist/templates/examples/todo/package.json +2 -2
- package/dist/templates/examples/todo/src/main.ts +17 -17
- package/dist/templates/examples/todo/src/scene.test.ts +4 -4
- package/dist/templates/examples/todo/src/story.test.ts +22 -16
- package/dist/templates/examples/ui-showcase/package.json +2 -2
- package/dist/templates/examples/ui-showcase/src/main.ts +8 -5
- package/dist/templates/examples/ui-showcase/src/story.test.ts +3 -3
- package/dist/templates/examples/ui-showcase/src/ui/init.ts +4 -1
- package/dist/templates/examples/ui-showcase/src/ui/subscriptions.ts +10 -0
- package/dist/templates/examples/ui-showcase/src/ui/update.ts +119 -91
- package/dist/templates/examples/ui-showcase/src/ui/view/toast.ts +20 -3
- package/dist/templates/examples/view-transitions/package.json +2 -2
- package/dist/templates/examples/view-transitions/src/main.ts +3 -3
- package/dist/templates/examples/weather/package.json +2 -2
- package/dist/templates/examples/weather/src/main.ts +5 -5
- package/dist/templates/examples/web-components/package.json +2 -2
- package/dist/templates/examples/web-components/src/main.ts +4 -4
- package/dist/templates/examples/websocket-chat/package.json +2 -2
- package/dist/templates/examples/websocket-chat/src/main.ts +8 -8
- package/dist/templates/examples/websocket-chat/src/scene.test.ts +18 -6
- package/dist/templates/examples/websocket-chat/src/story.test.ts +15 -9
- package/dist/templates/release.json +13 -13
- package/dist/templates/rendering/ssg/src/main.ts +3 -3
- package/dist/templates/rendering/ssr/scripts/serve.ts +2 -2
- package/dist/templates/rendering/ssr/src/main.ts +3 -3
- package/package.json +5 -5
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Option } from 'effect'
|
|
2
2
|
import { expect, given, placeholder, role, scene, text } from 'foldkit/scene'
|
|
3
|
-
import {
|
|
3
|
+
import { modifyFields } from 'foldkit/struct'
|
|
4
4
|
import { describe, test } from 'vitest'
|
|
5
5
|
|
|
6
6
|
import { Listbox } from '@foldkit/ui'
|
|
@@ -40,7 +40,7 @@ describe('view', () => {
|
|
|
40
40
|
scene(
|
|
41
41
|
{ update, view },
|
|
42
42
|
given(
|
|
43
|
-
|
|
43
|
+
modifyFields(browseModel, {
|
|
44
44
|
route: () =>
|
|
45
45
|
AppRoute.Browse({
|
|
46
46
|
search: Option.some('Tyranno'),
|
|
@@ -58,7 +58,7 @@ describe('view', () => {
|
|
|
58
58
|
scene(
|
|
59
59
|
{ update, view },
|
|
60
60
|
given(
|
|
61
|
-
|
|
61
|
+
modifyFields(browseModel, {
|
|
62
62
|
route: () =>
|
|
63
63
|
AppRoute.Browse({
|
|
64
64
|
search: Option.some('zzzNoMatch'),
|
|
@@ -76,7 +76,7 @@ describe('view', () => {
|
|
|
76
76
|
scene(
|
|
77
77
|
{ update, view },
|
|
78
78
|
given(
|
|
79
|
-
|
|
79
|
+
modifyFields(browseModel, {
|
|
80
80
|
route: () => AppRoute.NotFound({ path: '/oops' }),
|
|
81
81
|
}),
|
|
82
82
|
),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Option } from 'effect'
|
|
2
2
|
import { Command, given, message, model, story } from 'foldkit/story'
|
|
3
|
-
import {
|
|
3
|
+
import { modifyFields } from 'foldkit/struct'
|
|
4
4
|
import { fromString } from 'foldkit/url'
|
|
5
5
|
import { describe, expect, test } from 'vitest'
|
|
6
6
|
|
|
@@ -104,7 +104,7 @@ describe('update', () => {
|
|
|
104
104
|
story(
|
|
105
105
|
update,
|
|
106
106
|
given(
|
|
107
|
-
|
|
107
|
+
modifyFields(browseModel, {
|
|
108
108
|
route: () =>
|
|
109
109
|
AppRoute.Browse({
|
|
110
110
|
search: Option.some('foo'),
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
"test": "vitest run"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@effect/platform-browser": "4.0.0-rc.
|
|
13
|
-
"effect": "4.0.0-rc.
|
|
12
|
+
"@effect/platform-browser": "4.0.0-rc.116",
|
|
13
|
+
"effect": "4.0.0-rc.116",
|
|
14
14
|
"foldkit": "workspace:*"
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
@@ -5,7 +5,7 @@ import { defineMessageUnion } from 'foldkit/message'
|
|
|
5
5
|
import { UrlRequest, load, pushUrl } from 'foldkit/navigation'
|
|
6
6
|
import { Transition } from 'foldkit/route'
|
|
7
7
|
import { defineTaggedUnion } from 'foldkit/schema'
|
|
8
|
-
import {
|
|
8
|
+
import { modifyFields } from 'foldkit/struct'
|
|
9
9
|
import { Url, toString as urlToString } from 'foldkit/url'
|
|
10
10
|
|
|
11
11
|
import { type Painting, findPaintingWithIndex, paintings } from './data'
|
|
@@ -128,7 +128,7 @@ const nextSequenceNumber = (
|
|
|
128
128
|
const logTransition =
|
|
129
129
|
(transition: AppTransition): Step =>
|
|
130
130
|
model => ({
|
|
131
|
-
model:
|
|
131
|
+
model: modifyFields(model, {
|
|
132
132
|
transitionLog: transitionLog =>
|
|
133
133
|
pipe(
|
|
134
134
|
transitionLog,
|
|
@@ -148,7 +148,7 @@ const loadCatalogOnGalleryEntry =
|
|
|
148
148
|
Transition.isEntering(transition, 'Gallery') &&
|
|
149
149
|
model.catalogStatus !== 'Loading'
|
|
150
150
|
? {
|
|
151
|
-
model:
|
|
151
|
+
model: modifyFields(model, { catalogStatus: () => 'Loading' }),
|
|
152
152
|
commands: [LoadCatalog()],
|
|
153
153
|
}
|
|
154
154
|
: { model }
|
|
@@ -159,7 +159,7 @@ const loadPaintingOnEntry =
|
|
|
159
159
|
Option.match(Transition.entered(transition, 'Painting'), {
|
|
160
160
|
onNone: () => ({ model }),
|
|
161
161
|
onSome: ({ paintingId }) => ({
|
|
162
|
-
model:
|
|
162
|
+
model: modifyFields(model, {
|
|
163
163
|
paintingStatus: () => PaintingStatus.Loading({ paintingId }),
|
|
164
164
|
}),
|
|
165
165
|
commands: [LoadPainting({ paintingId })],
|
|
@@ -175,7 +175,7 @@ const reloadPaintingOnIdChange =
|
|
|
175
175
|
previousRoute.paintingId === nextRoute.paintingId
|
|
176
176
|
? { model }
|
|
177
177
|
: {
|
|
178
|
-
model:
|
|
178
|
+
model: modifyFields(model, {
|
|
179
179
|
paintingStatus: () =>
|
|
180
180
|
PaintingStatus.Loading({
|
|
181
181
|
paintingId: nextRoute.paintingId,
|
|
@@ -229,31 +229,31 @@ export const update = (model: Model, message: Message) =>
|
|
|
229
229
|
const nextRoute = urlToAppRoute(url)
|
|
230
230
|
const transition = Transition.make(model.route, nextRoute)
|
|
231
231
|
return handleTransition(
|
|
232
|
-
|
|
232
|
+
modifyFields(model, { route: () => nextRoute }),
|
|
233
233
|
transition,
|
|
234
234
|
)
|
|
235
235
|
},
|
|
236
236
|
|
|
237
237
|
SucceededLoadCatalog: () => ({
|
|
238
|
-
model:
|
|
238
|
+
model: modifyFields(model, { catalogStatus: () => 'Ready' }),
|
|
239
239
|
}),
|
|
240
240
|
|
|
241
241
|
SucceededLoadPainting: ({ paintingId }) =>
|
|
242
242
|
model.paintingStatus._tag === 'Loading' &&
|
|
243
243
|
model.paintingStatus.paintingId === paintingId
|
|
244
244
|
? {
|
|
245
|
-
model:
|
|
245
|
+
model: modifyFields(model, {
|
|
246
246
|
paintingStatus: () => PaintingStatus.Ready({ paintingId }),
|
|
247
247
|
}),
|
|
248
248
|
}
|
|
249
249
|
: { model },
|
|
250
250
|
|
|
251
251
|
UpdatedStudioDraft: ({ value }) => ({
|
|
252
|
-
model:
|
|
252
|
+
model: modifyFields(model, { studioDraft: () => value }),
|
|
253
253
|
}),
|
|
254
254
|
|
|
255
255
|
SucceededSaveDraft: ({ draft }) => ({
|
|
256
|
-
model:
|
|
256
|
+
model: modifyFields(model, { maybeSavedDraft: () => Option.some(draft) }),
|
|
257
257
|
}),
|
|
258
258
|
})
|
|
259
259
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Array, Option } from 'effect'
|
|
2
2
|
import { Command, given, message, model, story } from 'foldkit/story'
|
|
3
|
-
import {
|
|
3
|
+
import { modifyFields } from 'foldkit/struct'
|
|
4
4
|
import { fromString } from 'foldkit/url'
|
|
5
5
|
import { describe, expect, test } from 'vitest'
|
|
6
6
|
|
|
@@ -81,7 +81,11 @@ describe('update', () => {
|
|
|
81
81
|
test('re-entering the gallery while a catalog load is in flight does not fire another', () => {
|
|
82
82
|
story(
|
|
83
83
|
update,
|
|
84
|
-
given(
|
|
84
|
+
given(
|
|
85
|
+
modifyFields(modelOn(AppRoute.Home()), {
|
|
86
|
+
catalogStatus: () => 'Loading',
|
|
87
|
+
}),
|
|
88
|
+
),
|
|
85
89
|
message(
|
|
86
90
|
Message.ChangedUrl({ url: urlOrThrow('http://localhost/gallery') }),
|
|
87
91
|
),
|
|
@@ -121,7 +125,7 @@ describe('update', () => {
|
|
|
121
125
|
story(
|
|
122
126
|
update,
|
|
123
127
|
given(
|
|
124
|
-
|
|
128
|
+
modifyFields(modelOn(AppRoute.Painting({ paintingId: 1 })), {
|
|
125
129
|
paintingStatus: () => PaintingStatus.Ready({ paintingId: 1 }),
|
|
126
130
|
}),
|
|
127
131
|
),
|
|
@@ -153,7 +157,7 @@ describe('update', () => {
|
|
|
153
157
|
story(
|
|
154
158
|
update,
|
|
155
159
|
given(
|
|
156
|
-
|
|
160
|
+
modifyFields(modelOn(AppRoute.Painting({ paintingId: 1 })), {
|
|
157
161
|
paintingStatus: () => PaintingStatus.Ready({ paintingId: 1 }),
|
|
158
162
|
}),
|
|
159
163
|
),
|
|
@@ -173,7 +177,7 @@ describe('update', () => {
|
|
|
173
177
|
story(
|
|
174
178
|
update,
|
|
175
179
|
given(
|
|
176
|
-
|
|
180
|
+
modifyFields(modelOn(AppRoute.Painting({ paintingId: 2 })), {
|
|
177
181
|
paintingStatus: () => PaintingStatus.Loading({ paintingId: 2 }),
|
|
178
182
|
}),
|
|
179
183
|
),
|
|
@@ -190,7 +194,7 @@ describe('update', () => {
|
|
|
190
194
|
story(
|
|
191
195
|
update,
|
|
192
196
|
given(
|
|
193
|
-
|
|
197
|
+
modifyFields(modelOn(AppRoute.Studio()), {
|
|
194
198
|
studioDraft: () => 'half-finished thought',
|
|
195
199
|
}),
|
|
196
200
|
),
|
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
"test": "vitest run"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@effect/platform-browser": "4.0.0-rc.
|
|
12
|
+
"@effect/platform-browser": "4.0.0-rc.116",
|
|
13
13
|
"@foldkit/ui": "workspace:*",
|
|
14
|
-
"effect": "4.0.0-rc.
|
|
14
|
+
"effect": "4.0.0-rc.116",
|
|
15
15
|
"foldkit": "workspace:*"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
@@ -3,7 +3,7 @@ import { Command, Runtime, Subscription, 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'
|
|
6
|
-
import {
|
|
6
|
+
import { modifyFields } from 'foldkit/struct'
|
|
7
7
|
import { Url, toString as urlToString } from 'foldkit/url'
|
|
8
8
|
|
|
9
9
|
import {
|
|
@@ -105,7 +105,7 @@ const foldPeopleEntry = <Input>(
|
|
|
105
105
|
update,
|
|
106
106
|
read: model => Option.some(model.peoplePage),
|
|
107
107
|
write: (model, nextPeoplePage) =>
|
|
108
|
-
|
|
108
|
+
modifyFields(model, { peoplePage: () => nextPeoplePage }),
|
|
109
109
|
toParentMessage: message => Message.GotPeopleMessage({ message }),
|
|
110
110
|
})
|
|
111
111
|
|
|
@@ -115,7 +115,7 @@ const foldPeopleRouteChanged = foldPeopleEntry(People.informRouteChanged)
|
|
|
115
115
|
|
|
116
116
|
const setRoute =
|
|
117
117
|
(nextRoute: AppRoute): Update.Step<Model, Message> =>
|
|
118
|
-
model => ({ model:
|
|
118
|
+
model => ({ model: modifyFields(model, { route: () => nextRoute }) })
|
|
119
119
|
|
|
120
120
|
export const update = (model: Model, message: Message) =>
|
|
121
121
|
Message.match<UpdateReturn>(message, {
|
|
@@ -160,28 +160,24 @@ export const update = (model: Model, message: Message) =>
|
|
|
160
160
|
// SUBSCRIPTION
|
|
161
161
|
|
|
162
162
|
export const subscriptions = Subscription.make<Model, Message>()(() => ({
|
|
163
|
-
|
|
164
|
-
Subscription.
|
|
163
|
+
keyBindings: Subscription.persistent(
|
|
164
|
+
Subscription.keyBindings<Message>({
|
|
165
165
|
bindings: [
|
|
166
166
|
{
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
Message.EnteredNavigationShortcut({ shortcut: 'GH' }),
|
|
167
|
+
keys: ['G', 'H'],
|
|
168
|
+
mapEvent: () => Message.EnteredNavigationShortcut({ shortcut: 'GH' }),
|
|
170
169
|
},
|
|
171
170
|
{
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
Message.EnteredNavigationShortcut({ shortcut: 'GP' }),
|
|
171
|
+
keys: ['G', 'P'],
|
|
172
|
+
mapEvent: () => Message.EnteredNavigationShortcut({ shortcut: 'GP' }),
|
|
175
173
|
},
|
|
176
174
|
{
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
Message.EnteredNavigationShortcut({ shortcut: 'GF' }),
|
|
175
|
+
keys: ['G', 'F'],
|
|
176
|
+
mapEvent: () => Message.EnteredNavigationShortcut({ shortcut: 'GF' }),
|
|
180
177
|
},
|
|
181
178
|
{
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
Message.EnteredNavigationShortcut({ shortcut: 'GN' }),
|
|
179
|
+
keys: ['G', 'N'],
|
|
180
|
+
mapEvent: () => Message.EnteredNavigationShortcut({ shortcut: 'GN' }),
|
|
185
181
|
},
|
|
186
182
|
],
|
|
187
183
|
}),
|
|
@@ -4,7 +4,7 @@ import { Html, HtmlBuilder } from 'foldkit/html'
|
|
|
4
4
|
import { defineMessageUnion } from 'foldkit/message'
|
|
5
5
|
import { pushUrl } from 'foldkit/navigation'
|
|
6
6
|
import { defineTaggedUnion } from 'foldkit/schema'
|
|
7
|
-
import {
|
|
7
|
+
import { modifyFields } from 'foldkit/struct'
|
|
8
8
|
|
|
9
9
|
import { Button, Input } from '@foldkit/ui'
|
|
10
10
|
|
|
@@ -149,7 +149,7 @@ export type UpdateReturn = Update.Return<Model, Message>
|
|
|
149
149
|
export const update = (model: Model, message: Message) =>
|
|
150
150
|
Message.match<UpdateReturn>(message, {
|
|
151
151
|
ChangedSearchInput: ({ value }) => ({
|
|
152
|
-
model:
|
|
152
|
+
model: modifyFields(model, { searchInput: () => value }),
|
|
153
153
|
}),
|
|
154
154
|
|
|
155
155
|
SubmittedSearch: () => ({
|
|
@@ -164,7 +164,7 @@ export const update = (model: Model, message: Message) =>
|
|
|
164
164
|
ChangedRoute: ({ route }) => {
|
|
165
165
|
const searchText = routeSearchText(route)
|
|
166
166
|
return {
|
|
167
|
-
model:
|
|
167
|
+
model: modifyFields(model, {
|
|
168
168
|
searchInput: () => searchText,
|
|
169
169
|
searchHistory: searchHistory =>
|
|
170
170
|
addSearchToHistory(searchHistory, searchText),
|
|
@@ -175,7 +175,7 @@ export const update = (model: Model, message: Message) =>
|
|
|
175
175
|
},
|
|
176
176
|
|
|
177
177
|
SucceededFetchPeople: ({ query, people: fetchedPeople }) => ({
|
|
178
|
-
model:
|
|
178
|
+
model: modifyFields(model, {
|
|
179
179
|
results: () => SearchResults.Loaded({ query, people: fetchedPeople }),
|
|
180
180
|
}),
|
|
181
181
|
}),
|
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
"test": "vitest run"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@effect/platform-browser": "4.0.0-rc.
|
|
12
|
+
"@effect/platform-browser": "4.0.0-rc.116",
|
|
13
13
|
"@foldkit/ui": "workspace:*",
|
|
14
|
-
"effect": "4.0.0-rc.
|
|
14
|
+
"effect": "4.0.0-rc.116",
|
|
15
15
|
"foldkit": "workspace:*"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Array, Number, Option, Predicate, Schema, pipe } from 'effect'
|
|
2
|
-
import {
|
|
2
|
+
import { modifyFields } from 'foldkit/struct'
|
|
3
3
|
|
|
4
4
|
import { CartItem, Item } from './item'
|
|
5
5
|
|
|
@@ -26,7 +26,7 @@ export const addItem =
|
|
|
26
26
|
onSome: () =>
|
|
27
27
|
mapCartItem(
|
|
28
28
|
item.id,
|
|
29
|
-
|
|
29
|
+
modifyFields({
|
|
30
30
|
quantity: Number.increment,
|
|
31
31
|
}),
|
|
32
32
|
)(cart),
|
|
@@ -43,7 +43,7 @@ export const changeQuantity = (itemId: string, quantity: number) =>
|
|
|
43
43
|
? removeItem(itemId)
|
|
44
44
|
: mapCartItem(
|
|
45
45
|
itemId,
|
|
46
|
-
|
|
46
|
+
modifyFields({
|
|
47
47
|
quantity: () => quantity,
|
|
48
48
|
}),
|
|
49
49
|
)
|
|
@@ -51,7 +51,7 @@ export const changeQuantity = (itemId: string, quantity: number) =>
|
|
|
51
51
|
export const incrementQuantity = (itemId: string) =>
|
|
52
52
|
mapCartItem(
|
|
53
53
|
itemId,
|
|
54
|
-
|
|
54
|
+
modifyFields({
|
|
55
55
|
quantity: Number.increment,
|
|
56
56
|
}),
|
|
57
57
|
)
|
|
@@ -3,7 +3,7 @@ import { Command, Runtime, 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'
|
|
6
|
-
import {
|
|
6
|
+
import { modifyFields } from 'foldkit/struct'
|
|
7
7
|
import { Url, toString as urlToString } from 'foldkit/url'
|
|
8
8
|
|
|
9
9
|
import { products } from './data/products'
|
|
@@ -87,16 +87,16 @@ const foldProductsOutMessage = Products.OutMessage.match<
|
|
|
87
87
|
>({
|
|
88
88
|
AddedToCart:
|
|
89
89
|
({ item }) =>
|
|
90
|
-
model => ({ model:
|
|
90
|
+
model => ({ model: modifyFields(model, { cart: Cart.addItem(item) }) }),
|
|
91
91
|
IncrementedQuantity:
|
|
92
92
|
({ itemId }) =>
|
|
93
93
|
model => ({
|
|
94
|
-
model:
|
|
94
|
+
model: modifyFields(model, { cart: Cart.incrementQuantity(itemId) }),
|
|
95
95
|
}),
|
|
96
96
|
DecrementedQuantity:
|
|
97
97
|
({ itemId }) =>
|
|
98
98
|
model => ({
|
|
99
|
-
model:
|
|
99
|
+
model: modifyFields(model, { cart: Cart.decrementQuantity(itemId) }),
|
|
100
100
|
}),
|
|
101
101
|
})
|
|
102
102
|
|
|
@@ -104,7 +104,7 @@ const foldProducts = Update.foldChild({
|
|
|
104
104
|
update: Products.update,
|
|
105
105
|
read: (model: Model) => Option.some(model.productsPage),
|
|
106
106
|
write: (model, nextProductsPage) =>
|
|
107
|
-
|
|
107
|
+
modifyFields(model, { productsPage: () => nextProductsPage }),
|
|
108
108
|
toParentMessage: message => Message.GotProductsMessage({ message }),
|
|
109
109
|
foldOutMessage: foldProductsOutMessage,
|
|
110
110
|
})
|
|
@@ -128,7 +128,7 @@ export const update = (model: Model, message: Message) =>
|
|
|
128
128
|
}),
|
|
129
129
|
|
|
130
130
|
ChangedUrl: ({ url }) => ({
|
|
131
|
-
model:
|
|
131
|
+
model: modifyFields(model, {
|
|
132
132
|
route: () => urlToAppRoute(url),
|
|
133
133
|
}),
|
|
134
134
|
}),
|
|
@@ -136,37 +136,37 @@ export const update = (model: Model, message: Message) =>
|
|
|
136
136
|
GotProductsMessage: ({ message }) => foldProducts(model, message),
|
|
137
137
|
|
|
138
138
|
ClickedIncrementQuantity: ({ itemId }) => ({
|
|
139
|
-
model:
|
|
139
|
+
model: modifyFields(model, {
|
|
140
140
|
cart: Cart.incrementQuantity(itemId),
|
|
141
141
|
}),
|
|
142
142
|
}),
|
|
143
143
|
|
|
144
144
|
ClickedDecrementQuantity: ({ itemId }) => ({
|
|
145
|
-
model:
|
|
145
|
+
model: modifyFields(model, {
|
|
146
146
|
cart: Cart.decrementQuantity(itemId),
|
|
147
147
|
}),
|
|
148
148
|
}),
|
|
149
149
|
|
|
150
150
|
ClickedRemoveCartItem: ({ itemId }) => ({
|
|
151
|
-
model:
|
|
151
|
+
model: modifyFields(model, {
|
|
152
152
|
cart: Cart.removeItem(itemId),
|
|
153
153
|
}),
|
|
154
154
|
}),
|
|
155
155
|
|
|
156
156
|
ClickedClearCart: () => ({
|
|
157
|
-
model:
|
|
157
|
+
model: modifyFields(model, {
|
|
158
158
|
cart: () => [],
|
|
159
159
|
}),
|
|
160
160
|
}),
|
|
161
161
|
|
|
162
162
|
UpdatedDeliveryInstructions: ({ value }) => ({
|
|
163
|
-
model:
|
|
163
|
+
model: modifyFields(model, {
|
|
164
164
|
deliveryInstructions: () => value,
|
|
165
165
|
}),
|
|
166
166
|
}),
|
|
167
167
|
|
|
168
168
|
ClickedPlaceOrder: () => ({
|
|
169
|
-
model:
|
|
169
|
+
model: modifyFields(model, {
|
|
170
170
|
orderPlaced: () => true,
|
|
171
171
|
cart: () => [],
|
|
172
172
|
deliveryInstructions: () => '',
|
|
@@ -2,7 +2,7 @@ import { Array, Effect, Option, Schema } from 'effect'
|
|
|
2
2
|
import { Command, Submodel, type Update } from 'foldkit'
|
|
3
3
|
import { defineMessageUnion } from 'foldkit/message'
|
|
4
4
|
import { replaceUrl } from 'foldkit/navigation'
|
|
5
|
-
import {
|
|
5
|
+
import { modifyFields } from 'foldkit/struct'
|
|
6
6
|
|
|
7
7
|
import { Button, Input } from '@foldkit/ui'
|
|
8
8
|
|
|
@@ -68,7 +68,7 @@ export const update = (model: Model, message: Message) =>
|
|
|
68
68
|
CompletedReplaceSearchUrl: () => ({ model }),
|
|
69
69
|
|
|
70
70
|
ChangedSearchInput: ({ value }) => ({
|
|
71
|
-
model:
|
|
71
|
+
model: modifyFields(model, { searchText: () => value }),
|
|
72
72
|
commands: [
|
|
73
73
|
ReplaceSearchUrl({
|
|
74
74
|
url: productsRouter({
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Option } from 'effect'
|
|
2
2
|
import { click, expect, given, role, scene, text } from 'foldkit/scene'
|
|
3
|
-
import {
|
|
3
|
+
import { modifyFields } from 'foldkit/struct'
|
|
4
4
|
import { describe, test } from 'vitest'
|
|
5
5
|
|
|
6
6
|
import { products } from './data/products'
|
|
@@ -34,7 +34,7 @@ describe('view', () => {
|
|
|
34
34
|
scene(
|
|
35
35
|
{ update, view },
|
|
36
36
|
given(
|
|
37
|
-
|
|
37
|
+
modifyFields(baseModel, {
|
|
38
38
|
cart: () => [
|
|
39
39
|
{ item: apple, quantity: 2 },
|
|
40
40
|
{ item: banana, quantity: 3 },
|
|
@@ -56,7 +56,7 @@ describe('view', () => {
|
|
|
56
56
|
test('the Cart route shows the empty state when no items have been added', () => {
|
|
57
57
|
scene(
|
|
58
58
|
{ update, view },
|
|
59
|
-
given(
|
|
59
|
+
given(modifyFields(baseModel, { route: () => AppRoute.Cart() })),
|
|
60
60
|
expect(role('heading', { name: 'Shopping Cart' })).toExist(),
|
|
61
61
|
expect(text('Your cart is empty')).toExist(),
|
|
62
62
|
)
|
|
@@ -66,7 +66,7 @@ describe('view', () => {
|
|
|
66
66
|
scene(
|
|
67
67
|
{ update, view },
|
|
68
68
|
given(
|
|
69
|
-
|
|
69
|
+
modifyFields(baseModel, {
|
|
70
70
|
cart: () => [{ item: apple, quantity: 2 }],
|
|
71
71
|
route: () => AppRoute.Cart(),
|
|
72
72
|
}),
|
|
@@ -82,7 +82,7 @@ describe('view', () => {
|
|
|
82
82
|
test('the Checkout route shows the empty state when the cart is empty', () => {
|
|
83
83
|
scene(
|
|
84
84
|
{ update, view },
|
|
85
|
-
given(
|
|
85
|
+
given(modifyFields(baseModel, { route: () => AppRoute.Checkout() })),
|
|
86
86
|
expect(role('heading', { name: 'Checkout' })).toExist(),
|
|
87
87
|
expect(text('Your cart is empty')).toExist(),
|
|
88
88
|
)
|
|
@@ -92,7 +92,7 @@ describe('view', () => {
|
|
|
92
92
|
scene(
|
|
93
93
|
{ update, view },
|
|
94
94
|
given(
|
|
95
|
-
|
|
95
|
+
modifyFields(baseModel, {
|
|
96
96
|
cart: () => [{ item: apple, quantity: 2 }],
|
|
97
97
|
route: () => AppRoute.Checkout(),
|
|
98
98
|
}),
|
|
@@ -108,7 +108,7 @@ describe('view', () => {
|
|
|
108
108
|
scene(
|
|
109
109
|
{ update, view },
|
|
110
110
|
given(
|
|
111
|
-
|
|
111
|
+
modifyFields(baseModel, {
|
|
112
112
|
cart: () => [{ item: apple, quantity: 1 }],
|
|
113
113
|
route: () => AppRoute.Checkout(),
|
|
114
114
|
}),
|
|
@@ -122,7 +122,9 @@ describe('view', () => {
|
|
|
122
122
|
scene(
|
|
123
123
|
{ update, view },
|
|
124
124
|
given(
|
|
125
|
-
|
|
125
|
+
modifyFields(baseModel, {
|
|
126
|
+
route: () => AppRoute.NotFound({ path: '/oops' }),
|
|
127
|
+
}),
|
|
126
128
|
),
|
|
127
129
|
expect(role('heading', { name: '404 - Page Not Found' })).toExist(),
|
|
128
130
|
expect(text('The path "/oops" was not found.')).toExist(),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Option } from 'effect'
|
|
2
2
|
import { given, message, model, story } from 'foldkit/story'
|
|
3
|
-
import {
|
|
3
|
+
import { modifyFields } from 'foldkit/struct'
|
|
4
4
|
import { fromString } from 'foldkit/url'
|
|
5
5
|
import { describe, expect, test } from 'vitest'
|
|
6
6
|
|
|
@@ -126,7 +126,7 @@ describe('update', () => {
|
|
|
126
126
|
story(
|
|
127
127
|
update,
|
|
128
128
|
given(
|
|
129
|
-
|
|
129
|
+
modifyFields(baseModel, {
|
|
130
130
|
cart: () => [{ item: apple, quantity: 1 }],
|
|
131
131
|
}),
|
|
132
132
|
),
|
|
@@ -141,7 +141,7 @@ describe('update', () => {
|
|
|
141
141
|
story(
|
|
142
142
|
update,
|
|
143
143
|
given(
|
|
144
|
-
|
|
144
|
+
modifyFields(baseModel, {
|
|
145
145
|
cart: () => [{ item: apple, quantity: 2 }],
|
|
146
146
|
}),
|
|
147
147
|
),
|
|
@@ -156,7 +156,7 @@ describe('update', () => {
|
|
|
156
156
|
story(
|
|
157
157
|
update,
|
|
158
158
|
given(
|
|
159
|
-
|
|
159
|
+
modifyFields(baseModel, {
|
|
160
160
|
cart: () => [{ item: apple, quantity: 1 }],
|
|
161
161
|
}),
|
|
162
162
|
),
|
|
@@ -171,7 +171,7 @@ describe('update', () => {
|
|
|
171
171
|
story(
|
|
172
172
|
update,
|
|
173
173
|
given(
|
|
174
|
-
|
|
174
|
+
modifyFields(baseModel, {
|
|
175
175
|
cart: () => [
|
|
176
176
|
{ item: apple, quantity: 2 },
|
|
177
177
|
{ item: banana, quantity: 1 },
|
|
@@ -190,7 +190,7 @@ describe('update', () => {
|
|
|
190
190
|
story(
|
|
191
191
|
update,
|
|
192
192
|
given(
|
|
193
|
-
|
|
193
|
+
modifyFields(baseModel, {
|
|
194
194
|
cart: () => [{ item: apple, quantity: 2 }],
|
|
195
195
|
}),
|
|
196
196
|
),
|
|
@@ -222,7 +222,7 @@ describe('update', () => {
|
|
|
222
222
|
story(
|
|
223
223
|
update,
|
|
224
224
|
given(
|
|
225
|
-
|
|
225
|
+
modifyFields(baseModel, {
|
|
226
226
|
cart: () => [{ item: apple, quantity: 2 }],
|
|
227
227
|
deliveryInstructions: () => 'Knock loudly',
|
|
228
228
|
}),
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
"test": "vitest run"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@effect/platform-browser": "4.0.0-rc.
|
|
13
|
-
"effect": "4.0.0-rc.
|
|
12
|
+
"@effect/platform-browser": "4.0.0-rc.116",
|
|
13
|
+
"effect": "4.0.0-rc.116",
|
|
14
14
|
"foldkit": "workspace:*"
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { modifyFields } from 'foldkit/struct'
|
|
2
2
|
import { describe, expect, test, vi } from 'vitest'
|
|
3
3
|
|
|
4
4
|
import { Message, type Model, handleSlow } from './main'
|
|
@@ -21,7 +21,7 @@ describe('handleSlow', () => {
|
|
|
21
21
|
durationMs: 12,
|
|
22
22
|
thresholdMs: 4,
|
|
23
23
|
previousModel: initialModel,
|
|
24
|
-
nextModel:
|
|
24
|
+
nextModel: modifyFields(initialModel, {
|
|
25
25
|
activeWorkload: () => 'Update',
|
|
26
26
|
}),
|
|
27
27
|
message: Message.ClickedRunUpdateWork(),
|