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(){}
|
required public init(){}
|
||||||
}
|
}
|
||||||
|
|
||||||
open class VDSLabel: UILabel, Modelable, ObservableObject {
|
open class VDSLabel: UILabel, Modelable {
|
||||||
@Published public var model: VDSLabelModel = DefaultLabelModel()
|
@Published public var model: VDSLabelModel = DefaultLabelModel()
|
||||||
private var cancellable: AnyCancellable?
|
private var cancellable: AnyCancellable?
|
||||||
|
|
||||||
public var fontSize: VDSFontSize = .large {
|
public var fontSize: VDSFontSize {
|
||||||
didSet {
|
get { model.fontSize }
|
||||||
if fontSize != model.fontSize {
|
set {
|
||||||
model.fontSize = fontSize
|
if model.fontSize != newValue {
|
||||||
|
model.fontSize = newValue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public var textPosition: VDSTextPosition = .left{
|
public var textPosition: VDSTextPosition {
|
||||||
didSet {
|
get { model.textPosition }
|
||||||
if textPosition != model.textPosition {
|
set {
|
||||||
model.textPosition = textPosition
|
if model.textPosition != newValue {
|
||||||
|
model.textPosition = newValue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public var fontWeight: VDSFontWeight = .regular {
|
public var fontWeight: VDSFontWeight {
|
||||||
didSet {
|
get { model.fontWeight }
|
||||||
if fontWeight != model.fontWeight {
|
set {
|
||||||
model.fontWeight = fontWeight
|
if model.fontWeight != newValue {
|
||||||
|
model.fontWeight = newValue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public var fontCategory: VDSFontCategory = .body {
|
public var fontCategory: VDSFontCategory {
|
||||||
didSet {
|
get { model.fontCategory }
|
||||||
if fontCategory != model.fontCategory {
|
set {
|
||||||
model.fontCategory = fontCategory
|
if model.fontCategory != newValue {
|
||||||
|
model.fontCategory = newValue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public var surface: Surface = .light {
|
public var surface: Surface {
|
||||||
didSet {
|
get { model.surface }
|
||||||
if surface != model.surface {
|
set {
|
||||||
model.surface = surface
|
if model.surface != newValue {
|
||||||
|
model.surface = newValue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -79,7 +84,7 @@ open class VDSLabel: UILabel, Modelable, ObservableObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func setup() {
|
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)
|
self?.onStateChange(viewModel: viewModel)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -43,7 +43,7 @@ public class DefaultToggleModel: DefaultLabelModel, VDSToggleModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@objcMembers open class VDSToggle: VDSControl, Modelable, Changable {
|
@objcMembers open class VDSToggle: VDSControl, Modelable, Changable {
|
||||||
|
|
||||||
public typealias ModelType = VDSToggleModel
|
public typealias ModelType = VDSToggleModel
|
||||||
@Published public var model: ModelType = DefaultToggleModel()
|
@Published public var model: ModelType = DefaultToggleModel()
|
||||||
private var cancellable: AnyCancellable?
|
private var cancellable: AnyCancellable?
|
||||||
@ -228,7 +228,7 @@ public class DefaultToggleModel: DefaultLabelModel, VDSToggleModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func setup() {
|
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)
|
self?.onStateChange(viewModel: viewModel)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,6 +7,8 @@
|
|||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
|
public let ModelStateDebounce = 0.02
|
||||||
|
|
||||||
public protocol Modelable {
|
public protocol Modelable {
|
||||||
associatedtype ModelType
|
associatedtype ModelType
|
||||||
var model: ModelType { get set }
|
var model: ModelType { get set }
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user