Skip to content

Take one options object in createMachineContext factories - #244

Merged
SandroMaglione merged 1 commit into
mainfrom
claude/gifted-bardeen-c3ehlr
Oct 23, 2026
Merged

SandroMaglione merged 1 commit into
mainfrom
claude/gifted-bardeen-c3ehlr

Conversation

@SandroMaglione

Copy link
Copy Markdown
Member

Summary

  • createMachineContext factories take no parameters or one options object. Each declared option, input or layer, is a required Provider prop of the same name and type.
  • A machine that needs only a capability layer declares ({ layer }) instead of the (_: void, layer) placeholder.
  • Options other than input and layer are a type error, so a capability cannot be passed under another name such as router.
  • A factory without parameters, such as AtomMachine.factory(Machine) for a machine without input, is still passed directly and called without an options object.
  • Breaking: a positional input factory, such as AtomMachine.factory(Machine) for a machine with input, is now a type error. Write ({ input }: { input: Input }) => AtomMachine.make(Machine, input).
  • Docs, README, JSDoc, runtime tests and typetests are updated.

Changeset

  • Added or updated for a library or package-metadata change
  • Not required because this PR does not change a publishable package

Minor changeset for @typeonce/effect-machine-react, with the migration.

Validation

  • pnpm check
  • Automated type-performance measurement passed or was not required
  • Automated runtime- and memory-performance measurement passed or was not required

Every pnpm check step passed locally, with two exceptions. The format check cannot download dprint plugins in this sandbox, so formatting was checked with the same plugin versions taken from npm. The devtools static-site test times out locally on unchanged main too. pnpm perf:types passed its budgets locally.


Generated by Claude Code

A factory declares the options it uses, input and layer, and each one is a
Provider prop of the same name and type. A machine that needs only a
capability layer no longer declares a placeholder input parameter. Options
other than input and layer are rejected, and a factory without parameters,
such as AtomMachine.factory for a machine without input, is still passed
directly.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01H9xMXPkpeqmvAbWNGY7R55
@github-actions

Copy link
Copy Markdown
Contributor

Type performance

Measured with TypeScript 6.0.3 and skipLibCheck=true.

Scenario Base PR Difference
Effect only 55 55 0 (0.0%)
Import effect-machine 55 55 0 (0.0%)
Machine.state (3 children) 2,664 2,664 0 (0.0%)
Machine.make (3 states, 2 events) 8,932 8,932 0 (0.0%)
machine.handle (3 states, 2 transitions) 39,449 39,449 0 (0.0%)
declared transition (10 named branches) 60,402 60,402 0 (0.0%)
atomic construction, guards, and reentry 85,710 85,710 0 (0.0%)
registered invocation (input-taking Effect) 39,819 39,819 0 (0.0%)
machine.handle (depth 24) 194,531 194,531 0 (0.0%)
machine.handle (wide depth 16) 218,238 218,238 0 (0.0%)
machine.handle (parallel/history/choice) 91,642 91,642 0 (0.0%)
machine definition (3 independent implementations) 99,173 99,173 0 (0.0%)
machine exact input/output/error/services 82,941 82,941 0 (0.0%)
execution adapter readiness 71,428 71,428 0 (0.0%)

Marginal instantiations are measured against the matching setup without that API call:

Scenario Base PR Difference
Import effect-machine 0 0 0
Machine.state (3 children) 2,609 2,609 0 (0.0%)
Machine.make (3 states, 2 events) 6,260 6,260 0 (0.0%)
machine.handle (3 states, 2 transitions) 30,517 30,517 0 (0.0%)
declared transition (10 named branches) 51,849 51,849 0 (0.0%)
atomic construction, guards, and reentry 70,370 70,370 0 (0.0%)
registered invocation (input-taking Effect) 32,682 32,682 0 (0.0%)
machine.handle (depth 24) 177,222 177,222 0 (0.0%)
machine.handle (wide depth 16) 201,707 201,707 0 (0.0%)
machine.handle (parallel/history/choice) 79,144 79,144 0 (0.0%)
machine definition (3 independent implementations) 88,492 88,492 0 (0.0%)
machine exact input/output/error/services 70,732 70,732 0 (0.0%)
execution adapter readiness 31,922 31,922 0 (0.0%)
Check times (informational)
Scenario Base PR
Effect only 0.02s 0.02s
Import effect-machine 0.02s 0.02s
Machine.state (3 children) 0.05s 0.05s
Machine.make (3 states, 2 events) 0.08s 0.08s
machine.handle (3 states, 2 transitions) 0.18s 0.18s
declared transition (10 named branches) 0.23s 0.24s
atomic construction, guards, and reentry 0.30s 0.30s
registered invocation (input-taking Effect) 0.19s 0.18s
machine.handle (depth 24) 0.36s 0.35s
machine.handle (wide depth 16) 0.42s 0.43s
machine.handle (parallel/history/choice) 0.32s 0.32s
machine definition (3 independent implementations) 0.32s 0.32s
machine exact input/output/error/services 0.31s 0.32s
execution adapter readiness 0.27s 0.26s

Type instantiations are the comparison metric. Check time varies with runner load and is informational only.

@SandroMaglione
SandroMaglione merged commit 401fee7 into main Oct 23, 2026
9 checks passed
@SandroMaglione
SandroMaglione deleted the claude/gifted-bardeen-c3ehlr branch October 23, 2026 00:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants