Skip to content

Commit f0d1fba

Browse files
chore: use dprint for formatting
1 parent ee4251e commit f0d1fba

30 files changed

Lines changed: 489 additions & 313 deletions

.prettierignore

Lines changed: 0 additions & 8 deletions
This file was deleted.

.prettierrc.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

.vscode/extensions.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"recommendations": ["dprint.dprint"]
3+
}

.vscode/settings.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"dprint.path": "node_modules/.bin/dprint",
3+
"editor.formatOnSave": true,
4+
"editor.defaultFormatter": "dprint.dprint",
5+
"editor.formatOnSaveMode": "file",
6+
"files.insertFinalNewline": true,
7+
"[typescript]": {
8+
"editor.defaultFormatter": "dprint.dprint"
9+
},
10+
"[typescriptreact]": {
11+
"editor.defaultFormatter": "dprint.dprint"
12+
},
13+
"[javascript]": {
14+
"editor.defaultFormatter": "dprint.dprint"
15+
},
16+
"[javascriptreact]": {
17+
"editor.defaultFormatter": "dprint.dprint"
18+
},
19+
"[json]": {
20+
"editor.defaultFormatter": "dprint.dprint"
21+
},
22+
"[jsonc]": {
23+
"editor.defaultFormatter": "dprint.dprint"
24+
},
25+
"[markdown]": {
26+
"editor.defaultFormatter": "dprint.dprint"
27+
}
28+
}

README.md

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ require upgrading Effect in lockstep; do not override the peer to another beta.
1919

2020
```ts
2121
import { Machine } from "@typeonce/effect-machine"
22-
import { AtomMachine } from "@typeonce/effect-machine/reactivity"
2322
import { ClusterMachine } from "@typeonce/effect-machine/cluster"
23+
import { AtomMachine } from "@typeonce/effect-machine/reactivity"
2424
```
2525

2626
Each ESM entrypoint is independent and tree-shakeable. Importing the root does
@@ -37,8 +37,8 @@ property contains the individual tagged schemas, and each case has a typed
3737
`make` constructor.
3838

3939
```ts
40-
import { Schema } from "effect"
4140
import { Machine } from "@typeonce/effect-machine"
41+
import { Schema } from "effect"
4242

4343
const State = Schema.TaggedUnion({
4444
Idle: {},
@@ -256,7 +256,9 @@ effects in `Machine.action`; actions are staged during planning and run by the
256256
managed runtime before it publishes the next state.
257257

258258
```ts
259-
Save: ({ target }) => Machine.action(writeAuditLog, target.local.Saving.from())
259+
const handlers = {
260+
Save: ({ target }) => Machine.action(writeAuditLog, target.local.Saving.from())
261+
}
260262
```
261263

262264
The one-argument form returns `void` after staging. The two-argument form
@@ -283,16 +285,18 @@ state interrupts the child. For a one-shot Effect, `Machine.invokeEffect` maps
283285
typed success and failure values directly to internal events:
284286

285287
```ts
286-
invoke: ({ state }) =>
287-
Machine.invokeEffect({
288-
id: "save",
289-
effect: save(state),
290-
onSuccess: (entry) => InternalEvent.cases.Saved.make({ id: entry.id }),
291-
onFailure: (error) =>
292-
InternalEvent.cases.SaveFailed.make({
293-
message: String(error)
294-
})
295-
})
288+
const loading = {
289+
invoke: ({ state }) =>
290+
Machine.invokeEffect({
291+
id: "save",
292+
effect: save(state),
293+
onSuccess: (entry) => InternalEvent.cases.Saved.make({ id: entry.id }),
294+
onFailure: (error) =>
295+
InternalEvent.cases.SaveFailed.make({
296+
message: String(error)
297+
})
298+
})
299+
}
296300
```
297301

298302
Omit `onFailure` when the Effect cannot fail. Defects and interruption remain
@@ -344,8 +348,8 @@ Exporting one descriptor remains the clearest module boundary.
344348
disposing the registry-owned reference stops it.
345349

346350
```ts
347-
import { Atom } from "effect/unstable/reactivity"
348351
import { AtomMachine } from "@typeonce/effect-machine/reactivity"
352+
import { Atom } from "effect/unstable/reactivity"
349353

