Skip to content

Commit

Permalink
Update FileState MainActor usage (#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xLeif authored Oct 2, 2024
1 parent 9713930 commit c15288a
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Sources/AppState/PropertyWrappers/State/FileState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import SwiftUI
#endif

/// `FileState` is a property wrapper allowing SwiftUI views to subscribe to Application's state changes in a reactive way. State is stored using `FileManager`. Works similar to `State` and `Published`.
@MainActor
@propertyWrapper public struct FileState<Value: Codable & Sendable> {
#if !os(Linux) && !os(Windows)
/// Holds the singleton instance of `Application`.
Expand All @@ -25,6 +24,7 @@ import SwiftUI
private let column: Int

/// Represents the current value of the `FileState`.
@MainActor
public var wrappedValue: Value {
get {
Application.fileState(
Expand All @@ -51,6 +51,7 @@ import SwiftUI

#if !os(Linux) && !os(Windows)
/// A binding to the `State`'s value, which can be used with SwiftUI views.
@MainActor
public var projectedValue: Binding<Value> {
Binding(
get: { wrappedValue },
Expand All @@ -64,6 +65,7 @@ import SwiftUI

- Parameter keyPath: The `KeyPath` for accessing `FileState` in Application.
*/
@MainActor
public init(
_ keyPath: KeyPath<Application, Application.FileState<Value>>,
_ fileID: StaticString = #fileID,
Expand All @@ -80,6 +82,7 @@ import SwiftUI

#if !os(Linux) && !os(Windows)
/// A property wrapper's synthetic storage property. This is just for SwiftUI to mutate the `wrappedValue` and send event through `objectWillChange` publisher when the `wrappedValue` changes
@MainActor
public static subscript<OuterSelf: ObservableObject>(
_enclosingInstance observed: OuterSelf,
wrapped wrappedKeyPath: ReferenceWritableKeyPath<OuterSelf, Value>,
Expand Down

0 comments on commit c15288a

Please sign in to comment.