diff --git a/Sources/Model/Data Flow/UpdateManager.swift b/Sources/Model/Data Flow/UpdateManager.swift index f17f1cd..4bb6d7d 100644 --- a/Sources/Model/Data Flow/UpdateManager.swift +++ b/Sources/Model/Data Flow/UpdateManager.swift @@ -27,7 +27,7 @@ public enum UpdateManager { /// 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. - static func addUpdateHandler(handler: @escaping (Bool) -> Void) { + public static func addUpdateHandler(handler: @escaping (Bool) -> Void) { updateHandlers.append(handler) } diff --git a/Tests/DemoApp/DemoApp.swift b/Tests/DemoApp/DemoApp.swift index 17b2af5..9399bdc 100644 --- a/Tests/DemoApp/DemoApp.swift +++ b/Tests/DemoApp/DemoApp.swift @@ -1,19 +1,18 @@ +import Foundation import Meta import SampleBackends struct DemoView: View { - @State private var test = "" + @State private var test = "Label" var view: Body { - Wrapper { - Backend1.TestWidget1() - Backend1.Button(test) { - test = "\(Int.random(in: 0...10))" - } - TestView() - testContent + Backend1.TestWidget1() + Backend1.Button(test) { + test = "\(Int.random(in: 1...10))" } + TestView() + testContent } @ViewBuilder @@ -43,3 +42,10 @@ for round in 0...2 { print("#\(round)") 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) diff --git a/Tests/SampleBackends/Backend1.swift b/Tests/SampleBackends/Backend1.swift index 1e1d5b3..2a7714e 100644 --- a/Tests/SampleBackends/Backend1.swift +++ b/Tests/SampleBackends/Backend1.swift @@ -56,7 +56,12 @@ public enum Backend1 { public struct Button: BackendWidget { + var label: String + var action: () -> Void + public init(_ label: String, action: @escaping () -> Void) { + self.label = label + self.action = action } public var debugTreeContent: [(String, body: Body)] { @@ -64,14 +69,24 @@ public enum Backend1 { } public var debugTreeParameters: [(String, value: any CustomStringConvertible)] { - [] + _ = action + return [("label", value: label), ("action", value: "() -> Void")] } public func container(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(_ storage: ViewStorage, modifiers: [(any AnyView) -> any AnyView], updateProperties: Bool, type: WidgetType.Type) { + if updateProperties { + print("Update button") + } else { + print("Do not update button") + } } }