/data_load_state.swift Secret
Last active
April 9, 2020 19:20
Star
You must be signed in to star a gist
`DataLoadState` sketch.
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
enum DataLoadState<Value, Error: Swift.Error> { | |
case initial | |
case loading | |
case loaded(Value) | |
case error(Error) /// (1) A challenging exercise for the reader is to think through extending | |
/// this type to support paginated loadings. | |
var isLoading: Bool { /// (2) Again, taking cue from Point Free’s enumeration properties work. | |
/// This will be helpful when enabling and disabling buttons while a request is in-flight. | |
switch self { | |
case .loading: | |
return true | |
default: | |
return false | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment