Skip to content

Instantly share code, notes, and snippets.

@Valkendorm
Created April 9, 2021 23:34
Show Gist options
  • Select an option

  • Save Valkendorm/bd8acacfb5d018a3ef7ec1e3fd56bdf3 to your computer and use it in GitHub Desktop.

Select an option

Save Valkendorm/bd8acacfb5d018a3ef7ec1e3fd56bdf3 to your computer and use it in GitHub Desktop.

Revisions

  1. Valkendorm created this gist Apr 9, 2021.
    56 changes: 56 additions & 0 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,56 @@

    // Available variables:
    // - Machine
    // - interpret
    // - assign
    // - send
    // - sendParent
    // - spawn
    // - raise
    // - actions
    // - XState (all XState exports)

    const doorMachine = Machine({
    states: {
    door: {
    id: "door",
    initial: 'closed',
    states: {
    closed: {},
    opened: {
    on: {
    CLOSE_DOOR: 'closed'
    }
    }
    }
    },
    handle: {
    id: "handle",
    initial: 'released',
    states: {
    released: {
    initial: 'unlocked',
    states: {
    unlocked: {
    on: {
    TOGGLE_LOCK: 'locked',
    TURN_HANDLE: '#handle.turned'
    }
    },
    locked: {
    on: {
    TOGGLE_LOCK: 'unlocked'
    }}
    }
    },
    turned: {
    on: {
    OPEN_DOOR: '#door.opened',
    RELEASE_HANDLE: 'released'
    }
    }
    }
    }
    },
    type: 'parallel'
    })