added subscribers and renamed from cancellables
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
0076a1ea21
commit
cb3bb9250d
@ -18,8 +18,7 @@ open class Control<ModelType: Modelable>: UIControl, ModelHandlerPublishable, Vi
|
||||
@Published public var model: ModelType = ModelType()
|
||||
public var modelPublished: Published<ModelType> { _model }
|
||||
public var modelPublisher: Published<ModelType>.Publisher { $model }
|
||||
|
||||
public var cancellables = Set<AnyCancellable>()
|
||||
public var subscribers = Set<AnyCancellable>()
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Properties
|
||||
@ -71,7 +70,7 @@ open class Control<ModelType: Modelable>: UIControl, ModelHandlerPublishable, Vi
|
||||
guard let self = self else { return }
|
||||
self.updateView(viewModel: viewModel)
|
||||
|
||||
}.store(in: &cancellables)
|
||||
}.store(in: &subscribers)
|
||||
setup()
|
||||
}
|
||||
}
|
||||
|
||||
@ -18,7 +18,7 @@ open class View<ModelType: Modelable>: UIView, ModelHandlerPublishable, ViewProt
|
||||
@Published public var model: ModelType = ModelType()
|
||||
public var modelPublished: Published<ModelType> { _model }
|
||||
public var modelPublisher: Published<ModelType>.Publisher { $model }
|
||||
public var cancellables = Set<AnyCancellable>()
|
||||
public var subscribers = Set<AnyCancellable>()
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Properties
|
||||
@ -70,7 +70,7 @@ open class View<ModelType: Modelable>: UIView, ModelHandlerPublishable, ViewProt
|
||||
guard let self = self else { return }
|
||||
self.updateView(viewModel: viewModel)
|
||||
|
||||
}.store(in: &cancellables)
|
||||
}.store(in: &subscribers)
|
||||
setup()
|
||||
}
|
||||
}
|
||||
|
||||
@ -20,7 +20,7 @@ open class LabelBase<ModelType: LabelModel>: UILabel, ModelHandlerPublishable, V
|
||||
@Published public var model: ModelType = ModelType()
|
||||
public var modelPublished: Published<ModelType> { _model }
|
||||
public var modelPublisher: Published<ModelType>.Publisher { $model }
|
||||
public var cancellables = Set<AnyCancellable>()
|
||||
public var subscribers = Set<AnyCancellable>()
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Properties
|
||||
@ -104,7 +104,7 @@ open class LabelBase<ModelType: LabelModel>: UILabel, ModelHandlerPublishable, V
|
||||
guard let self = self else { return }
|
||||
self.updateView(viewModel: viewModel)
|
||||
|
||||
}.store(in: &cancellables)
|
||||
}.store(in: &subscribers)
|
||||
|
||||
setup()
|
||||
}
|
||||
|
||||
@ -93,14 +93,14 @@ open class SelectorGroupBase<SelectorType, SelectorGroupType: SelectorGroupModel
|
||||
newSelectorView.selectedPublisher().sink { [weak self] model in
|
||||
guard self?.model.selectors.count ?? 0 > 0 else { return }
|
||||
self?.didSelect(selected: model)
|
||||
}.store(in: &cancellables)
|
||||
}.store(in: &subscribers)
|
||||
|
||||
//add model update to the subscribers
|
||||
newSelectorView.$model.debounce(for: .seconds(Constants.ModelStateDebounce), scheduler: RunLoop.main).sink { [weak self] model in
|
||||
if let cached = self?.getCachedSelector(viewModel: model), newSelectorView.shouldUpdateView(viewModel: cached) {
|
||||
self?.replace(viewModel: model)
|
||||
}
|
||||
}.store(in: &cancellables)
|
||||
}.store(in: &subscribers)
|
||||
|
||||
self.selectorViews.append(newSelectorView)
|
||||
mainStackView.addArrangedSubview(newSelectorView)
|
||||
|
||||
@ -6,7 +6,8 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
import Combine
|
||||
|
||||
public protocol ModelHandlerable: AnyObject {
|
||||
associatedtype ModelType: Modelable
|
||||
var model: ModelType { get set }
|
||||
@ -30,4 +31,5 @@ extension ModelHandlerable {
|
||||
public protocol ModelHandlerPublishable: ModelHandlerable {
|
||||
var modelPublished: Published<ModelType> { get }
|
||||
var modelPublisher: Published<ModelType>.Publisher { get }
|
||||
var subscribers: Set<AnyCancellable> { get set }
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user