Created
December 17, 2019 14:12
-
-
Save zsimo/3bc54eb227e34600d551edd9b7607367 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
// 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