Skip to content

Instantly share code, notes, and snippets.

@zsimo
Created December 17, 2019 14:12
Show Gist options
  • Save zsimo/3bc54eb227e34600d551edd9b7607367 to your computer and use it in GitHub Desktop.
Save zsimo/3bc54eb227e34600d551edd9b7607367 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// - XState (all XState exports)
const fetchMachine = Machine({
id: 'scroll',
initial: 'idle',
context: {
scroll_top: 0
},
states: {
idle: {
on: {
// event
READY: { // transition
// transition target (target status)
target: 'ready',
// transition actions
// An action is the way a statechart can cause things to happen in the outside world
actions: assign({
number_of_records: function (ctx, event) {
return event.number_of_records;
}
})
}
}
},
ready: {
on: {
SCROLL: {
target: 'scrolling',
actions: assign({
scroll_top: function (ctx, event) {
return event.drag_area;
}
})
}
}
},
not_scrolling: {
on: {
SCROLL: {
target: 'scrolling',
actions: assign({
scroll_top: function (ctx, event) {
return event.drag_area;
}
})
}
}
},
scrolling: {
on: {
STOP_SCROLL: 'not_scrolling'
},
activities: ['checking'],
}
}
},
{
activities: {
checking: () => {
// Start the beeping activity
const interval = setInterval(() => console.log('BEEP!'), 1000);
// Return a function that stops the beeping activity
return () => clearInterval(interval);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment