Skip to content

Instantly share code, notes, and snippets.

@abierbaum
Last active August 11, 2019 20:30
Show Gist options
  • Save abierbaum/10c0df48ddd727d7a8d1f27dc781a9d9 to your computer and use it in GitHub Desktop.
Save abierbaum/10c0df48ddd727d7a8d1f27dc781a9d9 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// Missing a reconnect
const ws_machine = Machine({
id: 'ws_machine',
initial: 'disconnected',
strict: true,
context: {
retries: 0
},
states: {
disconnected: {
on: {
CONNECT: 'connecting'
}
},
connecting: {
invoke: {
src: 'makeConnect',
onError: {
target: 'disconnected',
actions: assign({
retries: (context, event) => context.retries + 1
})
},
onDone: {
target: 'connected',
actions: assign({
retries: (context, event) => 0
})
}
},
on: {
CONNECT: undefined,
DISCONNECT: 'disconnecting'
}
},
connected: {
initial: 'start_count',
states: {
'start_count': {
/*
on: {
'': 'waiting'
}*/
after: {
1: 'waiting'
}
},
'waiting': {
after: {
10000: { target: '#disconnecting' }
},
on: {
REST_TIMER: {
//internal: false,
target: 'start_count'
}
}
}
},
on: {
DISCONNECT: '#disconnecting'
}
},
disconnecting: {
id: 'disconnecting',
invoke: {
src: 'dropConnection',
onError: {
target: 'disconnected',
},
onDone: {
target: 'disconnected'
}
}
}
}
/*,{
actions: {
doSomething: (context, event) => {
alert('Done');
}
}
}*/
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment