Skip to content

Instantly share code, notes, and snippets.

@parker-codes
Created June 16, 2020 02:23
Show Gist options
  • Select an option

  • Save parker-codes/cb61aac756eeab0e9c4d4e00875b208e to your computer and use it in GitHub Desktop.

Select an option

Save parker-codes/cb61aac756eeab0e9c4d4e00875b208e to your computer and use it in GitHub Desktop.

Revisions

  1. parker-codes created this gist Jun 16, 2020.
    20 changes: 20 additions & 0 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@

    const increment = context => context.count + 1;
    const decrement = context => context.count - 1;
    const reset = context => context.count = 0;

    const counterMachine = Machine({
    initial: 'active',
    context: {
    count: 0
    },
    states: {
    active: {
    on: {
    INC: { actions: assign({ count: increment }) },
    DEC: { actions: assign({ count: decrement }) },
    RESET: { actions: assign({ count: reset }) }
    }
    }
    }
    });