Skip to content

Commit

Permalink
Fix Linux build and test
Browse files Browse the repository at this point in the history
  • Loading branch information
p4checo committed Jan 16, 2023
1 parent e854218 commit c66a234
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Release"
selectedDebuggerIdentifier = ""
selectedLauncherIdentifier = "Xcode.IDEFoundation.Launcher.PosixSpawn"
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
codeCoverageEnabled = "YES">
<Testables>
Expand Down
58 changes: 29 additions & 29 deletions Sources/ComposableArchitecture/ViewStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,35 @@ public struct ViewStoreTask: Hashable, Sendable {
#if canImport(Combine)
extension ViewStore: ObservableObject {
}

final private class ValueWrapper<V>: ObservableObject {
var value: V {
willSet { objectWillChange.send() }
}

init(_ value: V) {
self.value = value
}
}

@propertyWrapper private struct ObservedState<Value>: DynamicProperty {
@ObservedObject private var box: ValueWrapper<Value>

var wrappedValue: Value {
get { box.value }
nonmutating set { box.value = newValue }
}

var projectedValue: Binding<Value> {
.init(
get: { wrappedValue },
set: { wrappedValue = $0 }
)
}
init(wrappedValue value: Value) {
self._box = ObservedObject(wrappedValue: .init(value))
}
}
#endif

/// A producer of store state.
Expand Down Expand Up @@ -767,32 +796,3 @@ public struct StoreProducer<State>: SignalProducerConvertible {
self.upstream.map(keyPath).skipRepeats()
}
}

final private class ValueWrapper<V>: ObservableObject {
var value: V {
willSet { objectWillChange.send() }
}

init(_ value: V) {
self.value = value
}
}

@propertyWrapper private struct ObservedState<Value>: DynamicProperty {
@ObservedObject private var box: ValueWrapper<Value>

var wrappedValue: Value {
get { box.value }
nonmutating set { box.value = newValue }
}

var projectedValue: Binding<Value> {
.init(
get: { wrappedValue },
set: { wrappedValue = $0 }
)
}
init(wrappedValue value: Value) {
self._box = ObservedObject(wrappedValue: .init(value))
}
}
4 changes: 3 additions & 1 deletion Tests/ComposableArchitectureTests/RuntimeWarningTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,12 @@
reducer: EmptyReducer<State, Action>()
)

let viewStore = ViewStore(store)

var line: UInt = 0
XCTExpectFailure {
line = #line
ViewStore(store).binding(\.$value).wrappedValue = 42
viewStore.binding(\.$value).wrappedValue = 42
} issueMatcher: {
$0.compactDescription == """
A binding action sent from a view store at "\(#fileID):\(line + 1)" was not handled. …
Expand Down

0 comments on commit c66a234

Please sign in to comment.