refactored to all having didSelect
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
56a72f62a2
commit
96522d37da
@ -12,6 +12,7 @@ import UIKit
|
|||||||
public protocol SelectorGroupModelHandlerable: ModelHandlerable, Disabling, Surfaceable where ModelType: SelectorGroupModelable {
|
public protocol SelectorGroupModelHandlerable: ModelHandlerable, Disabling, Surfaceable where ModelType: SelectorGroupModelable {
|
||||||
associatedtype ModelHandlerType: ModelHandlerable where ModelType.SelectorModelType == ModelHandlerType.ModelType, ModelHandlerType: UIControl
|
associatedtype ModelHandlerType: ModelHandlerable where ModelType.SelectorModelType == ModelHandlerType.ModelType, ModelHandlerType: UIControl
|
||||||
var selectorViews: [ModelHandlerType] { get set }
|
var selectorViews: [ModelHandlerType] { get set }
|
||||||
|
func didSelect(_ selectedControl: ModelHandlerType)
|
||||||
func createModelHandler(selector: ModelHandlerType.ModelType) -> 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(){
|
public func updateSelectors(){
|
||||||
let selectors = model.selectors.compactMap { existing in
|
let selectors = model.selectors.compactMap { existing in
|
||||||
return existing.copyWith {
|
return existing.copyWith {
|
||||||
@ -66,18 +51,6 @@ extension SelectorGroupModelHandlerable {
|
|||||||
model.selectors[index] = viewModel
|
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 {
|
public func createModelHandler(selector: ModelHandlerType.ModelType) -> ModelHandlerType {
|
||||||
//create view
|
//create view
|
||||||
@ -103,4 +76,15 @@ extension SelectorGroupSelectedModelHandlerable {
|
|||||||
return newSelectorView
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user