Last active
August 11, 2019 20:30
-
-
Save abierbaum/10c0df48ddd727d7a8d1f27dc781a9d9 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
// 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