Skip to content

Instantly share code, notes, and snippets.

@pangratz
Last active January 24, 2021 19:34
Show Gist options
  • Select an option

  • Save pangratz/6a81c3860b6292baab6e14da952744b0 to your computer and use it in GitHub Desktop.

Select an option

Save pangratz/6a81c3860b6292baab6e14da952744b0 to your computer and use it in GitHub Desktop.

Revisions

  1. pangratz revised this gist Jan 24, 2021. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion machine.js
    Original file line number Diff line number Diff line change
    @@ -38,7 +38,8 @@
    unstarted: {
    on: {
    START: {
    target: 'started'
    target: 'started',
    actions: ['resetCurrentCardIndex']
    }
    }
    },
  2. pangratz revised this gist Jan 24, 2021. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -49,13 +49,15 @@
    target: 'finished',
    cond: 'isLast'
    }, {
    target: 'started'
    target: 'started',
    actions: ['incrementCurrentCardIndex']
    }],
    PREV: [{
    target: 'unstarted',
    cond: 'isFirst'
    }, {
    target: 'started'
    target: 'started',
    actions: ['decrementCurrentCardIndex']
    }]
    }
    },
  3. pangratz revised this gist Jan 24, 2021. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -15,6 +15,11 @@

    initial: 'overview',

    context: {
    cards: null,
    currentCardIndex: null
    },

    states: {
    overview: {
    on: {
  4. pangratz revised this gist Jan 24, 2021. 1 changed file with 9 additions and 1 deletion.
    10 changes: 9 additions & 1 deletion machine.js
    Original file line number Diff line number Diff line change
    @@ -16,10 +16,18 @@
    initial: 'overview',

    states: {
    overview: {},
    overview: {
    on: {
    START_QUIZ: 'quiz'
    }
    },

    quiz: {
    initial: 'unstarted',

    on: {
    CANCEL_QUIZ: 'overview'
    },

    states: {
    unstarted: {
  5. pangratz revised this gist Jan 24, 2021. 1 changed file with 30 additions and 3 deletions.
    33 changes: 30 additions & 3 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -22,11 +22,38 @@
    initial: 'unstarted',

    states: {
    unstarted: {},
    unstarted: {
    on: {
    START: {
    target: 'started'
    }
    }
    },

    started: {},
    started: {
    on: {
    NEXT: [{
    target: 'finished',
    cond: 'isLast'
    }, {
    target: 'started'
    }],
    PREV: [{
    target: 'unstarted',
    cond: 'isFirst'
    }, {
    target: 'started'
    }]
    }
    },

    finished: {}
    finished: {
    on: {
    RESTART: {
    target: 'unstarted'
    }
    }
    }
    }
    }
    }
  6. pangratz created this gist Jan 23, 2021.
    34 changes: 34 additions & 0 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@

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

    const fetchMachine = Machine({
    id: 'house-of-cards',

    initial: 'overview',

    states: {
    overview: {},

    quiz: {
    initial: 'unstarted',

    states: {
    unstarted: {},

    started: {},

    finished: {}
    }
    }
    }
    });