Skip to content

Instantly share code, notes, and snippets.

@itacirgabral
Created September 29, 2021 04:43
Show Gist options
  • Select an option

  • Save itacirgabral/2ea77cf325a5acec3ffe02c6bb11e1e7 to your computer and use it in GitHub Desktop.

Select an option

Save itacirgabral/2ea77cf325a5acec3ffe02c6bb11e1e7 to your computer and use it in GitHub Desktop.

Revisions

  1. itacirgabral created this gist Sep 29, 2021.
    34 changes: 34 additions & 0 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    const machine = Machine({
    id: 'lightbulb',
    initial: 'unlit',
    states: {
    lit: {
    on: {
    TOGGLE: 'unlit',
    BREAK: 'broken'
    }
    },
    unlit: {
    exit: () => {},
    on: {
    TOGGLE: 'lit',
    BREAK: {
    target: 'broken',
    actions: [(ctx, e) => {
    console.log(e.myArg)
    }, 'logB']
    }
    }
    },
    broken: {
    type: 'final',
    entry: (ctx, e) => {} // ['a', 'b']
    }
    },
    strict: true
    }, {
    actions: {
    logB: () => console.log('b')
    },

    })