From 9f3fdc1ae74d49e03d71630eb6e556d68a5fdc55 Mon Sep 17 00:00:00 2001 From: Stephano Telolahy Date: Sun, 19 Jan 2025 00:03:56 +0100 Subject: [PATCH] wip --- WildWestOnline/UI/Game/Sources/GameView.swift | 6 +++--- .../UI/Game/Sources/GameViewBuilder.swift | 2 +- .../UIKit/GamePlayViewController.swift | 20 +++++++++++++------ .../Utilities/Redux/Sources/Store.swift | 1 + 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/WildWestOnline/UI/Game/Sources/GameView.swift b/WildWestOnline/UI/Game/Sources/GameView.swift index a8e78c666..a3b07883f 100644 --- a/WildWestOnline/UI/Game/Sources/GameView.swift +++ b/WildWestOnline/UI/Game/Sources/GameView.swift @@ -50,9 +50,9 @@ struct GameView: View { } @Environment(\.theme) private var theme - @StateObject private var store: Store + @StateObject private var store: Store - init(store: @escaping () -> Store) { + init(store: @escaping () -> Store) { // SwiftUI ensures that the following initialization uses the // closure only once during the lifetime of the view. _store = StateObject(wrappedValue: store()) @@ -72,7 +72,7 @@ struct GameView: View { #Preview { GameView { - .init(initial: .mockedData) + .init(initialState: .mockedData, dependencies: ()) } } diff --git a/WildWestOnline/UI/Game/Sources/GameViewBuilder.swift b/WildWestOnline/UI/Game/Sources/GameViewBuilder.swift index 11dfbdfd3..c1c60afdb 100644 --- a/WildWestOnline/UI/Game/Sources/GameViewBuilder.swift +++ b/WildWestOnline/UI/Game/Sources/GameViewBuilder.swift @@ -11,7 +11,7 @@ import AppCore import GameCore public struct GameViewBuilder: View { - @EnvironmentObject private var store: Store + @EnvironmentObject private var store: Store public init() {} diff --git a/WildWestOnline/UI/Game/Sources/UIKit/GamePlayViewController.swift b/WildWestOnline/UI/Game/Sources/UIKit/GamePlayViewController.swift index c18015fb9..1468591f6 100644 --- a/WildWestOnline/UI/Game/Sources/UIKit/GamePlayViewController.swift +++ b/WildWestOnline/UI/Game/Sources/UIKit/GamePlayViewController.swift @@ -22,7 +22,7 @@ class GamePlayViewController: UIViewController { // MARK: - Data - private var store: Store + private var store: Store private var subscriptions: Set = [] private var events: [String] = [] @@ -45,7 +45,7 @@ class GamePlayViewController: UIViewController { // MARK: - Init - init(store: Store) { + init(store: Store) { self.store = store super.init(nibName: "GamePlayViewController", bundle: .module) } @@ -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) + } } } @@ -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)) + } } } } @@ -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)) + } } } diff --git a/WildWestOnline/Utilities/Redux/Sources/Store.swift b/WildWestOnline/Utilities/Redux/Sources/Store.swift index b7408f809..68d59d7bd 100644 --- a/WildWestOnline/Utilities/Redux/Sources/Store.swift +++ b/WildWestOnline/Utilities/Redux/Sources/Store.swift @@ -15,6 +15,7 @@ public protocol Action: Sendable {} /// Also return side-effects in response, and eventually dispatch more actions public typealias Reducer = (inout State, Action, Dependencies) throws -> Effect +/// ``Effect`` is an asynchronous `Action` public enum Effect { case none case publisher(AnyPublisher)