vds_ios/VDS/Protocols/SelectorGroupHandlerable.swift
Matt Bruce 921e13b3cf refactored into protocols
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
2022-08-23 14:55:15 -05:00

45 lines
1.3 KiB
Swift

//
// SelectorGroupHandlerable.swift
// VDS
//
// Created by Matt Bruce on 8/23/22.
//
import Foundation
public protocol SelectorGroupHandlerable: ModelHandlerable, Disabling, Surfaceable where ModelType: SelectorGroupModelable {
associatedtype ModelHandlerType: ModelHandlerable where ModelType.SelectorModelType == ModelHandlerType.ModelType
var selectorViews: [ModelHandlerType] { get set }
}
extension SelectorGroupHandlerable {
public func updateSelectors(){
let selectors = model.selectors.compactMap { existing in
return existing.copyWith {
$0.disabled = disabled
$0.surface = surface
}
}
model.selectors = selectors
}
public func getCachedSelector(viewModel: ModelHandlerType.ModelType) -> ModelHandlerType.ModelType? {
if let index = model.selectors.firstIndex(where: { element in
return element.id == viewModel.id
}) {
return model.selectors[index]
} else {
return nil
}
}
public func replace(viewModel: ModelHandlerType.ModelType){
if let index = model.selectors.firstIndex(where: { element in
return element.id == viewModel.id
}) {
model.selectors[index] = viewModel
}
}
}