Skip to content

Instantly share code, notes, and snippets.

@bautistaaa
Last active July 19, 2021 11:44
Show Gist options
  • Save bautistaaa/1d7adc18a4c7aafab64a9a5c9630d773 to your computer and use it in GitHub Desktop.
Save bautistaaa/1d7adc18a4c7aafab64a9a5c9630d773 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const playerMachine = Machine({
id: 'player',
initial: 'boot',
context: {
playbackState: undefined
},
states: {
boot: {
on: {
RESOLVE: { target: 'initialized'},
REJECT: { target: 'failed'},
},
},
initialized: {
type: 'parallel',
states : {
playback: {
initial: 'idle',
states: {
idle: {
on: {
PLAY: 'play'
}
},
play: {
on: {
PAUSE: 'pause'
}
},
pause: {
on: {
PLAY: 'play'
}
}
}
},
shuffle: {
initial: 'disabled',
states: {
disabled: {
on: { TOGGLE_SHUFFLE: 'enabled' },
},
enabled: {
on: { TOGGLE_SHUFFLE: 'disabled' },
},
},
},
repeat: {
initial: 'off',
states: {
off: {
on: { TOGGLE_REPEAT: 'all' },
},
all: {
on: { TOGGLE_REPEAT: 'one' },
},
one: {
on: { TOGGLE_REPEAT: 'off' },
},
},
},
modifyVolume: {
actions: ['modifyVolume']
},
},
},
failed: {}
}
}, {
actions: {
modifyVolume: assign({ volume: (_, event) => event.payload.data }),
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment