Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Available variables:
- // - Machine
- // - interpret
- // - assign
- // - send
- // - sendParent
- // - spawn
- // - raise
- // - actions
- // - XState (all XState exports)
- const singlePage = 5;
- const selectedMachine = Machine({
- id: "selected",
- initial: "empty",
- context: {
- cache: false
- },
- states: {
- empty: {
- on: {
- SELECTION_ADDED: "some"
- }
- },
- some: {
- on: {
- SELECTION_ADDED: [{
- target: "fetching",
- cond: "pageExistsInCache"
- },
- {
- target: "some"
- }],
- PAGE_REQUESTED: [{
- target: "fetching",
- cond: "pageExistsInCache"
- },
- {
- target: "some"
- }]
- }
- },
- fetching: {
- invoke: {
- src: () => new Promise(res => setTimeout(res, 500)),
- onDone: {
- target: "some",
- actions: "addToCache"
- }
- }
- }
- }
- }, {
- actions: {
- addToCache: assign({
- cache: true
- })
- },
- guards: {
- pageExistsInCache: (ctx) => ctx.cache
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement