Skip to content

Commit 434c648

Browse files
authored
Undisfavor some Store[dynamicMember:] overloads (#2793)
Came up on Slack. These current disfavored overloads can lead to more difficult to debug error messages, like when trying to form a binding over bindable actions with state that isn't equatable.
1 parent b832aa4 commit 434c648

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

Sources/ComposableArchitecture/Observation/Binding+Observation.swift

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@
6868
}
6969

7070
extension Store where State: ObservableState, Action: BindableAction, Action.State == State {
71-
@_disfavoredOverload
7271
public subscript<Value: Equatable>(
7372
dynamicMember keyPath: WritableKeyPath<State, Value>
7473
) -> Value {
@@ -88,9 +87,8 @@
8887
Action: BindableAction,
8988
Action.State == State
9089
{
91-
@_disfavoredOverload
9290
public var state: State {
93-
get { self.state }
91+
get { self.observableState }
9492
set {
9593
BindingLocal.$isActive.withValue(true) {
9694
self.send(.binding(.set(\.self, newValue)))
@@ -106,7 +104,6 @@
106104
Action.ViewAction: BindableAction,
107105
Action.ViewAction.State == State
108106
{
109-
@_disfavoredOverload
110107
public subscript<Value: Equatable>(
111108
dynamicMember keyPath: WritableKeyPath<State, Value>
112109
) -> Value {
@@ -127,9 +124,8 @@
127124
Action.ViewAction: BindableAction,
128125
Action.ViewAction.State == State
129126
{
130-
@_disfavoredOverload
131127
public var state: State {
132-
get { self.state }
128+
get { self.observableState }
133129
set {
134130
BindingLocal.$isActive.withValue(true) {
135131
self.send(.view(.binding(.set(\.self, newValue))))

Sources/ComposableArchitecture/Observation/Store+Observation.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,16 @@
1515
#endif
1616

1717
extension Store where State: ObservableState {
18-
/// Direct access to state in the store when `State` conforms to ``ObservableState``.
19-
public var state: State {
18+
var observableState: State {
2019
self._$observationRegistrar.access(self, keyPath: \.currentState)
2120
return self.currentState
2221
}
2322

23+
/// Direct access to state in the store when `State` conforms to ``ObservableState``.
24+
public var state: State {
25+
self.observableState
26+
}
27+
2428
public subscript<Value>(dynamicMember keyPath: KeyPath<State, Value>) -> Value {
2529
self.state[keyPath: keyPath]
2630
}

0 commit comments

Comments
 (0)