Skip to content

Instantly share code, notes, and snippets.

@christiannwamba
Created May 14, 2020 18:02
Show Gist options
  • Save christiannwamba/a537f1f1237f95ccf7aa1e542f49d310 to your computer and use it in GitHub Desktop.
Save christiannwamba/a537f1f1237f95ccf7aa1e542f49d310 to your computer and use it in GitHub Desktop.

Revisions

  1. christiannwamba created this gist May 14, 2020.
    35 changes: 35 additions & 0 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    // DEMO: History State (Shallow)


    const poweredOnStates = {
    lowHeat: {
    on: { TOGGLE_HEAT: 'highHeat' }
    },
    highHeat: {
    on: { TOGGLE_HEAT: 'lowHeat' }
    },
    // When this state node is activated
    // It returns the previous state of
    // poweredOnStates
    // A state that remembers :)
    hist: {
    type: 'history'
    }
    }


    const spaceHeaterMachine = Machine({
    id: 'spaceHeater',
    initial: 'poweredOff',
    states: {
    poweredOff: {
    on: { TOGGLE_POWER: 'poweredOn.hist' }
    },
    poweredOn: {
    on: { TOGGLE_POWER: 'poweredOff' },

    initial: 'lowHeat',
    states: poweredOnStates
    }
    }
    })