Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
stephencelis committed Nov 8, 2023
1 parent 40d35a5 commit cbc7df1
Show file tree
Hide file tree
Showing 158 changed files with 649 additions and 559 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-concurrency-extras",
"state" : {
"revision" : "ea631ce892687f5432a833312292b80db238186a",
"version" : "1.0.0"
"revision" : "bb5059bde9022d69ac516803f4f227d8ac967f71",
"version" : "1.1.0"
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ struct AlertAndConfirmationDialog {
var count = 0
}

enum Action: Equatable {
enum Action {
case alert(PresentationAction<Alert>)
case alertButtonTapped
case confirmationDialog(PresentationAction<ConfirmationDialog>)
case confirmationDialogButtonTapped

enum Alert: Equatable {
enum Alert {
case incrementButtonTapped
}
enum ConfirmationDialog: Equatable {
enum ConfirmationDialog {
case incrementButtonTapped
case decrementButtonTapped
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ struct Animations {
var isCircleScaled = false
}

enum Action: Equatable, Sendable {
enum Action: Sendable {
case alert(PresentationAction<Alert>)
case circleScaleToggleChanged(Bool)
case rainbowButtonTapped
case resetButtonTapped
case setColor(Color)
case tapped(CGPoint)

enum Alert: Equatable, Sendable {
enum Alert: Sendable {
case resetConfirmationButtonTapped
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ struct BindingForm {
@BindingState var toggleIsOn = false
}

enum Action: BindableAction, Equatable {
enum Action: BindableAction {
case binding(BindingAction<State>)
case resetButtonTapped
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct TwoCounters {
var counter2 = Counter.State()
}

enum Action: Equatable {
enum Action {
case counter1(Counter.Action)
case counter2(Counter.Action)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ struct Counter {
var count = 0
}

enum Action: Equatable {
enum Action {
case decrementButtonTapped
case incrementButtonTapped
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ struct FocusDemo {
}
}

enum Action: BindableAction, Equatable {
enum Action: BindableAction {
case binding(BindingAction<State>)
case signInButtonTapped
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct OptionalBasics {
var optionalCounter: Counter.State?
}

enum Action: Equatable {
enum Action {
case optionalCounter(Counter.Action)
case toggleCounterButtonTapped
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ struct SharedState {
}
}

enum Action: Equatable {
enum Action {
case counter(Counter.Action)
case profile(Profile.Action)
case selectTab(Tab)
Expand Down Expand Up @@ -83,7 +83,7 @@ struct SharedState {
var numberOfCounts = 0
}

enum Action: Equatable {
enum Action {
case alert(PresentationAction<Alert>)
case decrementButtonTapped
case incrementButtonTapped
Expand Down Expand Up @@ -143,7 +143,7 @@ struct SharedState {
}
}

enum Action: Equatable {
enum Action {
case resetCounterButtonTapped
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ struct EffectsBasics {
var numberFact: String?
}

enum Action: Equatable {
enum Action {
case decrementButtonTapped
case decrementDelayResponse
case incrementButtonTapped
case numberFactButtonTapped
case numberFactResponse(TaskResult<String>)
case numberFactResponse(Result<String, Error>)
}

@Dependency(\.continuousClock) var clock
Expand Down Expand Up @@ -74,7 +74,7 @@ struct EffectsBasics {
// Return an effect that fetches a number fact from the API and returns the
// value back to the reducer's `numberFactResponse` action.
return .run { [count = state.count] send in
await send(.numberFactResponse(TaskResult { try await self.factClient.fetch(count) }))
await send(.numberFactResponse(Result { try await self.factClient.fetch(count) }))
}

case let .numberFactResponse(.success(response)):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ struct EffectsCancellation {
var isFactRequestInFlight = false
}

enum Action: Equatable {
enum Action {
case cancelButtonTapped
case stepperChanged(Int)
case factButtonTapped
case factResponse(TaskResult<String>)
case factResponse(Result<String, Error>)
}

@Dependency(\.factClient) var factClient
Expand All @@ -50,7 +50,7 @@ struct EffectsCancellation {
state.isFactRequestInFlight = true

return .run { [count = state.count] send in
await send(.factResponse(TaskResult { try await self.factClient.fetch(count) }))
await send(.factResponse(Result { try await self.factClient.fetch(count) }))
}
.cancellable(id: CancelID.factRequest)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ struct LongLivingEffects {
var screenshotCount = 0
}

enum Action: Equatable {
enum Action {
case task
case userDidTakeScreenshotNotification
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ struct Refreshable {
var fact: String?
}

enum Action: Equatable {
enum Action {
case cancelButtonTapped
case decrementButtonTapped
case factResponse(TaskResult<String>)
case factResponse(Result<String, Error>)
case incrementButtonTapped
case refresh
}
Expand Down Expand Up @@ -57,7 +57,7 @@ struct Refreshable {
state.fact = nil
return .run { [count = state.count] send in
await send(
.factResponse(TaskResult { try await self.factClient.fetch(count) }),
.factResponse(Result { try await self.factClient.fetch(count) }),
animation: .default
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ struct WebSocket {
}
}

enum Action: Equatable {
enum Action {
case alert(PresentationAction<Alert>)
case connectButtonTapped
case messageToSendChanged(String)
case receivedSocketMessage(TaskResult<WebSocketClient.Message>)
case receivedSocketMessage(Result<WebSocketClient.Message, Error>)
case sendButtonTapped
case sendResponse(didSucceed: Bool)
case webSocket(WebSocketClient.Action)
Expand Down Expand Up @@ -208,11 +208,13 @@ struct WebSocketClient {
}
}

enum Action: Equatable {
@CasePathable
enum Action {
case didOpen(protocol: String?)
case didClose(code: URLSessionWebSocketTask.CloseCode, reason: Data?)
}

@CasePathable
enum Message: Equatable {
struct Unknown: Error {}

Expand All @@ -229,7 +231,7 @@ struct WebSocketClient {
}

var open: @Sendable (ID, URL, [String]) async -> AsyncStream<Action>
var receive: @Sendable (ID) async throws -> AsyncStream<TaskResult<Message>>
var receive: @Sendable (ID) async throws -> AsyncStream<Result<Message, Error>>
var send: @Sendable (ID, URLSessionWebSocketTask.Message) async throws -> Void
var sendPing: @Sendable (ID) async throws -> Void
}
Expand Down Expand Up @@ -297,12 +299,12 @@ extension WebSocketClient: DependencyKey {
try self.socket(id: id).cancel(with: closeCode, reason: reason)
}

func receive(id: ID) throws -> AsyncStream<TaskResult<Message>> {
func receive(id: ID) throws -> AsyncStream<Result<Message, Error>> {
let socket = try self.socket(id: id)
return AsyncStream { continuation in
let task = Task {
while !Task.isCancelled {
continuation.yield(await TaskResult { try await Message(socket.receive()) })
continuation.yield(await Result { try await Message(socket.receive()) })
}
continuation.finish()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ struct NavigateAndLoadList {
}
}

enum Action: Equatable {
enum Action {
case counter(Counter.Action)
case setNavigation(selection: UUID?)
case setNavigationSelectionDelayCompleted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ struct NavigateAndLoad {
var optionalCounter: Counter.State?
}

enum Action: Equatable {
enum Action {
case optionalCounter(Counter.Action)
case setNavigation(isActive: Bool)
case setNavigationIsActiveDelayCompleted
Expand Down
14 changes: 7 additions & 7 deletions Examples/CaseStudies/SwiftUICaseStudies/03-NavigationStack.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ struct NavigationDemo {
var path = StackState<Path.State>()
}

enum Action: Equatable {
enum Action {
case goBackToScreen(id: StackElementID)
case goToABCButtonTapped
case path(StackAction<Path.State, Path.Action>)
Expand Down Expand Up @@ -67,7 +67,7 @@ struct NavigationDemo {
case screenC(ScreenC.State = .init())
}

enum Action: Equatable {
enum Action {
case screenA(ScreenA.Action)
case screenB(ScreenB.Action)
case screenC(ScreenC.Action)
Expand Down Expand Up @@ -220,12 +220,12 @@ struct ScreenA {
var isLoading = false
}

enum Action: Equatable {
enum Action {
case decrementButtonTapped
case dismissButtonTapped
case incrementButtonTapped
case factButtonTapped
case factResponse(TaskResult<String>)
case factResponse(Result<String, Error>)
}

@Dependency(\.dismiss) var dismiss
Expand All @@ -250,7 +250,7 @@ struct ScreenA {
case .factButtonTapped:
state.isLoading = true
return .run { [count = state.count] send in
await send(.factResponse(.init { try await self.factClient.fetch(count) }))
await send(.factResponse(Result { try await self.factClient.fetch(count) }))
}

case let .factResponse(.success(fact)):
Expand Down Expand Up @@ -348,7 +348,7 @@ struct ScreenAView: View {
struct ScreenB {
struct State: Codable, Equatable, Hashable {}

enum Action: Equatable {
enum Action {
case screenAButtonTapped
case screenBButtonTapped
case screenCButtonTapped
Expand Down Expand Up @@ -405,7 +405,7 @@ struct ScreenC {
var isTimerRunning = false
}

enum Action: Equatable {
enum Action {
case startButtonTapped
case stopButtonTapped
case timerTick
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ struct Nested: Reducer {
var rows: IdentifiedArrayOf<State> = []
}

// NB: `@Reducer` cannot be applied to recursive reducers.
@CasePathable
enum Action: Equatable {
enum Action {
case addRowButtonTapped
case nameTextFieldChanged(String)
case onDelete(IndexSet)
indirect case row(id: State.ID, action: Action)
indirect case rows(IdentifiedActionOf<Nested>)
}

@Dependency(\.uuid) var uuid
Expand All @@ -43,11 +44,11 @@ struct Nested: Reducer {
state.rows.remove(atOffsets: indexSet)
return .none

case .row:
case .rows:
return .none
}
}
.forEach(\.rows, action: \.row) {
.forEach(\.rows, action: \.rows) {
Self()
}
}
Expand All @@ -67,9 +68,7 @@ struct NestedView: View {
AboutView(readMe: readMe)
}

ForEachStore(
self.store.scope(state: \.rows, action: { .row(id: $0, action: $1) })
) { rowStore in
ForEachStore(self.store.scope(state: \.rows, action: { .rows($0) })) { rowStore in
WithViewStore(rowStore, observe: \.name) { rowViewStore in
NavigationLink(
destination: NestedView(store: rowStore)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import XCTestDynamicOverlay
struct DownloadClient {
var download: @Sendable (URL) -> AsyncThrowingStream<Event, Error>

@CasePathable
enum Event: Equatable {
case response(Data)
case updateProgress(Double)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ struct DownloadComponent {
let url: URL
}

enum Action: Equatable {
enum Action {
case alert(PresentationAction<Alert>)
case buttonTapped
case downloadClient(TaskResult<DownloadClient.Event>)
case downloadClient(Result<DownloadClient.Event, Error>)

enum Alert: Equatable {
enum Alert {
case deleteButtonTapped
case stopButtonTapped
}
Expand Down
Loading

0 comments on commit cbc7df1

Please sign in to comment.