The Composable Architecture

Co-authored-by: Stephen Celis <stephen.celis@gmail.com>
This commit is contained in:
Brandon Williams
2020-05-03 16:19:55 -07:00
commit d2240d0e76
243 changed files with 28515 additions and 0 deletions

View File

@@ -0,0 +1,52 @@
import AppCore
import Combine
import ComposableArchitecture
import SwiftUI
import UIKit
struct UIKitAppView: UIViewControllerRepresentable {
let store: Store<AppState, AppAction>
func makeUIViewController(context: Context) -> AppViewController {
AppViewController(store: store)
}
func updateUIViewController(
_ uiViewController: AppViewController,
context: Context
) {
// Nothing to do
}
}
class AppViewController: UINavigationController {
let store: Store<AppState, AppAction>
private var cancellables: Set<AnyCancellable> = []
init(store: Store<AppState, AppAction>) {
self.store = store
super.init(nibName: nil, bundle: nil)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func viewDidLoad() {
super.viewDidLoad()
self.store
.scope(state: \.login, action: AppAction.login)
.ifLet { [weak self] loginStore in
self?.setViewControllers([LoginViewController(store: loginStore)], animated: false)
}
.store(in: &self.cancellables)
self.store
.scope(state: \.newGame, action: AppAction.newGame)
.ifLet { [weak self] newGameStore in
self?.setViewControllers([NewGameViewController(store: newGameStore)], animated: false)
}
.store(in: &self.cancellables)
}
}