-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Isolate state
and send
to main actor
#35
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -159,9 +159,9 @@ public struct Update<Model: ModelProtocol> { | |
public protocol StoreProtocol { | ||
associatedtype Model: ModelProtocol | ||
|
||
var state: Model { get } | ||
@MainActor var state: Model { get } | ||
|
||
func send(_ action: Model.Action) -> Void | ||
@MainActor func send(_ action: Model.Action) -> Void | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rather than isolating send to main actor, we may want to allow send to be nonisolated, and have a separate main-actor isolated |
||
} | ||
|
||
/// Store is a source of truth for a state. | ||
|
@@ -172,6 +172,7 @@ public protocol StoreProtocol { | |
/// Store has a `@Published` `state` (typically a struct). | ||
/// All updates and effects to this state happen through actions | ||
/// sent to `store.send`. | ||
@MainActor | ||
public final class Store<Model>: ObservableObject, StoreProtocol | ||
where Model: ModelProtocol | ||
{ | ||
|
@@ -312,6 +313,7 @@ where Model: ModelProtocol | |
} | ||
} | ||
|
||
@MainActor | ||
public struct ViewStore<ViewModel: ModelProtocol>: StoreProtocol { | ||
private var _send: (ViewModel.Action) -> Void | ||
public var state: ViewModel | ||
|
@@ -344,6 +346,7 @@ extension ViewStore { | |
|
||
extension StoreProtocol { | ||
/// Create a viewStore from a StoreProtocol | ||
@MainActor | ||
public func viewStore<ViewModel: ModelProtocol>( | ||
get: (Self.Model) -> ViewModel, | ||
tag: @escaping (ViewModel.Action) -> Self.Model.Action | ||
|
@@ -387,6 +390,7 @@ extension Binding { | |
} | ||
|
||
extension StoreProtocol { | ||
@MainActor | ||
public func binding<Value>( | ||
get: @escaping (Self.Model) -> Value, | ||
tag: @escaping (Value) -> Self.Model.Action | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Get-only property should be nonisolated.