refactored radio button group more
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
8e4d4d6ded
commit
8824ea95bc
@ -11,9 +11,9 @@ public class RadioButtonGroup: RadioButtonGroupBase<DefaultRadioButtonGroupModel
|
|||||||
|
|
||||||
public class RadioButtonGroupBase<RadioButtonGroupModelType: SelectorGroupModel, RadioButtonType: RadioButtonBase<RadioButtonGroupModelType.SelectorType>>: SelectorGroupBase<RadioButtonGroupModelType.SelectorType, RadioButtonGroupModelType, RadioButtonType> {
|
public class RadioButtonGroupBase<RadioButtonGroupModelType: SelectorGroupModel, RadioButtonType: RadioButtonBase<RadioButtonGroupModelType.SelectorType>>: SelectorGroupBase<RadioButtonGroupModelType.SelectorType, RadioButtonGroupModelType, RadioButtonType> {
|
||||||
|
|
||||||
public override func didSelect(selected: RadioButtonGroupModelType.SelectorType) {
|
public override func didSelect(selected: RadioButtonGroupModelType.SelectorType) {
|
||||||
for selectorModel in model.selectors {
|
for selectorModel in model.selectors {
|
||||||
print("Pre Cached Selector: \(selectorModel.inputId): \(selectorModel.selected)")
|
print("Pre Cached Selector: \(selectorModel.id): \(selectorModel.selected)")
|
||||||
}
|
}
|
||||||
|
|
||||||
if var oldSelectedModel = selectedModel {
|
if var oldSelectedModel = selectedModel {
|
||||||
@ -26,9 +26,9 @@ public class RadioButtonGroupBase<RadioButtonGroupModelType: SelectorGroupModel,
|
|||||||
replace(viewModel: newSelectedModel)
|
replace(viewModel: newSelectedModel)
|
||||||
|
|
||||||
selectedModel = newSelectedModel
|
selectedModel = newSelectedModel
|
||||||
|
|
||||||
for selectorModel in model.selectors {
|
for selectorModel in model.selectors {
|
||||||
print("Post Cached Selector: \(selectorModel.inputId): \(selectorModel.selected)")
|
print("Post Cached Selector: \(selectorModel.id): \(selectorModel.selected)")
|
||||||
}
|
}
|
||||||
|
|
||||||
print("\n")
|
print("\n")
|
||||||
|
|||||||
@ -14,6 +14,7 @@ public struct DefaultRadioButtonGroupModel: SelectorGroupModel{
|
|||||||
public var value: AnyHashable?
|
public var value: AnyHashable?
|
||||||
public var surface: Surface = .light
|
public var surface: Surface = .light
|
||||||
public var disabled: Bool = false
|
public var disabled: Bool = false
|
||||||
|
public var selectedModel: DefaultRadioButtonModel?
|
||||||
public var selectors: [SelectorType]
|
public var selectors: [SelectorType]
|
||||||
public init() { selectors = [] }
|
public init() { selectors = [] }
|
||||||
public init(selectors: [SelectorType]){
|
public init(selectors: [SelectorType]){
|
||||||
|
|||||||
@ -12,7 +12,10 @@ import Combine
|
|||||||
open class SelectorGroupBase<SelectorType, SelectorGroupType: SelectorGroupModel, SelectorHandlerType: SelectorBase<SelectorType>>: View<SelectorGroupType>, Changable where SelectorType == SelectorGroupType.SelectorType {
|
open class SelectorGroupBase<SelectorType, SelectorGroupType: SelectorGroupModel, SelectorHandlerType: SelectorBase<SelectorType>>: View<SelectorGroupType>, Changable where SelectorType == SelectorGroupType.SelectorType {
|
||||||
|
|
||||||
public var selectorViews: [SelectorHandlerType] = []
|
public var selectorViews: [SelectorHandlerType] = []
|
||||||
|
|
||||||
|
@Proxy(\.model.selectedModel)
|
||||||
public var selectedModel: SelectorType?
|
public var selectedModel: SelectorType?
|
||||||
|
|
||||||
public var onChange: Blocks.ActionBlock?
|
public var onChange: Blocks.ActionBlock?
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -88,11 +91,12 @@ open class SelectorGroupBase<SelectorType, SelectorGroupType: SelectorGroupModel
|
|||||||
|
|
||||||
//add the selectedPublisher for the change
|
//add the selectedPublisher for the change
|
||||||
newSelectorView.selectedPublisher().sink { [weak self] model in
|
newSelectorView.selectedPublisher().sink { [weak self] model in
|
||||||
|
guard self?.model.selectors.count ?? 0 > 0 else { return }
|
||||||
self?.didSelect(selected: model)
|
self?.didSelect(selected: model)
|
||||||
}.store(in: &cancellables)
|
}.store(in: &cancellables)
|
||||||
|
|
||||||
//add model update to the subscribers
|
//add model update to the subscribers
|
||||||
newSelectorView.$model.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)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,6 +9,7 @@ import Foundation
|
|||||||
|
|
||||||
public protocol SelectorGroupModel<SelectorType>: Modelable, FormFieldable {
|
public protocol SelectorGroupModel<SelectorType>: Modelable, FormFieldable {
|
||||||
associatedtype SelectorType: SelectorModel
|
associatedtype SelectorType: SelectorModel
|
||||||
|
var selectedModel: SelectorType? { get set }
|
||||||
var selectors: [SelectorType] { get set }
|
var selectors: [SelectorType] { get set }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -18,6 +19,7 @@ public struct DefaultSelectorGroupModel<SelectorType: SelectorModel>: SelectorGr
|
|||||||
public var value: AnyHashable?
|
public var value: AnyHashable?
|
||||||
public var surface: Surface = .light
|
public var surface: Surface = .light
|
||||||
public var disabled: Bool = false
|
public var disabled: Bool = false
|
||||||
|
public var selectedModel: SelectorType?
|
||||||
public var selectors: [SelectorType]
|
public var selectors: [SelectorType]
|
||||||
public init() { selectors = [] }
|
public init() { selectors = [] }
|
||||||
public init(selectors: [SelectorType]){
|
public init(selectors: [SelectorType]){
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user