vds_ios/VDS/Protocols/ModelHandlerable.swift
Matt Bruce cb3bb9250d added subscribers and renamed from cancellables
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
2022-08-11 14:16:58 -05:00

36 lines
851 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 }
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
}
}
}
public protocol ModelHandlerPublishable: ModelHandlerable {
var modelPublished: Published<ModelType> { get }
var modelPublisher: Published<ModelType>.Publisher { get }
var subscribers: Set<AnyCancellable> { get set }
}