Added the "configuration" property constant to the FeedListCoordinator coordinator in the Feed framework to initialise the view model for the FeedListViewController view controller.
This commit is contained in:
parent
2cb6e95d17
commit
af6d4db807
@ -37,6 +37,7 @@ extension AppDelegate: UIApplicationDelegate {
|
||||
coordinator.present(animated: false)
|
||||
coordinator.present(
|
||||
child: FeedListCoordinator(
|
||||
configuration: .init(session: .ephemeral),
|
||||
router: StackRouter(coordinator.navigationController)
|
||||
),
|
||||
animated: false
|
||||
|
@ -10,22 +10,22 @@ import Foundation
|
||||
import ReviewsCoordinationKit
|
||||
|
||||
public final class FeedListCoordinator: Coordinator {
|
||||
|
||||
|
||||
// MARK: Constants
|
||||
public let router: any Router
|
||||
|
||||
private let sessionConfiguration: URLSessionConfiguration
|
||||
private let configuration: FeedListConfiguration
|
||||
|
||||
// MARK: Properties
|
||||
public var children: [any Coordinator] = []
|
||||
|
||||
// MARK: Initialisers
|
||||
public init(
|
||||
router: any Router,
|
||||
sessionConfiguration: URLSessionConfiguration = .ephemeral
|
||||
configuration: FeedListConfiguration,
|
||||
router: any Router
|
||||
) {
|
||||
self.configuration = configuration
|
||||
self.router = router
|
||||
self.sessionConfiguration = sessionConfiguration
|
||||
}
|
||||
|
||||
// MARK: Functions
|
||||
@ -34,9 +34,7 @@ public final class FeedListCoordinator: Coordinator {
|
||||
onDismiss: Router.OnDismissClosure? = nil
|
||||
) {
|
||||
router.present(
|
||||
FeedListViewController(configuration: .init(
|
||||
session: sessionConfiguration
|
||||
)),
|
||||
FeedListViewController(.init(configuration: configuration)),
|
||||
animated: animated,
|
||||
onDismiss: onDismiss
|
||||
)
|
||||
|
@ -13,11 +13,8 @@ import ReviewsiTunesKit
|
||||
extension FeedListViewController {
|
||||
final class ViewModel: ObservableObject {
|
||||
|
||||
// MARK: Type aliases
|
||||
typealias Configuration = FeedListViewController.Configuration
|
||||
|
||||
// MARK: Constants
|
||||
private let configuration: Configuration
|
||||
private let configuration: FeedListConfiguration
|
||||
|
||||
private let filterWords: FilterWordsUseCase = .init()
|
||||
private let topWords: TopWordsUseCase = .init()
|
||||
@ -40,7 +37,7 @@ extension FeedListViewController {
|
||||
}()
|
||||
|
||||
// MARK: Initialisers
|
||||
init(configuration: Configuration = .init()) {
|
||||
init(configuration: FeedListConfiguration = .init()) {
|
||||
self.configuration = configuration
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,7 @@ import ReviewsUIKit
|
||||
import SwiftUI
|
||||
import UIKit
|
||||
|
||||
public class FeedListViewController: UITableViewController {
|
||||
class FeedListViewController: UITableViewController {
|
||||
|
||||
// MARK: Constants
|
||||
private let viewModel: ViewModel
|
||||
@ -79,8 +79,8 @@ public class FeedListViewController: UITableViewController {
|
||||
}()
|
||||
|
||||
// MARK: Initialisers
|
||||
public init(configuration: Configuration = .init()) {
|
||||
self.viewModel = .init(configuration: configuration)
|
||||
init(_ viewModel: ViewModel) {
|
||||
self.viewModel = viewModel
|
||||
|
||||
super.init(style: .plain)
|
||||
}
|
||||
@ -95,7 +95,7 @@ public class FeedListViewController: UITableViewController {
|
||||
}
|
||||
|
||||
// MARK: UIViewController
|
||||
public override func viewDidLoad() {
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
||||
setNavigationBar()
|
||||
@ -108,14 +108,14 @@ public class FeedListViewController: UITableViewController {
|
||||
}
|
||||
|
||||
// MARK: UITableViewDataSource
|
||||
public override func tableView(
|
||||
override func tableView(
|
||||
_ tableView: UITableView,
|
||||
numberOfRowsInSection section: Int
|
||||
) -> Int {
|
||||
viewModel.itemsCount
|
||||
}
|
||||
|
||||
public override func tableView(
|
||||
override func tableView(
|
||||
_ tableView: UITableView,
|
||||
cellForRowAt indexPath: IndexPath
|
||||
) -> UITableViewCell {
|
||||
@ -127,7 +127,7 @@ public class FeedListViewController: UITableViewController {
|
||||
}
|
||||
|
||||
// MARK: UITableViewDelegate
|
||||
public override func tableView(
|
||||
override func tableView(
|
||||
_ tableView: UITableView,
|
||||
didSelectRowAt indexPath: IndexPath
|
||||
) {
|
||||
@ -340,9 +340,9 @@ import ReviewsiTunesKit
|
||||
#Preview("Feed List loading reviews") {
|
||||
MockURLProtocol.response = .init(statusCode: 200)
|
||||
|
||||
return UINavigationController(
|
||||
rootViewController: FeedListViewController(configuration: .init(session: .mock))
|
||||
)
|
||||
return UINavigationController(rootViewController: FeedListViewController(.init(
|
||||
configuration: .init(session: .mock)
|
||||
)))
|
||||
}
|
||||
|
||||
@available(iOS 17.0, *)
|
||||
@ -398,9 +398,9 @@ import ReviewsiTunesKit
|
||||
])
|
||||
)
|
||||
|
||||
return UINavigationController(
|
||||
rootViewController: FeedListViewController(configuration: .init(session: .mock))
|
||||
)
|
||||
return UINavigationController(rootViewController: FeedListViewController(.init(
|
||||
configuration: .init(session: .mock)
|
||||
)))
|
||||
}
|
||||
|
||||
@available(iOS 17.0, *)
|
||||
@ -410,13 +410,13 @@ import ReviewsiTunesKit
|
||||
object: Feed(entries: [])
|
||||
)
|
||||
|
||||
return UINavigationController(
|
||||
rootViewController: FeedListViewController(configuration: .init(session: .mock))
|
||||
)
|
||||
return UINavigationController(rootViewController: FeedListViewController(.init(
|
||||
configuration: .init(session: .mock)
|
||||
)))
|
||||
}
|
||||
|
||||
@available(iOS 17.0, *)
|
||||
#Preview("Feed List with live reviews") {
|
||||
UINavigationController(rootViewController: FeedListViewController())
|
||||
return UINavigationController(rootViewController: FeedListViewController(.init()))
|
||||
}
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user