From 7f6883c7b7e06fe98e11e3a674aa105ba9cdf4d7 Mon Sep 17 00:00:00 2001 From: Nikita Semenov Date: Thu, 4 Aug 2022 17:01:19 +0300 Subject: [PATCH] fix: view model configuration --- .../Protocols/FiltersCollectionHolder.swift | 3 -- ...swift => DefaultFilterCellViewModel.swift} | 0 .../ViewModels/DefaultFiltersViewModel.swift | 32 +++++------------ .../Views/BaseFiltersCollectionView.swift | 36 ++++++++----------- 4 files changed, 24 insertions(+), 47 deletions(-) rename TIEcommerce/Sources/Filters/ViewModels/{DefaultCellViewModel.swift => DefaultFilterCellViewModel.swift} (100%) diff --git a/TIEcommerce/Sources/Filters/Protocols/FiltersCollectionHolder.swift b/TIEcommerce/Sources/Filters/Protocols/FiltersCollectionHolder.swift index a1c7328b..020a4109 100644 --- a/TIEcommerce/Sources/Filters/Protocols/FiltersCollectionHolder.swift +++ b/TIEcommerce/Sources/Filters/Protocols/FiltersCollectionHolder.swift @@ -23,8 +23,5 @@ import UIKit public protocol FiltersCollectionHolder: AnyObject { - func applyChange(_ changes: [DefaultFiltersViewModel.Change]) func updateView() - func configure(filterCell: UICollectionViewCell, cellViewModel: FilterCellViewModelProtocol) - func registerCells() } diff --git a/TIEcommerce/Sources/Filters/ViewModels/DefaultCellViewModel.swift b/TIEcommerce/Sources/Filters/ViewModels/DefaultFilterCellViewModel.swift similarity index 100% rename from TIEcommerce/Sources/Filters/ViewModels/DefaultCellViewModel.swift rename to TIEcommerce/Sources/Filters/ViewModels/DefaultFilterCellViewModel.swift diff --git a/TIEcommerce/Sources/Filters/ViewModels/DefaultFiltersViewModel.swift b/TIEcommerce/Sources/Filters/ViewModels/DefaultFiltersViewModel.swift index 5e67a16c..823900c8 100644 --- a/TIEcommerce/Sources/Filters/ViewModels/DefaultFiltersViewModel.swift +++ b/TIEcommerce/Sources/Filters/ViewModels/DefaultFiltersViewModel.swift @@ -24,8 +24,7 @@ import UIKit open class DefaultFiltersViewModel: NSObject, FiltersViewModelProtocol, - UICollectionViewDelegate, - UICollectionViewDataSource { + UICollectionViewDelegate { public typealias Change = (indexPath: IndexPath, viewModel: FilterCellViewModelProtocol) @@ -40,21 +39,6 @@ open class DefaultFiltersViewModel: NSObject, self.cellsViewModels = filters.compactMap { $0.convertToViewModel() as? FilterCellViewModelProtocol } } - // MARK: - UICollectionViewDataSource - - open func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { - filtersCollectionHolder?.registerCells() - return cellsViewModels.count - } - - open func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - let viewModel = cellsViewModels[indexPath.item] - let cell = collectionView.dequeueReusableCell(withReuseIdentifier: viewModel.id, for: indexPath) - filtersCollectionHolder?.configure(filterCell: cell, cellViewModel: viewModel) - - return cell - } - // MARK: - UICollectionViewDelegate open func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { @@ -70,13 +54,15 @@ open class DefaultFiltersViewModel: NSObject, filters[offset].isSelected = selectedFilters.contains(element) } - let changedItems = changedFilters - .map { - Change(indexPath: IndexPath(item: $0.offset, section: .zero), - viewModel: cellsViewModels[$0.offset]) - } + filtersCollectionHolder?.updateView() - filtersCollectionHolder?.applyChange(changedItems) + // let changedItems = changedFilters + // .map { + // Change(indexPath: IndexPath(item: $0.offset, section: .zero), + // viewModel: cellsViewModels[$0.offset]) + // } + + // filtersCollectionHolder?.applyChange(changedItems) } // MARK: - Private methods diff --git a/TIEcommerce/Sources/Filters/Views/BaseFiltersCollectionView.swift b/TIEcommerce/Sources/Filters/Views/BaseFiltersCollectionView.swift index 8b1aab2b..2607a6a3 100644 --- a/TIEcommerce/Sources/Filters/Views/BaseFiltersCollectionView.swift +++ b/TIEcommerce/Sources/Filters/Views/BaseFiltersCollectionView.swift @@ -54,7 +54,6 @@ open class BaseFiltersCollectionView