Last active
July 11, 2021 10:24
-
-
Save tom-sherman/77aacd62ac46d545f6ae6c4c6de5fc05 to your computer and use it in GitHub Desktop.
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
module FetchMachine = Machine({ | |
type state = [#idle | #loading | #success | #failure] | |
type event = [#FETCH | #RESOLVE | #REJECT | #RETRY] | |
type context = {retries: int} | |
let id = "fetch" | |
let initial = #idle | |
let states = [ | |
State({ | |
name: #idle, | |
on: [(#FETCH, #loading)], | |
}), | |
State({ | |
name: #loading, | |
on: [(#RESOLVE, #success), (#REJECT, #failure)], | |
}), | |
Final({ | |
name: #success, | |
}), | |
State({ | |
name: #failure, | |
on: [(#RETRY, #loading)], | |
}), | |
] | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment