From 96522d37da3129bc76f6824f4edb78e1fbea6286 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Thu, 8 Sep 2022 16:19:32 -0500 Subject: [PATCH] refactored to all having didSelect Signed-off-by: Matt Bruce --- .../SelectorGroupModelHandlerable.swift | 40 ++++++------------- 1 file changed, 12 insertions(+), 28 deletions(-) diff --git a/VDS/Protocols/SelectorGroupModelHandlerable.swift b/VDS/Protocols/SelectorGroupModelHandlerable.swift index d9aa96d7..447333f4 100644 --- a/VDS/Protocols/SelectorGroupModelHandlerable.swift +++ b/VDS/Protocols/SelectorGroupModelHandlerable.swift @@ -12,6 +12,7 @@ import UIKit public protocol SelectorGroupModelHandlerable: ModelHandlerable, Disabling, Surfaceable where ModelType: SelectorGroupModelable { associatedtype ModelHandlerType: ModelHandlerable where ModelType.SelectorModelType == ModelHandlerType.ModelType, ModelHandlerType: UIControl var selectorViews: [ModelHandlerType] { get set } + func didSelect(_ selectedControl: ModelHandlerType) func createModelHandler(selector: ModelHandlerType.ModelType) -> ModelHandlerType } @@ -23,22 +24,6 @@ extension SelectorGroupModelHandlerable { }) } - public func createModelHandler(selector: ModelHandlerType.ModelType) -> ModelHandlerType { - //create view - let newSelectorView = ModelHandlerType(with: selector) - - //add model update to the subscribers - newSelectorView.handlerPublisher() - .sink { [weak self] model in - if let cached = self?.getCachedSelector(viewModel: model), newSelectorView.shouldUpdateView(viewModel: cached) { - self?.replace(viewModel: model) - } - } - .store(in: &subscribers) - - return newSelectorView - } - public func updateSelectors(){ let selectors = model.selectors.compactMap { existing in return existing.copyWith { @@ -66,18 +51,6 @@ extension SelectorGroupModelHandlerable { model.selectors[index] = viewModel } } -} - -///MARK: Groups that allow single selections -public protocol SelectorGroupSelectedModelHandlerable: SelectorGroupModelHandlerable where ModelType: SelectorGroupSelectedModelable { - func didSelect(_ selectedControl: ModelHandlerType) -} - -extension SelectorGroupSelectedModelHandlerable { - - public var selectedModel: ModelHandlerType.ModelType? { - return model.selectedModel - } public func createModelHandler(selector: ModelHandlerType.ModelType) -> ModelHandlerType { //create view @@ -103,4 +76,15 @@ extension SelectorGroupSelectedModelHandlerable { return newSelectorView } + +} + +///MARK: Groups that allow single selections +public protocol SelectorGroupSelectedModelHandlerable: SelectorGroupModelHandlerable where ModelType: SelectorGroupSelectedModelable { } + +extension SelectorGroupSelectedModelHandlerable { + + public var selectedModel: ModelHandlerType.ModelType? { + return model.selectedModel + } }