Skip to content
This repository has been archived by the owner on Oct 17, 2024. It is now read-only.

Commit

Permalink
Fix signal for asynchronous updates
Browse files Browse the repository at this point in the history
  • Loading branch information
david-swift committed Sep 20, 2024
1 parent bb1d946 commit ef0cb2b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
12 changes: 9 additions & 3 deletions Sources/Model/Data Flow/Signal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
import Foundation

/// A type that signalizes an action.
public struct Signal: Sendable {
public struct Signal: Model {

/// 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 }
Expand All @@ -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
}

Expand Down
6 changes: 6 additions & 0 deletions Sources/View/StateWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit ef0cb2b

Please sign in to comment.