Last active
April 25, 2020 07:41
-
-
Save herrfugbaum/2c837af6a8c1d2fcc71ed78bdaa38b3c to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const replMachine = Machine({ | |
id: 'replMachine', | |
initial: 'repl', | |
context: { | |
cursor: 0, | |
data: [1,2,3,4,5] | |
}, | |
states: { | |
repl: { | |
on: { | |
ENTER_KEY: 'parsing' | |
} | |
}, | |
parsing: { | |
on: { | |
SUCCESS: 'readMore', | |
ERROR: 'error' | |
} | |
}, | |
readMore: { | |
on: { | |
SPACE_KEY: [ | |
{ | |
target: 'readMore', | |
cond: 'notOnLastPage', | |
actions: ['cursorIncrement'] | |
}, | |
{ | |
target: 'repl', | |
actions: ['cursorReset'] | |
} | |
], | |
readAll: { | |
target: 'repl', | |
actions: ['cursorReset'] | |
} | |
} | |
}, | |
error: { | |
on: { | |
'': { | |
target: 'repl', | |
actions: ['printError'] | |
} | |
} | |
} | |
} | |
}, | |
{ | |
actions: { | |
cursorIncrement: assign({ | |
cursor: context => context.cursor + 1, | |
}), | |
cursorReset : assign({ | |
cursor: context => context.cursor = 0, | |
}), | |
printError: () => console.log('Some Error occured!') | |
}, | |
guards: { | |
'notOnLastPage': (context,event) => context.cursor < context.data.length | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment