Loadable

public enum Loadable<Value>
extension Loadable: Equatable where Value: Equatable

Enum representing the loadable state of a value of type Value.

This enum assumes use within EPI networking context, hence error state is represented by NetworkError object

  • The value has not been requested yet.

    This is convenience value that can be used as initial value for initialised Loadable or LoadableSubject instance.

    Declaration

    Swift

    case notRequested
  • The value is currently being loaded. Allows access to the last loaded value (if available) and a cancel bag.

    CancelBag instance can be used to cancel loading through cancelLoading method or manually if flow requires non-standard handling

    Declaration

    Swift

    case isLoading(last: Value?, cancelBag: CancelBag)
  • State representing value that has been successfully loaded.

    Declaration

    Swift

    case loaded(Value)
  • The loading process has failed with an error in form of typed NetworkError.

    NetworkError contains details regarding HTTP or API error that occured during loading.

    Declaration

    Swift

    case failed(NetworkError)
  • The loaded value.

    Declaration

    Swift

    public var value: Value? { get }
  • The network error encountered during the loading process.

    Declaration

    Swift

    public var error: NetworkError? { get }
  • A boolean flag indicating whether the value is currently being loaded.

    Declaration

    Swift

    public var isLoading: Bool { get }
  • Sets the loadable state to isLoading, along with the last loaded value and a cancel bag.

    Declaration

    Swift

    mutating func setIsLoading(cancelBag: CancelBag)

    Parameters

    cancelBag

    The CancelBag to be associated with the loading process.

  • Cancels the loading process.

    If the loading process was in progress, it cancels it by calling cancel() on the associated cancel bag. If there was a last loaded value available, the loadable state is updated to .loaded with the last value. Otherwise, the loadable state is updated to .failed with a NetworkError indicating cancellation by the user through cancelled status.

    Declaration

    Swift

    mutating func cancelLoading()
  • Maps the loaded value to a new loadable state using the given transform closure.

    Declaration

    Swift

    func map<MappedValue>(_ transform: (Value) throws -> MappedValue) -> Loadable<MappedValue>

    Parameters

    transform

    The closure to transform the loaded value.

    Return Value

    The transformed loadable state.

Available where Value: Equatable

  • Determines whether two loadable values are equal.

    Two loadable values are considered equal if they have the same Loadable state.

    Declaration

    Swift

    public static func == (lhs: Loadable<Value>, rhs: Loadable<Value>) -> Bool

    Parameters

    lhs

    The first loadable value to compare.

    rhs

    The second loadable value to compare.

    Return Value

    true if the loadable values are equal, false otherwise.