Fix signal for asynchronous updates

This commit is contained in:
david-swift 2024-09-19 22:32:53 +02:00
parent bb1d946b4a
commit 80c430c546
2 changed files with 15 additions and 3 deletions

View File

@ -8,12 +8,14 @@
import Foundation
/// A type that signalizes an action.
public struct Signal: Sendable {
public struct Signal: Model, Sendable {
/// An action is signalized by toggling a boolean to `true` and back to `false`.
@State var boolean = false
var boolean = false
/// A signal has a unique identifier.
public let id: UUID = .init()
/// The model data.
public var model: ModelData?
/// Whether the action has caused an update.
public var update: Bool { boolean }
@ -23,7 +25,11 @@ public struct Signal: Sendable {
/// Activate a signal.
public func signal() {
boolean = true
setModel { $0.boolean = true }
}
/// Destroy a signal.
mutating func destroySignal() {
boolean = false
}

View File

@ -55,6 +55,12 @@ struct StateWrapper: ConvenienceWidget {
return
}
await content().updateStorage(storage, data: data, updateProperties: updateProperties, type: type)
for property in state {
if var value = property.value.content.value as? Signal, value.update {
value.destroySignal()
property.value.content.value = value
}
}
}
/// Get a view storage.