Last active
October 26, 2019 17:26
-
-
Save sytabaresa/655cd249767f498a6a3cab48ec21f58e 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 { cancel } = actions | |
const playerMachine = Machine( | |
{ | |
id: 'player', | |
initial: 'idle', | |
context: { | |
promotion: 0, | |
promotionCounter: 0 | |
}, | |
states: { | |
idle: { | |
on: { | |
PLAY: [ | |
{target: 'promo', cond: 'showPromo'}, | |
{target: 'changing'} | |
] | |
} | |
}, | |
changing: { | |
entry: 'setIdleTimer', | |
onExit: 'clearIdleTimer', | |
on: { | |
PLAY: [ | |
{target: 'idle', actions: ["displaySong", 'incrementPromotionalCounter']} | |
], | |
TIMER: [ | |
{target: 'idle', actions: ["displaySong", 'incrementPromotionalCounter']} | |
], | |
END: {target: 'idle'}, | |
} | |
}, | |
promo: { | |
on: { | |
END: {target: 'idle'} | |
} | |
} | |
} | |
}, | |
{ | |
guards: { | |
showPromo: (context, event) => context.promotionCounter > 10 | |
}, | |
actions: { | |
incrementPromotionalCounter: assign({ | |
promotionCounter: (context, event) => context.promotionCounter + 1 | |
}), | |
displaySong: (context, event) => console.log("change"), | |
setIdleTimer: send('TIMER', {id: 'idleTimer',delay:1000}), | |
clearIdleTimer: cancel('idleTimer') | |
} | |
} | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment