NetworkOperationState and RequestNetworkOperationModel for tracking network request state. Just like GeneralDataLoadingState but without empty state.
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user