vds_ios/VDS/Protocols/ModelHandlerable.swift
Matt Bruce 552e0416d3 refactored out ModelHandlerPublishable and moved into the handler
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
2022-08-12 15:27:50 -05:00

33 lines
788 B
Swift

//
// Modelable.swift
// VDS
//
// Created by Matt Bruce on 7/22/22.
//
import Foundation
import Combine
public protocol ModelHandlerable: AnyObject {
associatedtype ModelType: Modelable
var model: ModelType { get set }
var modelPublished: Published<ModelType> { get }
var modelPublisher: Published<ModelType>.Publisher { get }
var subscribers: Set<AnyCancellable> { get set }
init(with model: ModelType)
func set(with model: ModelType)
func shouldUpdateView(viewModel: ModelType) -> Bool
func updateView(viewModel: ModelType)
}
extension ModelHandlerable {
public func set(with model: ModelType) {
if shouldUpdateView(viewModel: model){
updateView(viewModel: model)
self.model = model
}
}
}