Skip to content

Commit 591f1a4

Browse files
authored
Fix perception warnings (#2849)
1 parent b8b726c commit 591f1a4

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

Sources/ComposableArchitecture/Store.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,11 @@ public final class Store<State, Action> {
210210
/// it conforms to ``ObservableState``.
211211
/// - Returns: The return value, if any, of the `body` closure.
212212
public func withState<R>(_ body: (_ state: State) -> R) -> R {
213-
body(self.currentState)
213+
#if canImport(Perception)
214+
_withoutPerceptionChecking { body(self.currentState) }
215+
#else
216+
body(self.currentState)
217+
#endif
214218
}
215219

216220
/// Sends an action to the store.

Sources/ComposableArchitecture/ViewStore.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,9 @@ public final class ViewStore<ViewState, ViewAction>: ObservableObject {
156156
action: fromViewAction,
157157
isInvalid: nil
158158
)
159-
self._state = CurrentValueRelay(self.store.currentState)
159+
self._state = CurrentValueRelay(self.store.withState { $0 })
160160
self.viewCancellable = self.store.rootStore.didSet
161-
.compactMap { [weak self] in self?.store.currentState }
161+
.compactMap { [weak self] in self?.store.withState { $0 } }
162162
.removeDuplicates(by: isDuplicate)
163163
.dropFirst()
164164
.sink { [weak self] in

0 commit comments

Comments
 (0)