swift-composable-architecture-extras

1.4.0

Library to make swift-composable-architecture more useful
Ryu0118/swift-composable-architecture-extras

What's New

v1.4.0

2023-11-15T06:19:36Z

What's Changed

  • Bump swift-composable-architecture to 1.0.0<2.0.0 by @Ryu0118 in #3

Full Changelog: 1.3.0...1.4.0

Composable Architecture Extras

Language:Swift License:MIT Latest Release Twitter

A companion library to Point-Free's swift-composable-architecture.

TaskResult And VoidSuccess

In the current TCA, TaskResult was not Equatable compliant, so it must be written like this

public struct HogeFeature: Reducer {
  public struct State: Equatable {}
  public enum Action: Equatable {
    case onAppear
    case response(TaskResult<EquatableVoid>)
  }

  public func reduce(into state: inout State, action: Action) -> Effect<Action> {
    switch action {
    case .onAppear:
      return .run { send in
        await send(
          .response(
            TaskResult {
              try await asyncThrowsVoidFunc()
              return VoidSuccess()
            }
          )
        )
      }
    case .response(.success):
      // do something
      return .none

    case .response(.failure(let error)):
      // handle error
      return .none
    }
  }
}

it is not kind to create an VoidSuccess on user just to conform TaskResult to Equatable even though Void is already provided in Swift. So we extended TaskResult so that it could be written like this.

public struct HogeFeature: Reducer {
  public struct State: Equatable {}
  public enum Action: Equatable {
    case onAppear
    case response(TaskResult<VoidSuccess>)
  }

  public func reduce(into state: inout State, action: Action) -> Effect<Action> {
    switch action {
    case .onAppear:
      return .run { send in
        await send(
          .response(
            TaskResult {
              try await asyncThrowsVoidFunc()
            }
          )
        )
      }
    case .response(.success):
      // do something
      return .none

    case .response(.failure(let error)):
      // handle error
      return .none
    }
  }
}

Installation

In the dependencies section, add:

.package(url: "https://github.com/Ryu0118/swift-composable-architecture-extras", from: "1.0.0")

In each module, add:

.target(
  name: "MyModule",
  dependencies: [
    .product(name: "ComposableArchitectureExtras", package: "swift-composable-architecture-extras")
  ]
),

Description

  • Swift Tools 5.7.0
View More Packages from this Author

Dependencies

Last updated: Thu Nov 21 2024 10:32:53 GMT-1000 (Hawaii-Aleutian Standard Time)