Skip to content

Commit 1918011

Browse files
committed
Use State in ViewContext
1 parent 6a0bb72 commit 1918011

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

Sources/Atoms/PropertyWrapper/ViewContext.swift

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,11 @@ import SwiftUI
3232
///
3333
@propertyWrapper
3434
public struct ViewContext: DynamicProperty {
35-
@StateObject
36-
private var state = State()
35+
@State
36+
private var phase = false
37+
38+
@State
39+
private var subscriberState = SubscriberState()
3740

3841
@Environment(\.store)
3942
private var _store
@@ -54,25 +57,25 @@ public struct ViewContext: DynamicProperty {
5457
/// Instead, you use the property variable created with the `@ViewContext` attribute.
5558
@MainActor
5659
public var wrappedValue: AtomViewContext {
57-
AtomViewContext(
60+
let phase = $phase
61+
62+
// Initializes State and starts observing for updates.
63+
_ = phase.wrappedValue
64+
65+
return AtomViewContext(
5866
store: store,
59-
subscriber: Subscriber(state.subscriberState),
67+
subscriber: Subscriber(subscriberState),
6068
subscription: Subscription(
6169
location: location,
62-
update: { [weak state] in
63-
state?.objectWillChange.send()
70+
update: {
71+
phase.wrappedValue.toggle()
6472
}
6573
)
6674
)
6775
}
6876
}
6977

7078
private extension ViewContext {
71-
@MainActor
72-
final class State: ObservableObject {
73-
let subscriberState = SubscriberState()
74-
}
75-
7679
@MainActor
7780
var store: StoreContext {
7881
guard let _store else {

0 commit comments

Comments
 (0)