Fix observing models not always working

This commit is contained in:
david-swift 2024-07-19 21:14:44 +02:00
parent e133b7b8b7
commit e490cf2b82
3 changed files with 10 additions and 13 deletions

View File

@ -113,11 +113,9 @@ extension App {
withObservationTracking {
_ = scene
} onChange: {
Task {
StateManager.updateState(id: app.storage.stateStorage.first?.value.id ?? .init())
StateManager.updateViews()
observe()
}
StateManager.updateState(id: app.storage.stateStorage.first?.value.id ?? .init())
StateManager.updateViews()
observe()
}
}

View File

@ -85,11 +85,9 @@ struct StateWrapper: ConvenienceWidget {
withObservationTracking {
_ = content()
} onChange: {
Task {
StateManager.updateState(id: storage.state.first?.value.id ?? .init())
StateManager.updateViews()
observe(storage: storage)
}
StateManager.updateState(id: storage.state.first?.value.id ?? .init())
StateManager.updateViews()
observe(storage: storage)
}
}

View File

@ -60,14 +60,15 @@ struct DemoView: View {
}
@available(macOS 14, *)
struct TestView: View {
@State private var test = "Label"
@State private var test = TestModel()
var view: Body {
Backend2.TestWidget4()
Backend1.Button(test) {
test = "\(Int.random(in: 1...10))"
Backend1.Button(test.test) {
test.test = "\(Int.random(in: 1...10))"
}
Backend1.Menu("Hi") {
Backend1.Menu("World") {