Skip to content

Commit e277664

Browse files
committed
Use State in AtomScope
1 parent 54a0de8 commit e277664

File tree

1 file changed

+14
-18
lines changed

1 file changed

+14
-18
lines changed

Sources/Atoms/AtomScope.swift

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -87,19 +87,19 @@ public struct AtomScope<Content: View>: View {
8787
public var body: some View {
8888
switch inheritance {
8989
case .environment(let id):
90-
InheritedEnvironment(
90+
WithEnvironment(
9191
id: id,
92-
content: content,
9392
overrides: overrides,
94-
observers: observers
93+
observers: observers,
94+
content: content
9595
)
9696

9797
case .context(let store):
98-
InheritedContext(
99-
content: content,
98+
WithContext(
10099
store: store,
101100
overrides: overrides,
102-
observers: observers
101+
observers: observers,
102+
content: content
103103
)
104104
}
105105
}
@@ -158,27 +158,23 @@ private extension AtomScope {
158158
case context(store: StoreContext)
159159
}
160160

161-
struct InheritedEnvironment: View {
162-
@MainActor
163-
final class State: ObservableObject {
164-
let token = ScopeKey.Token()
165-
}
166-
161+
struct WithEnvironment: View {
167162
let id: ScopeID
168-
let content: Content
169163
let overrides: [OverrideKey: any OverrideProtocol]
170164
let observers: [Observer]
165+
let content: Content
166+
167+
@State
168+
private var token = ScopeKey.Token()
171169

172-
@StateObject
173-
private var state = State()
174170
@Environment(\.store)
175171
private var environmentStore
176172

177173
var body: some View {
178174
content.environment(
179175
\.store,
180176
environmentStore?.scoped(
181-
scopeKey: ScopeKey(token: state.token),
177+
scopeKey: ScopeKey(token: token),
182178
scopeID: id,
183179
observers: observers,
184180
overrides: overrides
@@ -187,11 +183,11 @@ private extension AtomScope {
187183
}
188184
}
189185

190-
struct InheritedContext: View {
191-
let content: Content
186+
struct WithContext: View {
192187
let store: StoreContext
193188
let overrides: [OverrideKey: any OverrideProtocol]
194189
let observers: [Observer]
190+
let content: Content
195191

196192
var body: some View {
197193
content.environment(

0 commit comments

Comments
 (0)