350354
const runtime = Atom.runtime(AppLayer)
351355
const machines = AtomMachine.bind(runtime)

dprint.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"$schema": "https://dprint.dev/schemas/v0.json",
3+
"incremental": false,
4+
"includes": ["**/*.{ts,tsx,js,jsx,json,md}"],
5+
"indentWidth": 2,
6+
"lineWidth": 120,
7+
"newLineKind": "lf",
8+
"typescript": {
9+
"semiColons": "asi",
10+
"quoteStyle": "alwaysDouble",
11+
"trailingCommas": "never",
12+
"operatorPosition": "maintain",
13+
"arrowFunction.useParentheses": "force"
14+
},
15+
"excludes": [
16+
"LLMS.md",
17+
"**/dist",
18+
"**/build",
19+
"**/docs",
20+
"**/coverage",
21+
"packages/**/CHANGELOG.md",
22+
"!scratchpad/**/*",
23+
".agents",
24+
".context",
25+
".specs"
26+
],
27+
"plugins": [
28+
"https://plugins.dprint.dev/typescript-0.93.4.wasm",
29+
"https://plugins.dprint.dev/markdown-0.20.0.wasm",
30+
"https://plugins.dprint.dev/json-0.21.1.wasm"
31+
]
32+
}

examples/platformer/src/machine.ts

Lines changed: 30 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { Effect, Schema } from "effect"
21
import { Machine } from "@typeonce/effect-machine"
2+
import { Effect, Schema } from "effect"
33

44
// Domain schemas are shared by state payloads and the public physics protocol.
55
export const Axis = Schema.Literals([-1, 0, 1])
@@ -127,12 +127,11 @@ const initialCharacter = () =>
127127
character
128128
.locomotion(State.cases.Locomotion.make({}), (locomotion) =>
129129
locomotion.Grounded(State.cases.Grounded.make({}), (grounded) =>
130-
grounded.Standing(State.cases.Standing.make({}))
131-
)
132-
)
133-
.facing(State.cases.Facing.make({}), (facing) => facing.Right(State.cases.Right.make({})))
134-
.contact(State.cases.WallContact.make({}), (contact) => contact.NoWall(State.cases.NoWall.make({})))
135-
)
130+
grounded.Standing(State.cases.Standing.make({}))))
131+
.facing(State.cases.Facing.make({}), (facing) =>
132+
facing.Right(State.cases.Right.make({})))
133+
.contact(State.cases.WallContact.make({}), (contact) =>
134+
contact.NoWall(State.cases.NoWall.make({}))))
136135

