Improved the naming of some properties and functions in the LocationsAddCoordination, LocationsListCoordination, and LocationsListViewModeling protocols.

This commit is contained in:
Javier Cicchelli 2023-04-13 00:38:43 +02:00
parent a241767c86
commit dc7dbfb61a
8 changed files with 27 additions and 24 deletions

View File

@ -42,7 +42,7 @@ extension LocationsAddCoordinator: LocationsAddCoordination {
// MARK: Functions // MARK: Functions
func closeAddLocation() { func closeLocationsAddScreen() {
router.dismiss(animated: true) router.dismiss(animated: true)
} }

View File

@ -48,7 +48,7 @@ extension LocationsListCoordinator: LocationsListCoordination {
// MARK: Functions // MARK: Functions
func openAddLocation() { func openLocationsAddScreen() {
guard let viewController else { guard let viewController else {
return return
} }

View File

@ -10,6 +10,6 @@ protocol LocationsAddCoordination: AnyObject {
// MARK: Functions // MARK: Functions
func closeAddLocation() func closeLocationsAddScreen()
} }

View File

@ -10,6 +10,6 @@ protocol LocationsListCoordination: AnyObject {
// MARK: Functions // MARK: Functions
func openAddLocation() func openLocationsAddScreen()
} }

View File

@ -17,14 +17,14 @@ protocol LocationsListViewModeling: AnyObject {
var coordinator: LocationsListCoordination? { get set } var coordinator: LocationsListCoordination? { get set }
var locationsDidChangePublisher: PassthroughSubject<[Change], Never> { get } var locationsDidChangePublisher: PassthroughSubject<[Change], Never> { get }
var numberOfLocationSections: Int { get }
var viewStatusPublisher: Published<LocationsListViewStatus>.Publisher { get } var viewStatusPublisher: Published<LocationsListViewStatus>.Publisher { get }
var numberOfSectionsInData: Int { get }
// MARK: Functions // MARK: Functions
func openAddLocation()
func loadLocations() func loadLocations()
func numberOfDataItems(in section: Int) -> Int func location(at indexPath: IndexPath) -> Location
func dataItem(at indexPath: IndexPath) -> Location func numberOfLocations(in section: Int) -> Int
func openLocationsAdd()
} }

View File

@ -54,7 +54,7 @@ extension LocationsAddViewModel: LocationsAddViewModeling {
longitude: location.longitude longitude: location.longitude
) )
coordinator?.closeAddLocation() coordinator?.closeLocationsAddScreen()
} }
func setLocation(latitude: Float, longitude: Float) { func setLocation(latitude: Float, longitude: Float) {

View File

@ -67,14 +67,14 @@ extension LocationsListViewController: UITableViewDataSource {
// MARK: Functions // MARK: Functions
func numberOfSections(in tableView: UITableView) -> Int { func numberOfSections(in tableView: UITableView) -> Int {
viewModel.numberOfSectionsInData viewModel.numberOfLocationSections
} }
func tableView( func tableView(
_ tableView: UITableView, _ tableView: UITableView,
numberOfRowsInSection section: Int numberOfRowsInSection section: Int
) -> Int { ) -> Int {
viewModel.numberOfDataItems(in: section) viewModel.numberOfLocations(in: section)
} }
func tableView( func tableView(
@ -88,7 +88,7 @@ extension LocationsListViewController: UITableViewDataSource {
return .init() return .init()
} }
let entity = viewModel.dataItem(at: indexPath) let entity = viewModel.location(at: indexPath)
cell.update( cell.update(
iconName: entity.source == .remote ? "network" : "house", iconName: entity.source == .remote ? "network" : "house",
@ -163,7 +163,7 @@ private extension LocationsListViewController {
.store(in: &cancellables) .store(in: &cancellables)
viewModel viewModel
.controllerDidChangePublisher .locationsDidChangePublisher
.sink(receiveValue: { [weak self] updates in .sink(receiveValue: { [weak self] updates in
var movedToIndexPaths = [IndexPath]() var movedToIndexPaths = [IndexPath]()
@ -199,7 +199,7 @@ private extension LocationsListViewController {
} }
@objc func addLocationPressed() { @objc func addLocationPressed() {
viewModel.openAddLocation() viewModel.openLocationsAdd()
} }
} }

View File

@ -42,15 +42,11 @@ extension LocationsListViewModel: LocationsListViewModeling {
// MARK: Properties // MARK: Properties
var locationsDidChangePublisher: PassthroughSubject<[Persistence.Change], Never> { locationProvider.didChangePublisher } var locationsDidChangePublisher: PassthroughSubject<[Persistence.Change], Never> { locationProvider.didChangePublisher }
var numberOfSectionsInData: Int { locationProvider.numberOfSections } var numberOfLocationSections: Int { locationProvider.numberOfSections }
var viewStatusPublisher: Published<LocationsListViewStatus>.Publisher { $viewStatus } var viewStatusPublisher: Published<LocationsListViewStatus>.Publisher { $viewStatus }
// MARK: Functions // MARK: Functions
func openAddLocation() {
coordinator?.openAddLocation()
}
func loadLocations() { func loadLocations() {
Task { Task {
do { do {
@ -67,12 +63,19 @@ extension LocationsListViewModel: LocationsListViewModeling {
} }
} }
func numberOfDataItems(in section: Int) -> Int {
func location(at indexPath: IndexPath) -> Location {
locationProvider.location(at: indexPath)
}
func numberOfLocations(in section: Int) -> Int {
locationProvider.numberOfLocationsInSection(section) locationProvider.numberOfLocationsInSection(section)
} }
func dataItem(at indexPath: IndexPath) -> Location { func openLocationsAdd() {
locationProvider.location(at: indexPath) coordinator?.openLocationsAddScreen()
}
} }
} }