update to add subscribers
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
ee4bea37ca
commit
e6c55ef588
@ -100,18 +100,38 @@ open class SelectorGroup<SelectorType, SelectorGroupType: SelectorGroupModel<Sel
|
||||
if let inputId = selectorModel.inputId, let foundSelectorView = findSelectorView(inputId: inputId) {
|
||||
foundSelectorView.set(with: selectorModel)
|
||||
} else {
|
||||
|
||||
//create view
|
||||
let newSelectorView = SelectorHandlerType(with: selectorModel)
|
||||
newSelectorView.didSelect = {[weak self] (inputId) in
|
||||
guard let self else { return }
|
||||
self.didSelect(selected: selectorModel)
|
||||
}
|
||||
|
||||
//add the selectedPublisher for the change
|
||||
newSelectorView.selectedPublisher().sink { [weak self] model in
|
||||
self?.didSelect(selected: model)
|
||||
}.store(in: &cancellables)
|
||||
|
||||
newSelectorView.$model.sink { [weak self] model in
|
||||
//should replace
|
||||
if let cached = self?.getCachedSelector(viewModel: model), newSelectorView.shouldUpdateView(viewModel: cached) {
|
||||
self?.replace(viewModel: model)
|
||||
}
|
||||
}.store(in: &cancellables)
|
||||
|
||||
self.selectorViews.append(newSelectorView)
|
||||
mainStackView.addArrangedSubview(newSelectorView)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public func getCachedSelector(viewModel: SelectorType) -> SelectorType? {
|
||||
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: SelectorType){
|
||||
if let index = model.selectors.firstIndex(where: { element in
|
||||
|
||||
Loading…
Reference in New Issue
Block a user