137136
export const CharacterMachine = Machine.make({
138137
id: "PlatformerCharacter",
@@ -159,22 +158,17 @@ export const CharacterMachine = Machine.make({
159158
.motion(State.cases.Motion.make({}), (motion) =>
160159
motion.Jumping(
161160
State.cases.Jumping.make({ startedAt: event.at, push: 0, kind: "Ground" })
162-
)
163-
)
161+
))
164162
.airJump(State.cases.AirJump.make({}), (airJump) =>
165-
airJump.AirJumpGroundLock(State.cases.AirJumpGroundLock.make({}))
166-
)
167-
)
168-
)
169-
.facing(State.cases.Facing.make({}), (facing) => facing.Right(State.cases.Right.make({})))
163+
airJump.AirJumpGroundLock(State.cases.AirJumpGroundLock.make({})))))
164+
.facing(State.cases.Facing.make({}), (facing) =>
165+
facing.Right(State.cases.Right.make({})))
170166
.contact(State.cases.WallContact.make({}), (contact) =>
171167
event.wall === -1
172168
? contact.LeftWall(State.cases.LeftWall.make({}))
173169
: event.wall === 1
174-
? contact.RightWall(State.cases.RightWall.make({}))
175-
: contact.NoWall(State.cases.NoWall.make({}))
176-
)
177-
)
170+
? contact.RightWall(State.cases.RightWall.make({}))
171+
: contact.NoWall(State.cases.NoWall.make({}))))
178172
},
179173
states: {
180174
Standing: {
@@ -220,7 +214,7 @@ export const CharacterMachine = Machine.make({
220214
},
221215
Airborne: {
222216
on: {
223-
JumpPressed: Effect.fn(function* ({ event, runtime }) {
217+
JumpPressed: Effect.fn(function*({ event, runtime }) {
224218
const machine = yield* runtime
225219
const push = awayFrom(event.wall)
226220
yield* machine.raise(
@@ -230,14 +224,16 @@ export const CharacterMachine = Machine.make({
230224
)
231225
}),
232226
Landed: ({ event, target }) =>
233-
target.branch.Character.locomotion.Grounded(State.cases.Grounded.make({}), (grounded) =>
234-
grounded.Landing(
235-
State.cases.Landing.make({
236-
impact: event.impact,
237-
resumeAxis: event.axis,
238-
landedAt: event.at
239-
})
240-
)
227+
target.branch.Character.locomotion.Grounded(
228+
State.cases.Grounded.make({}),
229+
(grounded) =>
230+
grounded.Landing(
231+
State.cases.Landing.make({
232+
impact: event.impact,
233+
resumeAxis: event.axis,
234+
landedAt: event.at
235+
})
236+
)
241237
)
242238
},
243239
states: {
@@ -274,8 +270,7 @@ export const CharacterMachine = Machine.make({
274270
on: {
275271
WallJump: {
276272
reenter: true,
277-
transition: ({ target }) =>
278-
target.local.AirJumpWallLock(State.cases.AirJumpWallLock.make({}))
273+
transition: ({ target }) => target.local.AirJumpWallLock(State.cases.AirJumpWallLock.make({}))
279274
}
280275
},
281276
states: {
@@ -284,22 +279,20 @@ export const CharacterMachine = Machine.make({
284279
id: "ground-air-jump-unlock"
285280
}),
286281
on: {
287-
AirJumpUnlocked: ({ target }) =>
288-
target.local.AirJumpReady(State.cases.AirJumpReady.make({}))
282+
AirJumpUnlocked: ({ target }) => target.local.AirJumpReady(State.cases.AirJumpReady.make({}))
289283
}
290284
},
291285
AirJumpWallLock: {
292286
invoke: Machine.after("240 millis", InternalEvent.cases.AirJumpUnlocked.make({}), {
293287
id: "wall-air-jump-unlock"
294288
}),
295289
on: {
296-
AirJumpUnlocked: ({ target }) =>
297-
target.local.AirJumpReady(State.cases.AirJumpReady.make({}))
290+
AirJumpUnlocked: ({ target }) => target.local.AirJumpReady(State.cases.AirJumpReady.make({}))
298291
}
299292
},
300293
AirJumpReady: {
301294
on: {
302-
TryAirJump: Effect.fn(function* ({ event, runtime, target }) {
295+
TryAirJump: Effect.fn(function*({ event, runtime, target }) {
303296
const machine = yield* runtime
304297
yield* machine.raise(InternalEvent.cases.DoubleJump.make({ at: event.at }))
305298
return target.local.AirJumpSpent(State.cases.AirJumpSpent.make({}))
@@ -325,8 +318,7 @@ export const CharacterMachine = Machine.make({
325318
},
326319
Right: {
327320
on: {
328-
Move: ({ event, target }) =>
329-
event.axis === -1 ? target.local.Left(State.cases.Left.make({})) : undefined,
321+
Move: ({ event, target }) => event.axis === -1 ? target.local.Left(State.cases.Left.make({})) : undefined,
330322
WallJump: ({ event, target }) =>
331323
event.push === -1 ? target.local.Left(State.cases.Left.make({})) : undefined
332324
}
@@ -339,8 +331,8 @@ export const CharacterMachine = Machine.make({
339331
event.wall === -1
340332
? target.local.LeftWall(State.cases.LeftWall.make({}))
341333
: event.wall === 1
342-
? target.local.RightWall(State.cases.RightWall.make({}))
343-
: target.local.NoWall(State.cases.NoWall.make({}))
334+
? target.local.RightWall(State.cases.RightWall.make({}))
335+
: target.local.NoWall(State.cases.NoWall.make({}))
344336
},
345337
states: {
346338
NoWall: {},

examples/platformer/src/main.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import "./styles.css"
2-
import { Effect, Fiber, Stream } from "effect"
32
import { Machine } from "@typeonce/effect-machine"
3+
import { Effect, Fiber, Stream } from "effect"
44
import { GameAdapter } from "./game.ts"
55
import {
66
activeStateData,
77
airJumpMode,
8+
type CharacterEvent,
89
CharacterMachine,
10+
type CharacterSnapshot,
911
facingDirection,
1012
locomotionBranch,
1113
locomotionMode,
12-
wallContact,
13-
type CharacterEvent,
14-
type CharacterSnapshot
14+
wallContact
1515
} from "./machine.ts"
1616

1717
const requiredElement = <ElementType extends Element>(selector: string) => {
@@ -59,7 +59,7 @@ const publish = (next: CharacterSnapshot) => {
5959
})
6060
}
6161

62-
const program = Effect.gen(function* () {
62+
const program = Effect.gen(function*() {
6363
const actor = yield* Machine.start(CharacterMachine)
6464
deliver = (event) => Effect.runFork(actor.send(event).pipe(Effect.catchTag("StoppedError", () => Effect.void)))
6565
publish(yield* actor.state)

examples/pokemon/src/machine.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { Effect, Schema } from "effect"
21
import { Machine } from "@typeonce/effect-machine"
3-
import { Atom } from "effect/unstable/reactivity"
42
import { AtomMachine } from "@typeonce/effect-machine/reactivity"
3+
import { Effect, Schema } from "effect"
4+
import { Atom } from "effect/unstable/reactivity"
55
import { ReplaceMachine } from "./machines/replace.ts"
66
import { SelectionMachine } from "./machines/selection.ts"
77
import { Pokemon, PokemonService, ReplaceInTeam } from "./pokemon.ts"
@@ -18,7 +18,7 @@ export const ReplaceChild = Machine.child("replace", ReplaceMachine)
1818
const machine = Machine.make({
1919
states: States.states,
2020
events: [ReplaceInTeam],
21-
initial: Effect.fn(function* () {
21+
initial: Effect.fn(function*() {
2222
const pk = yield* PokemonService
2323
const team = yield* pk.getRandomTeam()
2424
return States.initial.ActiveTeam(new ActiveTeam({ team }))

examples/pokemon/src/machines/replace.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { Effect, Schema } from "effect"
21
import { Machine } from "@typeonce/effect-machine"
2+
import { Effect, Schema } from "effect"
33
import { Pokemon, PokemonService, ReplaceInTeam } from "../pokemon.ts"
44

55
class Idle extends Schema.TaggedClass<Idle>("Idle")("Idle", {}) {}
@@ -24,7 +24,7 @@ const ReplaceWithRandomMachine = Machine.invoke({
2424
Machine.effect(
2525
Effect.sleep("500 millis").pipe(
2626
Effect.andThen(
27-
Effect.gen(function* () {
27+
Effect.gen(function*() {
2828
const pk = yield* PokemonService
2929
const pokemon = yield* pk.getRandomPokemon()
3030
return new Replaced({ pokemon })

0 commit comments

Comments
 (0)