diff --git a/Sources/Model/Data Flow/StateManager.swift b/Sources/Model/Data Flow/StateManager.swift index 8b643c6..b7fc50d 100644 --- a/Sources/Model/Data Flow/StateManager.swift +++ b/Sources/Model/Data Flow/StateManager.swift @@ -24,8 +24,8 @@ public enum StateManager { /// Information about a piece of state. struct State { - /// The state's identifiers. - var ids: (first: UUID, second: UUID?) + /// The state's identifier. + var id: UUID /// The state value. var value: Any? /// Whether to update in the next iteration. @@ -35,14 +35,13 @@ public enum StateManager { /// - Parameter id: The identifier. /// - Returns: Whether the id is contained. func contains(id: UUID) -> Bool { - ids.first == id || ids.second == id + id == self.id } /// Change the identifier to a new one. /// - Parameter newID: The new identifier. mutating func changeID(new newID: UUID) { - ids.second = ids.first - ids.first = newID + id = newID } } @@ -72,7 +71,7 @@ public enum StateManager { static func setState(id: UUID, value: Any?) { if saveState { guard let index = state.firstIndex(where: { $0.contains(id: id) }) else { - state.append(.init(ids: (first: id, second: nil), value: value)) + state.append(.init(id: id, value: value)) return } state[safe: index]?.value = value diff --git a/Tests/DemoApp/DemoApp.swift b/Tests/DemoApp/DemoApp.swift index b106791..f795cec 100644 --- a/Tests/DemoApp/DemoApp.swift +++ b/Tests/DemoApp/DemoApp.swift @@ -1,5 +1,5 @@ import Foundation -import Meta +@testable import Meta import Observation import SampleBackends @@ -44,8 +44,9 @@ struct DemoView: View { var view: Body { Backend1.TestWidget1() Backend1.Button(model.test) { - model.test = "\(Int.random(in: 1...10))" - app.addSceneElement("main") + Task { + app.addSceneElement("main") + } } TestView() testContent @@ -66,10 +67,7 @@ struct TestView: View { var view: Body { Backend2.TestWidget4() Backend1.Button(test) { - Task { - try await Task.sleep(nanoseconds: 100_000_000) - test = "\(Int.random(in: 1...10))" - } + test = "\(Int.random(in: 1...10))" } Backend1.Menu("Hi") { Backend1.Menu("World") { diff --git a/Tests/SampleBackends/Backend1.swift b/Tests/SampleBackends/Backend1.swift index f03e43c..6ba51fd 100644 --- a/Tests/SampleBackends/Backend1.swift +++ b/Tests/SampleBackends/Backend1.swift @@ -60,9 +60,9 @@ public enum Backend1 { } public func update(_ storage: ViewStorage, modifiers: [(any AnyView) -> any AnyView], updateProperties: Bool, type: Storage.Type) { + storage.fields["action"] = action if updateProperties { print("Update button (label = \(label))") - storage.fields["action"] = action } else { print("Do not update button (label = \(label))") }