Skip to content

Commit f377ed1

Browse files
committed
Perception 2.0
1 parent d83d00c commit f377ed1

File tree

7 files changed

+65
-53
lines changed

7 files changed

+65
-53
lines changed

ComposableArchitecture.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 14 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ let package = Package(
2626
.package(url: "https://github.com/pointfreeco/swift-dependencies", from: "1.4.0"),
2727
.package(url: "https://github.com/pointfreeco/swift-identified-collections", from: "1.1.0"),
2828
.package(url: "https://github.com/pointfreeco/swift-macro-testing", from: "0.2.0"),
29-
.package(url: "https://github.com/pointfreeco/swift-navigation", from: "2.3.0"),
30-
.package(url: "https://github.com/pointfreeco/swift-perception", from: "1.3.4"),
31-
.package(url: "https://github.com/pointfreeco/swift-sharing", "0.1.2"..<"3.0.0"),
29+
.package(url: "https://github.com/pointfreeco/swift-navigation", branch: "swift-6-2"),
30+
.package(url: "https://github.com/pointfreeco/swift-perception", branch: "swift-6-2"),
31+
.package(url: "https://github.com/pointfreeco/swift-sharing", branch: "swift-6-2"),
3232
.package(url: "https://github.com/pointfreeco/xctest-dynamic-overlay", from: "1.3.0"),
3333
.package(url: "https://github.com/swiftlang/swift-docc-plugin", from: "1.0.0"),
3434
.package(url: "https://github.com/swiftlang/swift-syntax", "509.0.0"..<"602.0.0"),

[email protected]

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@ let package = Package(
2626
.package(url: "https://github.com/pointfreeco/swift-dependencies", from: "1.4.0"),
2727
.package(url: "https://github.com/pointfreeco/swift-identified-collections", from: "1.1.0"),
2828
.package(url: "https://github.com/pointfreeco/swift-macro-testing", from: "0.2.0"),
29-
.package(url: "https://github.com/pointfreeco/swift-navigation", from: "2.3.0"),
30-
.package(url: "https://github.com/pointfreeco/swift-perception", from: "1.3.4"),
31-
.package(url: "https://github.com/pointfreeco/swift-sharing", "0.1.2"..<"3.0.0"),
29+
.package(url: "https://github.com/pointfreeco/swift-navigation", branch: "swift-6-2"),
30+
// .package(url: "https://github.com/pointfreeco/swift-perception", branch: "swift-6-2"),
31+
.package(path: "../swift-perception"),
32+
.package(url: "https://github.com/pointfreeco/swift-sharing", branch: "swift-6-2"),
3233
.package(url: "https://github.com/pointfreeco/xctest-dynamic-overlay", from: "1.3.0"),
3334
.package(url: "https://github.com/swiftlang/swift-docc-plugin", from: "1.0.0"),
3435
.package(url: "https://github.com/swiftlang/swift-syntax", "509.0.0"..<"602.0.0"),

Sources/ComposableArchitecture/Core.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,13 @@ final class RootCore<Root: Reducer>: Core {
6161
self.reducer = reducer
6262
}
6363
func send(_ action: Root.Action) -> Task<Void, Never>? {
64-
_withoutPerceptionChecking {
64+
#if DEBUG
65+
_PerceptionLocals.$skipPerceptionChecking.withValue(true) {
66+
_send(action)
67+
}
68+
#else
6569
_send(action)
66-
}
70+
#endif
6771
}
6872
private func _send(_ action: Root.Action) -> Task<Void, Never>? {
6973
self.bufferedActions.append(action)

Sources/ComposableArchitecture/Observation/IdentifiedArray+Observation.swift

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ extension Store where State: ObservableState {
9292
public struct _StoreCollection<ID: Hashable & Sendable, State, Action>: RandomAccessCollection {
9393
private let store: Store<IdentifiedArray<ID, State>, IdentifiedAction<ID, Action>>
9494
private let data: IdentifiedArray<ID, State>
95+
private let isInPerceptionTracking = _isInPerceptionTracking
9596

9697
#if swift(<5.10)
9798
@MainActor(unsafe)
@@ -120,28 +121,37 @@ public struct _StoreCollection<ID: Hashable & Sendable, State, Action>: RandomAc
120121
)
121122
return MainActor._assumeIsolated { [uncheckedSelf = UncheckedSendable(self)] in
122123
let `self` = uncheckedSelf.wrappedValue
123-
guard self.data.indices.contains(position)
124-
else {
125-
return Store()
126-
}
127-
let elementID = self.data.ids[position]
128-
let scopeID = self.store.id(state: \.[id: elementID], action: \.[id: elementID])
129-
guard let child = self.store.children[scopeID] as? Store<State, Action>
130-
else {
131-
@MainActor
132-
func open(
133-
_ core: some Core<IdentifiedArray<ID, State>, IdentifiedAction<ID, Action>>
134-
) -> any Core<State, Action> {
135-
IfLetCore(
136-
base: core,
137-
cachedState: self.data[position],
138-
stateKeyPath: \.[id: elementID],
139-
actionKeyPath: \.[id: elementID]
140-
)
124+
var child: Store<State, Action> {
125+
guard self.data.indices.contains(position)
126+
else {
127+
return Store()
128+
}
129+
let elementID = self.data.ids[position]
130+
let scopeID = self.store.id(state: \.[id: elementID], action: \.[id: elementID])
131+
guard let child = self.store.children[scopeID] as? Store<State, Action>
132+
else {
133+
@MainActor
134+
func open(
135+
_ core: some Core<IdentifiedArray<ID, State>, IdentifiedAction<ID, Action>>
136+
) -> any Core<State, Action> {
137+
IfLetCore(
138+
base: core,
139+
cachedState: self.data[position],
140+
stateKeyPath: \.[id: elementID],
141+
actionKeyPath: \.[id: elementID]
142+
)
143+
}
144+
return self.store.scope(id: scopeID, childCore: open(self.store.core))
141145
}
142-
return self.store.scope(id: scopeID, childCore: open(self.store.core))
146+
return child
143147
}
144-
return child
148+
#if DEBUG
149+
return _PerceptionLocals.$isInPerceptionTracking.withValue(self.isInPerceptionTracking) {
150+
child
151+
}
152+
#else
153+
return child
154+
#endif
145155
}
146156
}
147157
}

Sources/ComposableArchitecture/Observation/NavigationStack+Observation.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ extension Store {
483483

484484
@_spi(Internals)
485485
public var _isInPerceptionTracking: Bool {
486-
#if !os(visionOS)
486+
#if DEBUG && !os(visionOS)
487487
return _PerceptionLocals.isInPerceptionTracking
488488
#else
489489
return false

Sources/ComposableArchitecture/Store.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,13 @@ public final class Store<State, Action>: _Store {
167167
/// it conforms to ``ObservableState``.
168168
/// - Returns: The return value, if any, of the `body` closure.
169169
public func withState<R>(_ body: (_ state: State) -> R) -> R {
170-
_withoutPerceptionChecking { body(self.currentState) }
170+
#if DEBUG
171+
_PerceptionLocals.$skipPerceptionChecking.withValue(true) {
172+
body(self.currentState)
173+
}
174+
#else
175+
body(self.currentState)
176+
#endif
171177
}
172178

173179
/// Sends an action to the store.

0 commit comments

Comments
 (0)