Fix signal for asynchronous updates
This commit is contained in:
parent
bb1d946b4a
commit
80c430c546
@ -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
|
||||
}
|
||||
|
||||
|
||||
@ -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.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user