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
|
@@ -2,7 +2,7 @@ import { Array, Match, Number, Option, Schema, Stream, pipe } from 'effect'
|
|
|
2
2
|
import { Runtime, Subscription, type Update } from 'foldkit'
|
|
3
3
|
import { type Document, type Html, HtmlBuilder, createLazy } from 'foldkit/html'
|
|
4
4
|
import { defineMessageUnion } from 'foldkit/message'
|
|
5
|
-
import {
|
|
5
|
+
import { modifyFields } from 'foldkit/struct'
|
|
6
6
|
|
|
7
7
|
const UPDATE_WORK_MS = 10
|
|
8
8
|
const VIEW_WORK_MS = 24
|
|
@@ -160,30 +160,30 @@ export const update = (model: Model, message: Message) =>
|
|
|
160
160
|
burnCpu(UPDATE_WORK_MS)
|
|
161
161
|
|
|
162
162
|
return {
|
|
163
|
-
model:
|
|
163
|
+
model: modifyFields(model, {
|
|
164
164
|
activeWorkload: () => 'Update',
|
|
165
165
|
}),
|
|
166
166
|
}
|
|
167
167
|
},
|
|
168
168
|
ClickedRunViewWork: () => ({
|
|
169
|
-
model:
|
|
169
|
+
model: modifyFields(model, {
|
|
170
170
|
activeWorkload: () => 'View',
|
|
171
171
|
}),
|
|
172
172
|
}),
|
|
173
173
|
ClickedRunPatchWork: () => ({
|
|
174
|
-
model:
|
|
174
|
+
model: modifyFields(model, {
|
|
175
175
|
activeWorkload: () => 'Patch',
|
|
176
176
|
patchRows: () => PATCH_ROW_COUNT,
|
|
177
177
|
patchRun: Number.increment,
|
|
178
178
|
}),
|
|
179
179
|
}),
|
|
180
180
|
ClickedRunSubscriptionDependenciesWork: () => ({
|
|
181
|
-
model:
|
|
181
|
+
model: modifyFields(model, {
|
|
182
182
|
activeWorkload: () => 'SubscriptionDependencies',
|
|
183
183
|
}),
|
|
184
184
|
}),
|
|
185
185
|
ClickedClearWarnings: () => ({
|
|
186
|
-
model:
|
|
186
|
+
model: modifyFields(model, {
|
|
187
187
|
activeWorkload: () => 'Idle',
|
|
188
188
|
warnings: () => [],
|
|
189
189
|
}),
|
|
@@ -195,7 +195,7 @@ export const update = (model: Model, message: Message) =>
|
|
|
195
195
|
}
|
|
196
196
|
|
|
197
197
|
return {
|
|
198
|
-
model:
|
|
198
|
+
model: modifyFields(model, {
|
|
199
199
|
activeWorkload: () => 'Idle',
|
|
200
200
|
nextWarningId: Number.increment,
|
|
201
201
|
warnings: prependWarning(warning),
|
|
@@ -223,7 +223,7 @@ export const subscriptions = Subscription.make<Model, Message>()(entry => ({
|
|
|
223
223
|
Subscription.fromEventFilterMap({
|
|
224
224
|
target: slowWarningTarget,
|
|
225
225
|
type: SLOW_WARNING_EVENT,
|
|
226
|
-
|
|
226
|
+
filterMapEvent: event =>
|
|
227
227
|
pipe(
|
|
228
228
|
event.detail,
|
|
229
229
|
Schema.decodeUnknownOption(SlowWarningReport),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { click, expect, given, role, scene, text } from 'foldkit/scene'
|
|
2
|
-
import {
|
|
2
|
+
import { modifyFields } from 'foldkit/struct'
|
|
3
3
|
import { describe, test } from 'vitest'
|
|
4
4
|
|
|
5
5
|
import { type Model, update, view } from './main'
|
|
@@ -38,7 +38,7 @@ describe('view', () => {
|
|
|
38
38
|
scene(
|
|
39
39
|
{ update, view },
|
|
40
40
|
given(
|
|
41
|
-
|
|
41
|
+
modifyFields(initialModel, {
|
|
42
42
|
warnings: () => [
|
|
43
43
|
{
|
|
44
44
|
id: 1,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Command, given, message, model, story } from 'foldkit/story'
|
|
2
|
-
import {
|
|
2
|
+
import { modifyFields } from 'foldkit/struct'
|
|
3
3
|
import { describe, expect, test } from 'vitest'
|
|
4
4
|
|
|
5
5
|
import { Message, type Model, update } from './main'
|
|
@@ -96,7 +96,7 @@ describe('update', () => {
|
|
|
96
96
|
story(
|
|
97
97
|
update,
|
|
98
98
|
given(
|
|
99
|
-
|
|
99
|
+
modifyFields(initialModel, {
|
|
100
100
|
patchRows: () => 4000,
|
|
101
101
|
warnings: () => [
|
|
102
102
|
{
|
|
@@ -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": {
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
import { Command, Runtime, Subscription, type Update } from 'foldkit'
|
|
12
12
|
import { Document, Html, HtmlBuilder } from 'foldkit/html'
|
|
13
13
|
import { defineMessageUnion } from 'foldkit/message'
|
|
14
|
-
import {
|
|
14
|
+
import { modifyFields } from 'foldkit/struct'
|
|
15
15
|
|
|
16
16
|
import { GAME, GAME_SPEED } from './constants'
|
|
17
17
|
import { Apple, Direction, Position, Snake } from './domain'
|
|
@@ -98,7 +98,7 @@ export const update = (model: Model, message: Message) =>
|
|
|
98
98
|
|
|
99
99
|
if (model.gameState === 'Playing') {
|
|
100
100
|
return {
|
|
101
|
-
model:
|
|
101
|
+
model: modifyFields(model, {
|
|
102
102
|
nextDirection: () => nextDirection,
|
|
103
103
|
}),
|
|
104
104
|
}
|
|
@@ -117,7 +117,7 @@ export const update = (model: Model, message: Message) =>
|
|
|
117
117
|
Match.exhaustive,
|
|
118
118
|
)
|
|
119
119
|
return {
|
|
120
|
-
model:
|
|
120
|
+
model: modifyFields(model, {
|
|
121
121
|
gameState: () => nextGameState,
|
|
122
122
|
}),
|
|
123
123
|
}
|
|
@@ -126,7 +126,7 @@ export const update = (model: Model, message: Message) =>
|
|
|
126
126
|
const nextSnake = Snake.create(GAME.INITIAL_POSITION)
|
|
127
127
|
|
|
128
128
|
return {
|
|
129
|
-
model:
|
|
129
|
+
model: modifyFields(model, {
|
|
130
130
|
snake: () => nextSnake,
|
|
131
131
|
direction: () => GAME.INITIAL_DIRECTION,
|
|
132
132
|
nextDirection: () => GAME.INITIAL_DIRECTION,
|
|
@@ -160,7 +160,7 @@ export const update = (model: Model, message: Message) =>
|
|
|
160
160
|
|
|
161
161
|
if (Snake.hasCollision(nextSnake)) {
|
|
162
162
|
return {
|
|
163
|
-
model:
|
|
163
|
+
model: modifyFields(model, {
|
|
164
164
|
gameState: () => 'GameOver',
|
|
165
165
|
highScore: highScore => Math.max(model.points, highScore),
|
|
166
166
|
}),
|
|
@@ -172,7 +172,7 @@ export const update = (model: Model, message: Message) =>
|
|
|
172
172
|
: []
|
|
173
173
|
|
|
174
174
|
return {
|
|
175
|
-
model:
|
|
175
|
+
model: modifyFields(model, {
|
|
176
176
|
snake: () => nextSnake,
|
|
177
177
|
direction: () => currentDirection,
|
|
178
178
|
points: points =>
|
|
@@ -183,7 +183,7 @@ export const update = (model: Model, message: Message) =>
|
|
|
183
183
|
},
|
|
184
184
|
|
|
185
185
|
PausedGame: () => ({
|
|
186
|
-
model:
|
|
186
|
+
model: modifyFields(model, {
|
|
187
187
|
gameState: gameState =>
|
|
188
188
|
gameState === 'Playing' ? 'Paused' : 'Playing',
|
|
189
189
|
}),
|
|
@@ -194,7 +194,7 @@ export const update = (model: Model, message: Message) =>
|
|
|
194
194
|
const nextSnake = Snake.create(startPosition)
|
|
195
195
|
|
|
196
196
|
return {
|
|
197
|
-
model:
|
|
197
|
+
model: modifyFields(model, {
|
|
198
198
|
snake: () => nextSnake,
|
|
199
199
|
direction: () => 'Right',
|
|
200
200
|
nextDirection: () => 'Right',
|
|
@@ -206,7 +206,7 @@ export const update = (model: Model, message: Message) =>
|
|
|
206
206
|
},
|
|
207
207
|
|
|
208
208
|
CompletedGenerateApplePosition: ({ position }) => ({
|
|
209
|
-
model:
|
|
209
|
+
model: modifyFields(model, {
|
|
210
210
|
apple: () => position,
|
|
211
211
|
}),
|
|
212
212
|
}),
|
|
@@ -255,7 +255,7 @@ export const subscriptions = Subscription.make<Model, Message>()(entry => ({
|
|
|
255
255
|
Subscription.fromEventFilterMapPreventDefault({
|
|
256
256
|
target: document,
|
|
257
257
|
type: 'keydown',
|
|
258
|
-
|
|
258
|
+
filterMapEvent: keyboardEvent =>
|
|
259
259
|
Option.some(Message.PressedKey({ key: keyboardEvent.key })),
|
|
260
260
|
}),
|
|
261
261
|
),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { expect, given, role, scene, text } from 'foldkit/scene'
|
|
2
|
-
import {
|
|
2
|
+
import { modifyFields } from 'foldkit/struct'
|
|
3
3
|
import { describe, test } from 'vitest'
|
|
4
4
|
|
|
5
5
|
import { Snake } from './domain'
|
|
@@ -40,7 +40,7 @@ describe('view', () => {
|
|
|
40
40
|
test('shows the playing prompt while the game is active', () => {
|
|
41
41
|
scene(
|
|
42
42
|
{ update, view },
|
|
43
|
-
given(
|
|
43
|
+
given(modifyFields(baseModel, { gameState: () => 'Playing' })),
|
|
44
44
|
expect(text('Playing - SPACE to pause')).toExist(),
|
|
45
45
|
)
|
|
46
46
|
})
|
|
@@ -48,7 +48,7 @@ describe('view', () => {
|
|
|
48
48
|
test('shows the paused prompt while the game is paused', () => {
|
|
49
49
|
scene(
|
|
50
50
|
{ update, view },
|
|
51
|
-
given(
|
|
51
|
+
given(modifyFields(baseModel, { gameState: () => 'Paused' })),
|
|
52
52
|
expect(text('Paused - SPACE to continue')).toExist(),
|
|
53
53
|
)
|
|
54
54
|
})
|
|
@@ -56,7 +56,12 @@ describe('view', () => {
|
|
|
56
56
|
test('shows the game-over prompt at the end of a run', () => {
|
|
57
57
|
scene(
|
|
58
58
|
{ update, view },
|
|
59
|
-
given(
|
|
59
|
+
given(
|
|
60
|
+
modifyFields(baseModel, {
|
|
61
|
+
gameState: () => 'GameOver',
|
|
62
|
+
points: () => 50,
|
|
63
|
+
}),
|
|
64
|
+
),
|
|
60
65
|
expect(text('Game Over - Press R to restart')).toExist(),
|
|
61
66
|
expect(text('Score: 50')).toExist(),
|
|
62
67
|
)
|
|
@@ -66,7 +71,7 @@ describe('view', () => {
|
|
|
66
71
|
scene(
|
|
67
72
|
{ update, view },
|
|
68
73
|
given(
|
|
69
|
-
|
|
74
|
+
modifyFields(baseModel, {
|
|
70
75
|
gameState: () => 'Playing',
|
|
71
76
|
points: () => 120,
|
|
72
77
|
highScore: () => 200,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Command, given, message, model, story } from 'foldkit/story'
|
|
2
|
-
import {
|
|
2
|
+
import { modifyFields } from 'foldkit/struct'
|
|
3
3
|
import { describe, expect, test } from 'vitest'
|
|
4
4
|
|
|
5
5
|
import { Snake } from './domain'
|
|
@@ -17,7 +17,7 @@ const playingModel: Model = {
|
|
|
17
17
|
highScore: 0,
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
const notStartedModel: Model =
|
|
20
|
+
const notStartedModel: Model = modifyFields(playingModel, {
|
|
21
21
|
gameState: () => 'NotStarted',
|
|
22
22
|
})
|
|
23
23
|
|
|
@@ -48,7 +48,7 @@ describe('update', () => {
|
|
|
48
48
|
test('arrow keys are ignored while the game is paused', () => {
|
|
49
49
|
story(
|
|
50
50
|
update,
|
|
51
|
-
given(
|
|
51
|
+
given(modifyFields(playingModel, { gameState: () => 'Paused' })),
|
|
52
52
|
message(Message.PressedKey({ key: 'ArrowDown' })),
|
|
53
53
|
model(model => {
|
|
54
54
|
expect(model.nextDirection).toBe('Right')
|
|
@@ -83,7 +83,7 @@ describe('update', () => {
|
|
|
83
83
|
test('SPACE on GameOver does nothing', () => {
|
|
84
84
|
story(
|
|
85
85
|
update,
|
|
86
|
-
given(
|
|
86
|
+
given(modifyFields(playingModel, { gameState: () => 'GameOver' })),
|
|
87
87
|
message(Message.PressedKey({ key: ' ' })),
|
|
88
88
|
model(model => {
|
|
89
89
|
expect(model.gameState).toBe('GameOver')
|
|
@@ -96,7 +96,7 @@ describe('update', () => {
|
|
|
96
96
|
test('R fires GenerateApplePosition and resets the snake', () => {
|
|
97
97
|
story(
|
|
98
98
|
update,
|
|
99
|
-
given(
|
|
99
|
+
given(modifyFields(playingModel, { points: () => 100 })),
|
|
100
100
|
message(Message.PressedKey({ key: 'r' })),
|
|
101
101
|
model(model => {
|
|
102
102
|
expect(model.gameState).toBe('NotStarted')
|
|
@@ -139,7 +139,7 @@ describe('update', () => {
|
|
|
139
139
|
})
|
|
140
140
|
|
|
141
141
|
test('eating an apple grows the snake, adds points, and requests a new apple', () => {
|
|
142
|
-
const aboutToEatModel: Model =
|
|
142
|
+
const aboutToEatModel: Model = modifyFields(playingModel, {
|
|
143
143
|
apple: () => ({ x: 11, y: 10 }),
|
|
144
144
|
})
|
|
145
145
|
const lengthBefore = aboutToEatModel.snake.length
|
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
"typecheck": "tsc --noEmit"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@effect/platform-browser": "4.0.0-rc.
|
|
14
|
-
"effect": "4.0.0-rc.
|
|
13
|
+
"@effect/platform-browser": "4.0.0-rc.116",
|
|
14
|
+
"effect": "4.0.0-rc.116",
|
|
15
15
|
"foldkit": "workspace:*"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
@@ -3,7 +3,7 @@ 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'
|
|
6
|
-
import {
|
|
6
|
+
import { modifyFields } from 'foldkit/struct'
|
|
7
7
|
import { Url, toString as urlToString } from 'foldkit/url'
|
|
8
8
|
|
|
9
9
|
import { AppRoute, aboutRouter, homeRouter, urlToAppRoute } from './route'
|
|
@@ -57,7 +57,7 @@ type UpdateReturn = Update.Return<Model, Message>
|
|
|
57
57
|
export const update = (model: Model, message: Message) =>
|
|
58
58
|
Message.match<UpdateReturn>(message, {
|
|
59
59
|
ClickedIncrement: () => ({
|
|
60
|
-
model:
|
|
60
|
+
model: modifyFields(model, { count: count => count + 1 }),
|
|
61
61
|
}),
|
|
62
62
|
ClickedLink: ({ request }) =>
|
|
63
63
|
UrlRequest.match<UpdateReturn>(request, {
|
|
@@ -71,7 +71,7 @@ export const update = (model: Model, message: Message) =>
|
|
|
71
71
|
}),
|
|
72
72
|
}),
|
|
73
73
|
ChangedUrl: ({ url }) => ({
|
|
74
|
-
model:
|
|
74
|
+
model: modifyFields(model, { route: () => urlToAppRoute(url) }),
|
|
75
75
|
}),
|
|
76
76
|
CompletedNavigateInternal: () => ({ model }),
|
|
77
77
|
CompletedLoadExternal: () => ({ model }),
|
|
@@ -11,11 +11,11 @@
|
|
|
11
11
|
"test": "vitest run"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@effect/platform-browser": "4.0.0-rc.
|
|
15
|
-
"@effect/platform-node": "4.0.0-rc.
|
|
16
|
-
"@effect/platform-node-shared": "4.0.0-rc.
|
|
14
|
+
"@effect/platform-browser": "4.0.0-rc.116",
|
|
15
|
+
"@effect/platform-node": "4.0.0-rc.116",
|
|
16
|
+
"@effect/platform-node-shared": "4.0.0-rc.116",
|
|
17
17
|
"@foldkit/ui": "workspace:*",
|
|
18
|
-
"effect": "4.0.0-rc.
|
|
18
|
+
"effect": "4.0.0-rc.116",
|
|
19
19
|
"foldkit": "workspace:*"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
@@ -2,7 +2,7 @@ import { Effect, Schema } from 'effect'
|
|
|
2
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
|
-
import {
|
|
5
|
+
import { modifyFields } from 'foldkit/struct'
|
|
6
6
|
|
|
7
7
|
import { Button } from '@foldkit/ui'
|
|
8
8
|
|
|
@@ -43,14 +43,14 @@ export const update = (model: Model, message: Message) =>
|
|
|
43
43
|
ClickedDecrement: () => {
|
|
44
44
|
const nextCount = model.count - 1
|
|
45
45
|
return {
|
|
46
|
-
model:
|
|
46
|
+
model: modifyFields(model, { count: () => nextCount }),
|
|
47
47
|
commands: [PersistCount({ count: nextCount })],
|
|
48
48
|
}
|
|
49
49
|
},
|
|
50
50
|
ClickedIncrement: () => {
|
|
51
51
|
const nextCount = model.count + 1
|
|
52
52
|
return {
|
|
53
|
-
model:
|
|
53
|
+
model: modifyFields(model, { count: () => nextCount }),
|
|
54
54
|
commands: [PersistCount({ count: nextCount })],
|
|
55
55
|
}
|
|
56
56
|
},
|
|
@@ -9,10 +9,10 @@
|
|
|
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
14
|
"clsx": "^2.1.1",
|
|
15
|
-
"effect": "4.0.0-rc.
|
|
15
|
+
"effect": "4.0.0-rc.116",
|
|
16
16
|
"foldkit": "workspace:*"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
@@ -15,7 +15,7 @@ import { Machine } from 'foldkit/experimental'
|
|
|
15
15
|
import { otherwise, to, when } from 'foldkit/experimental/machine'
|
|
16
16
|
import { defineMessageUnion } from 'foldkit/message'
|
|
17
17
|
import { defineTaggedUnion } from 'foldkit/schema'
|
|
18
|
-
import {
|
|
18
|
+
import { modifyFields } from 'foldkit/struct'
|
|
19
19
|
|
|
20
20
|
import { RadioGroup } from '@foldkit/ui'
|
|
21
21
|
|
|
@@ -181,7 +181,7 @@ export const checkoutMachine = Machine.define({
|
|
|
181
181
|
Cart: {
|
|
182
182
|
on: {
|
|
183
183
|
SelectedEdition: to('Cart', ({ state, message }) => ({
|
|
184
|
-
model:
|
|
184
|
+
model: modifyFields(state, {
|
|
185
185
|
isShippingRequired: () => message.isShippingRequired,
|
|
186
186
|
}),
|
|
187
187
|
})),
|
|
@@ -224,7 +224,7 @@ export const checkoutMachine = Machine.define({
|
|
|
224
224
|
Payment: {
|
|
225
225
|
on: {
|
|
226
226
|
ToggledPaymentMethod: to('Payment', ({ state, message }) => ({
|
|
227
|
-
model:
|
|
227
|
+
model: modifyFields(state, {
|
|
228
228
|
isPaymentMethodSelected: () => message.isSelected,
|
|
229
229
|
}),
|
|
230
230
|
})),
|
|
@@ -260,15 +260,17 @@ export const checkoutMachine = Machine.define({
|
|
|
260
260
|
Review: {
|
|
261
261
|
on: {
|
|
262
262
|
ToggledPaymentMethod: to('Review', ({ state, message }) => ({
|
|
263
|
-
model:
|
|
263
|
+
model: modifyFields(state, {
|
|
264
264
|
isPaymentMethodSelected: () => message.isSelected,
|
|
265
265
|
}),
|
|
266
266
|
})),
|
|
267
267
|
ToggledTermsAccepted: to('Review', ({ state, message }) => ({
|
|
268
|
-
model:
|
|
268
|
+
model: modifyFields(state, {
|
|
269
|
+
isTermsAccepted: () => message.isAccepted,
|
|
270
|
+
}),
|
|
269
271
|
})),
|
|
270
272
|
UpdatedPromoCode: to('Review', ({ state, message }) => ({
|
|
271
|
-
model:
|
|
273
|
+
model: modifyFields(state, {
|
|
272
274
|
promoCodeInput: () => message.value,
|
|
273
275
|
promo: currentPromo =>
|
|
274
276
|
currentPromo._tag === 'RejectedPromo'
|
|
@@ -281,14 +283,16 @@ export const checkoutMachine = Machine.define({
|
|
|
281
283
|
reviewToMaybeDiscount,
|
|
282
284
|
'Review',
|
|
283
285
|
({ state, guardValue: discount }) => ({
|
|
284
|
-
model:
|
|
286
|
+
model: modifyFields(state, {
|
|
285
287
|
promo: () => Promo.AppliedPromo({ discount }),
|
|
286
288
|
}),
|
|
287
289
|
}),
|
|
288
290
|
),
|
|
289
291
|
otherwise(
|
|
290
292
|
to('Review', ({ state }) => ({
|
|
291
|
-
model:
|
|
293
|
+
model: modifyFields(state, {
|
|
294
|
+
promo: () => Promo.RejectedPromo(),
|
|
295
|
+
}),
|
|
292
296
|
})),
|
|
293
297
|
),
|
|
294
298
|
],
|
|
@@ -376,7 +380,7 @@ const stepMachine =
|
|
|
376
380
|
}
|
|
377
381
|
|
|
378
382
|
return {
|
|
379
|
-
model:
|
|
383
|
+
model: modifyFields(model, {
|
|
380
384
|
checkout: () => nextCheckout,
|
|
381
385
|
transitionLog: flow(
|
|
382
386
|
Array.prepend(transitionLogEntry),
|
|
@@ -403,7 +407,7 @@ const foldEditionRadioGroup = Update.foldChild({
|
|
|
403
407
|
update: EditionRadioGroup.update,
|
|
404
408
|
read: (model: Model) => Option.some(model.editionRadioGroup),
|
|
405
409
|
write: (model, nextEditionRadioGroup) =>
|
|
406
|
-
|
|
410
|
+
modifyFields(model, { editionRadioGroup: () => nextEditionRadioGroup }),
|
|
407
411
|
toParentMessage: message => Message.GotEditionRadioGroupMessage({ message }),
|
|
408
412
|
foldOutMessage: foldEditionRadioGroupOutMessage,
|
|
409
413
|
})
|
|
@@ -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": {
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
import { Command, Runtime, Subscription, type Update } from 'foldkit'
|
|
12
12
|
import { Document, Html, HtmlBuilder } from 'foldkit/html'
|
|
13
13
|
import { defineMessageUnion } from 'foldkit/message'
|
|
14
|
-
import {
|
|
14
|
+
import { modifyFields } from 'foldkit/struct'
|
|
15
15
|
|
|
16
16
|
import { Button } from '@foldkit/ui'
|
|
17
17
|
|
|
@@ -71,20 +71,20 @@ export const update = (model: Model, message: Message) =>
|
|
|
71
71
|
}),
|
|
72
72
|
|
|
73
73
|
CompletedDetermineStartTime: ({ startTime }) => ({
|
|
74
|
-
model:
|
|
74
|
+
model: modifyFields(model, {
|
|
75
75
|
isRunning: () => true,
|
|
76
76
|
startTime: () => startTime,
|
|
77
77
|
}),
|
|
78
78
|
}),
|
|
79
79
|
|
|
80
80
|
ClickedStop: () => ({
|
|
81
|
-
model:
|
|
81
|
+
model: modifyFields(model, {
|
|
82
82
|
isRunning: () => false,
|
|
83
83
|
}),
|
|
84
84
|
}),
|
|
85
85
|
|
|
86
86
|
ClickedReset: () => ({
|
|
87
|
-
model:
|
|
87
|
+
model: modifyFields(model, {
|
|
88
88
|
elapsedMs: () => 0,
|
|
89
89
|
isRunning: () => false,
|
|
90
90
|
startTime: () => 0,
|
|
@@ -97,7 +97,7 @@ export const update = (model: Model, message: Message) =>
|
|
|
97
97
|
}),
|
|
98
98
|
|
|
99
99
|
CompletedDetermineTickTime: ({ elapsedMs }) => ({
|
|
100
|
-
model:
|
|
100
|
+
model: modifyFields(model, {
|
|
101
101
|
elapsedMs: () => elapsedMs,
|
|
102
102
|
}),
|
|
103
103
|
}),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Command, given, message, model, story } from 'foldkit/story'
|
|
2
|
-
import {
|
|
2
|
+
import { modifyFields } from 'foldkit/struct'
|
|
3
3
|
import { describe, expect, test } from 'vitest'
|
|
4
4
|
|
|
5
5
|
import {
|
|
@@ -27,7 +27,7 @@ describe('update', () => {
|
|
|
27
27
|
test('ClickedStart fires DetermineStartTime with current elapsed time', () => {
|
|
28
28
|
story(
|
|
29
29
|
update,
|
|
30
|
-
given(
|
|
30
|
+
given(modifyFields(idleModel, { elapsedMs: () => 2000 })),
|
|
31
31
|
message(Message.ClickedStart()),
|
|
32
32
|
Command.expectHas(DetermineStartTime),
|
|
33
33
|
model(model => {
|
|
@@ -9,10 +9,10 @@
|
|
|
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
14
|
"clsx": "^2.1.1",
|
|
15
|
-
"effect": "4.0.0-rc.
|
|
15
|
+
"effect": "4.0.0-rc.116",
|
|
16
16
|
"foldkit": "workspace:*"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|