Skip to content

Added module for Machine#6429

Open
SandroMaglione wants to merge 1 commit into
Effect-TS:mainfrom
SandroMaglione:sandro/state-charts
Open

Added module for Machine#6429
SandroMaglione wants to merge 1 commit into
Effect-TS:mainfrom
SandroMaglione:sandro/state-charts

Conversation

@SandroMaglione

Copy link
Copy Markdown
Contributor

Type

  • Refactor
  • Feature
  • Bug Fix
  • Optimization
  • Documentation Update

Description

Added Machine module with Atom adapter:

  • Machine ("state chart")
  • AtomMachine integration for effect-atom

The feature is exposed under effect/unstable/machine.

import { Machine } from "effect/unstable/machine"

class Cart extends Schema.TaggedClass<Cart>("Cart")("Cart", {
  orderId: Schema.String
}) {}

class Editing extends Schema.TaggedClass<Editing>("Editing")("Editing", {}) {}
class Reviewing extends Schema.TaggedClass<Reviewing>("Reviewing")("Reviewing", {}) {}

class Checkout extends Schema.TaggedClass<Checkout>("Checkout")("Checkout", {
  orderId: Schema.String
}) {}

class Payment extends Schema.TaggedClass<Payment>("Payment")("Payment", {
  status: Schema.Literals(["pending", "paid"])
}) {}

class Delivery extends Schema.TaggedClass<Delivery>("Delivery")("Delivery", {
  status: Schema.Literals(["label", "shipped"])
}) {}

class Review extends Schema.TaggedClass<Review>("Review")("Review", {}) {}

class Submit extends Schema.TaggedClass<Submit>("Submit")("Submit", {
  orderId: Schema.String
}) {}

const OrderStates = Machine.defineStates({
  cart: {
    schema: Cart,
    initial: "editing",
    states: {
      editing: Editing,
      reviewing: Reviewing
    }
  },
  checkout: {
    schema: Checkout,
    type: "parallel",
    states: {
      payment: Payment,
      delivery: Delivery
    }
  }
})

const orderMachine = Machine.make({
  id: "Order",
  states: OrderStates.states,
  events: [Review, Submit],
  initial: () =>
    OrderStates.initial.cart(
      new Cart({ orderId: "order-1" }),
      (cart) => cart.editing(new Editing({}))
    )
}).handle({
  cart: {
    states: {
      editing: {
        on: {
          Review: ({ target }) => target.local.reviewing(new Reviewing({}))
        }
      },
      reviewing: {
        on: {
          Submit: ({ event, target }) =>
            target.full.checkout(
              new Checkout({ orderId: event.orderId }),
              (checkout) =>
                checkout
                  .payment(new Payment({ status: "pending" }))
                  .delivery(new Delivery({ status: "label" }))
            )
        }
      }
    }
  }
})

Feel free to push back on any of the API decisions or to propose or ask for any change.

Related

Moved over from the effect-smol PR.

This work is inspired by xstate, and it builds on top of #1945.

@github-project-automation github-project-automation Bot moved this to Discussion Ongoing in PR Backlog Jul 16, 2026
@changeset-bot

changeset-bot Bot commented Jul 16, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 04966cf

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 27 packages
Name Type
effect Patch
@effect/opentelemetry Patch
@effect/platform-browser Patch
@effect/platform-bun Patch
@effect/platform-node-shared Patch
@effect/platform-node Patch
@effect/vitest Patch
@effect/ai-anthropic Patch
@effect/ai-openai-compat Patch
@effect/ai-openai Patch
@effect/ai-openrouter Patch
@effect/atom-react Patch
@effect/atom-solid Patch
@effect/atom-vue Patch
@effect/sql-clickhouse Patch
@effect/sql-d1 Patch
@effect/sql-libsql Patch
@effect/sql-mssql Patch
@effect/sql-mysql2 Patch
@effect/sql-pg Patch
@effect/sql-pglite Patch
@effect/sql-sqlite-bun Patch
@effect/sql-sqlite-do Patch
@effect/sql-sqlite-node Patch
@effect/sql-sqlite-react-native Patch
@effect/sql-sqlite-wasm Patch
@effect/openapi-generator Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@IMax153 IMax153 added the 4.0 label Jul 16, 2026
@IMax153
IMax153 requested a review from mikearnaldi July 19, 2026 17:28
@IMax153 IMax153 added the enhancement New feature or request label Jul 19, 2026
@tim-smart

Copy link
Copy Markdown
Contributor

What does the cluster integration look like?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4.0 enhancement New feature or request

Projects

Status: Discussion Ongoing

Development

Successfully merging this pull request may close these issues.

3 participants