NetworkOperationState and RequestNetworkOperationModel for tracking network request state. Just like GeneralDataLoadingState but without empty state.

This commit is contained in:
2018-05-18 18:52:40 +03:00
parent 4c6990883a
commit d600d57260
18 changed files with 445 additions and 93 deletions
@@ -20,6 +20,13 @@
// THE SOFTWARE.
//
/// Enum that contains states for general data loading.
///
/// - initial: Initial state. Before something will happen.
/// - loading: Loading state. When data loading is started.
/// - result: Result state from a specific data source with result.
/// - error: Error state with a specific error.
/// - empty: Empty state. When data was requested and empty result was received.
public enum GeneralDataLoadingState<DS: DataSource>: DataLoadingState {
case initial
@@ -55,4 +62,31 @@ public enum GeneralDataLoadingState<DS: DataSource>: DataLoadingState {
return .error(error: error)
}
public var isInitialState: Bool {
switch self {
case .initial:
return true
default:
return false
}
}
public var result: DS.ResultType? {
switch self {
case .result(let newResult, _):
return newResult
default:
return nil
}
}
public var error: Error? {
switch self {
case .error(let error):
return error
default:
return nil
}
}
}