Add testing for state properties
This commit is contained in:
parent
1d7c80f5e7
commit
4b9ea1e883
@ -27,7 +27,7 @@ public enum UpdateManager {
|
|||||||
|
|
||||||
/// Add a handler that is called when the user interface should update.
|
/// Add a handler that is called when the user interface should update.
|
||||||
/// - Parameter handler: The handler. The parameter defines whether the whole UI should be force updated.
|
/// - Parameter handler: The handler. The parameter defines whether the whole UI should be force updated.
|
||||||
static func addUpdateHandler(handler: @escaping (Bool) -> Void) {
|
public static func addUpdateHandler(handler: @escaping (Bool) -> Void) {
|
||||||
updateHandlers.append(handler)
|
updateHandlers.append(handler)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,19 +1,18 @@
|
|||||||
|
import Foundation
|
||||||
import Meta
|
import Meta
|
||||||
import SampleBackends
|
import SampleBackends
|
||||||
|
|
||||||
struct DemoView: View {
|
struct DemoView: View {
|
||||||
|
|
||||||
@State private var test = ""
|
@State private var test = "Label"
|
||||||
|
|
||||||
var view: Body {
|
var view: Body {
|
||||||
Wrapper {
|
Backend1.TestWidget1()
|
||||||
Backend1.TestWidget1()
|
Backend1.Button(test) {
|
||||||
Backend1.Button(test) {
|
test = "\(Int.random(in: 1...10))"
|
||||||
test = "\(Int.random(in: 0...10))"
|
|
||||||
}
|
|
||||||
TestView()
|
|
||||||
testContent
|
|
||||||
}
|
}
|
||||||
|
TestView()
|
||||||
|
testContent
|
||||||
}
|
}
|
||||||
|
|
||||||
@ViewBuilder
|
@ViewBuilder
|
||||||
@ -43,3 +42,10 @@ for round in 0...2 {
|
|||||||
print("#\(round)")
|
print("#\(round)")
|
||||||
DemoView().updateStorage(storage, modifiers: modifiers, updateProperties: true, type: backendType)
|
DemoView().updateStorage(storage, modifiers: modifiers, updateProperties: true, type: backendType)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UpdateManager.addUpdateHandler { _ in
|
||||||
|
print("#Handler")
|
||||||
|
DemoView().updateStorage(storage, modifiers: modifiers, updateProperties: false, type: backendType)
|
||||||
|
}
|
||||||
|
|
||||||
|
sleep(2)
|
||||||
|
|||||||
@ -56,7 +56,12 @@ public enum Backend1 {
|
|||||||
|
|
||||||
public struct Button: BackendWidget {
|
public struct Button: BackendWidget {
|
||||||
|
|
||||||
|
var label: String
|
||||||
|
var action: () -> Void
|
||||||
|
|
||||||
public init(_ label: String, action: @escaping () -> Void) {
|
public init(_ label: String, action: @escaping () -> Void) {
|
||||||
|
self.label = label
|
||||||
|
self.action = action
|
||||||
}
|
}
|
||||||
|
|
||||||
public var debugTreeContent: [(String, body: Body)] {
|
public var debugTreeContent: [(String, body: Body)] {
|
||||||
@ -64,14 +69,24 @@ public enum Backend1 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public var debugTreeParameters: [(String, value: any CustomStringConvertible)] {
|
public var debugTreeParameters: [(String, value: any CustomStringConvertible)] {
|
||||||
[]
|
_ = action
|
||||||
|
return [("label", value: label), ("action", value: "() -> Void")]
|
||||||
}
|
}
|
||||||
|
|
||||||
public func container<WidgetType>(modifiers: [(any AnyView) -> any AnyView], type: WidgetType.Type) -> ViewStorage {
|
public func container<WidgetType>(modifiers: [(any AnyView) -> any AnyView], type: WidgetType.Type) -> ViewStorage {
|
||||||
.init(nil)
|
Task {
|
||||||
|
try await Task.sleep(for: .seconds(1))
|
||||||
|
action()
|
||||||
|
}
|
||||||
|
return .init(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func update<WidgetType>(_ storage: ViewStorage, modifiers: [(any AnyView) -> any AnyView], updateProperties: Bool, type: WidgetType.Type) {
|
public func update<WidgetType>(_ storage: ViewStorage, modifiers: [(any AnyView) -> any AnyView], updateProperties: Bool, type: WidgetType.Type) {
|
||||||
|
if updateProperties {
|
||||||
|
print("Update button")
|
||||||
|
} else {
|
||||||
|
print("Do not update button")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user