45 lines
1.3 KiB
Swift
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
|
|
}
|
|
}
|
|
}
|