refactored code for debounce
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
f5c7d73bad
commit
641ae4d572
@ -19,46 +19,51 @@ open class DefaultLabelModel: VDSLabelModel {
|
||||
required public init(){}
|
||||
}
|
||||
|
||||
open class VDSLabel: UILabel, Modelable, ObservableObject {
|
||||
open class VDSLabel: UILabel, Modelable {
|
||||
@Published public var model: VDSLabelModel = DefaultLabelModel()
|
||||
private var cancellable: AnyCancellable?
|
||||
|
||||
public var fontSize: VDSFontSize = .large {
|
||||
didSet {
|
||||
if fontSize != model.fontSize {
|
||||
model.fontSize = fontSize
|
||||
public var fontSize: VDSFontSize {
|
||||
get { model.fontSize }
|
||||
set {
|
||||
if model.fontSize != newValue {
|
||||
model.fontSize = newValue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public var textPosition: VDSTextPosition = .left{
|
||||
didSet {
|
||||
if textPosition != model.textPosition {
|
||||
model.textPosition = textPosition
|
||||
public var textPosition: VDSTextPosition {
|
||||
get { model.textPosition }
|
||||
set {
|
||||
if model.textPosition != newValue {
|
||||
model.textPosition = newValue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public var fontWeight: VDSFontWeight = .regular {
|
||||
didSet {
|
||||
if fontWeight != model.fontWeight {
|
||||
model.fontWeight = fontWeight
|
||||
public var fontWeight: VDSFontWeight {
|
||||
get { model.fontWeight }
|
||||
set {
|
||||
if model.fontWeight != newValue {
|
||||
model.fontWeight = newValue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public var fontCategory: VDSFontCategory = .body {
|
||||
didSet {
|
||||
if fontCategory != model.fontCategory {
|
||||
model.fontCategory = fontCategory
|
||||
public var fontCategory: VDSFontCategory {
|
||||
get { model.fontCategory }
|
||||
set {
|
||||
if model.fontCategory != newValue {
|
||||
model.fontCategory = newValue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public var surface: Surface = .light {
|
||||
didSet {
|
||||
if surface != model.surface {
|
||||
model.surface = surface
|
||||
public var surface: Surface {
|
||||
get { model.surface }
|
||||
set {
|
||||
if model.surface != newValue {
|
||||
model.surface = newValue
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -79,7 +84,7 @@ open class VDSLabel: UILabel, Modelable, ObservableObject {
|
||||
}
|
||||
|
||||
func setup() {
|
||||
cancellable = $model.sink { [weak self] viewModel in
|
||||
cancellable = $model.debounce(for: .seconds(ModelStateDebounce), scheduler: RunLoop.main).sink { [weak self] viewModel in
|
||||
self?.onStateChange(viewModel: viewModel)
|
||||
}
|
||||
}
|
||||
|
||||
@ -43,7 +43,7 @@ public class DefaultToggleModel: DefaultLabelModel, VDSToggleModel {
|
||||
}
|
||||
|
||||
@objcMembers open class VDSToggle: VDSControl, Modelable, Changable {
|
||||
|
||||
|
||||
public typealias ModelType = VDSToggleModel
|
||||
@Published public var model: ModelType = DefaultToggleModel()
|
||||
private var cancellable: AnyCancellable?
|
||||
@ -228,7 +228,7 @@ public class DefaultToggleModel: DefaultLabelModel, VDSToggleModel {
|
||||
}
|
||||
|
||||
func setup() {
|
||||
cancellable = $model.sink { [weak self] viewModel in
|
||||
cancellable = $model.debounce(for: .seconds(ModelStateDebounce), scheduler: RunLoop.main).sink { [weak self] viewModel in
|
||||
self?.onStateChange(viewModel: viewModel)
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,6 +7,8 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
public let ModelStateDebounce = 0.02
|
||||
|
||||
public protocol Modelable {
|
||||
associatedtype ModelType
|
||||
var model: ModelType { get set }
|
||||
|
||||
Loading…
Reference in New Issue
Block a user