Skip to content

Instantly share code, notes, and snippets.

@nightink
Created December 23, 2019 03:21
Show Gist options
  • Save nightink/25fa49083374e6e45a0977ffda66484a to your computer and use it in GitHub Desktop.
Save nightink/25fa49083374e6e45a0977ffda66484a 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)
let lionMachine = Machine(
{
id: 'lion',
initial: 'idle',
context: {
displayIndex: 0 // 龙骨、背景图展示第几套
},
states: {
idle: {
on: {
CLICK: 'jiaohu',
UP_CLICK: 'preUpgrade'
},
entry: 'play'
},
jiaohu: {
type: 'parallel',
states: {
animation: {
initial: 'playing',
states: {
playing: {
on: {
LOOP_END_hudong: [
{
target: '#lion.idle',
in: '#lion.jiaohu.rpc.end'
},
{ target: 'playing' }
]
},
entry: 'play'
}
}
},
rpc: {
initial: 'init',
states: {
init: {
invoke: {
src: 'poke',
onDone: 'end',
onError: 'end'
}
},
end: {
type: 'final'
}
}
}
}
},
preUpgrade: {
invoke: {
src: 'fetchUpgrade',
onDone: {
target: 'upgrade',
actions: assign((context, event) => ({
displayIndex: event.data.displayIndex
}))
},
onError: 'idle'
}
},
upgrade: {
on: {
END: 'idle'
},
entry: 'play'
}
}
},
{}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment