Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
stephtelolahy committed Jan 18, 2025
1 parent d1600f4 commit 9f3fdc1
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
6 changes: 3 additions & 3 deletions WildWestOnline/UI/Game/Sources/GameView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ struct GameView: View {
}

@Environment(\.theme) private var theme
@StateObject private var store: Store<State>
@StateObject private var store: Store<State, Void>

init(store: @escaping () -> Store<State>) {
init(store: @escaping () -> Store<State, Void>) {
// SwiftUI ensures that the following initialization uses the
// closure only once during the lifetime of the view.
_store = StateObject(wrappedValue: store())
Expand All @@ -72,7 +72,7 @@ struct GameView: View {

#Preview {
GameView {
.init(initial: .mockedData)
.init(initialState: .mockedData, dependencies: ())
}
}

Expand Down
2 changes: 1 addition & 1 deletion WildWestOnline/UI/Game/Sources/GameViewBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import AppCore
import GameCore

public struct GameViewBuilder: View {
@EnvironmentObject private var store: Store<AppState>
@EnvironmentObject private var store: Store<AppState, AppDependencies>

public init() {}

Expand Down
20 changes: 14 additions & 6 deletions WildWestOnline/UI/Game/Sources/UIKit/GamePlayViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class GamePlayViewController: UIViewController {

// MARK: - Data

private var store: Store<GameView.State>
private var store: Store<GameView.State, Void>
private var subscriptions: Set<AnyCancellable> = []
private var events: [String] = []

Expand All @@ -45,7 +45,7 @@ class GamePlayViewController: UIViewController {

// MARK: - Init

init(store: Store<GameView.State>) {
init(store: Store<GameView.State, Void>) {
self.store = store
super.init(nibName: "GamePlayViewController", bundle: .module)
}
Expand All @@ -65,13 +65,17 @@ class GamePlayViewController: UIViewController {

override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
store.dispatch(GameAction.startTurn(player: store.state.startPlayer))
Task {
await store.dispatch(GameAction.startTurn(player: store.state.startPlayer))
}
}

// MARK: - IBAction

@IBAction private func closeButtonTapped(_ sender: Any) {
store.dispatch(SetupGameAction.quitGame)
Task {
await store.dispatch(SetupGameAction.quitGame)
}
}
}

Expand Down Expand Up @@ -131,7 +135,9 @@ private extension GamePlayViewController {
return
}

self.store.dispatch(GameAction.choose(option, player: player))
Task {
await self.store.dispatch(GameAction.choose(option, player: player))
}
}
}
}
Expand Down Expand Up @@ -297,7 +303,9 @@ extension GamePlayViewController: UICollectionViewDelegate {
return
}

store.dispatch(GameAction.play(item.card, player: player))
Task {
await store.dispatch(GameAction.play(item.card, player: player))
}
}
}

Expand Down
1 change: 1 addition & 0 deletions WildWestOnline/Utilities/Redux/Sources/Store.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public protocol Action: Sendable {}
/// Also return side-effects in response, and eventually dispatch more actions
public typealias Reducer<State, Dependencies> = (inout State, Action, Dependencies) throws -> Effect

/// ``Effect`` is an asynchronous `Action`
public enum Effect {
case none
case publisher(AnyPublisher<Action, Never>)
Expand Down

0 comments on commit 9f3fdc1

Please sign in to comment.