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