Skip to content

Commit

Permalink
Undisfavor some Store[dynamicMember:] overloads (pointfreeco#2793)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
stephencelis authored Feb 26, 2024
1 parent b832aa4 commit 434c648
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
}

extension Store where State: ObservableState, Action: BindableAction, Action.State == State {
@_disfavoredOverload
public subscript<Value: Equatable>(
dynamicMember keyPath: WritableKeyPath<State, Value>
) -> Value {
Expand All @@ -88,9 +87,8 @@
Action: BindableAction,
Action.State == State
{
@_disfavoredOverload
public var state: State {
get { self.state }
get { self.observableState }
set {
BindingLocal.$isActive.withValue(true) {
self.send(.binding(.set(\.self, newValue)))
Expand All @@ -106,7 +104,6 @@
Action.ViewAction: BindableAction,
Action.ViewAction.State == State
{
@_disfavoredOverload
public subscript<Value: Equatable>(
dynamicMember keyPath: WritableKeyPath<State, Value>
) -> Value {
Expand All @@ -127,9 +124,8 @@
Action.ViewAction: BindableAction,
Action.ViewAction.State == State
{
@_disfavoredOverload
public var state: State {
get { self.state }
get { self.observableState }
set {
BindingLocal.$isActive.withValue(true) {
self.send(.view(.binding(.set(\.self, newValue))))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@
#endif

extension Store where State: ObservableState {
/// Direct access to state in the store when `State` conforms to ``ObservableState``.
public var state: State {
var observableState: State {
self._$observationRegistrar.access(self, keyPath: \.currentState)
return self.currentState
}

/// Direct access to state in the store when `State` conforms to ``ObservableState``.
public var state: State {
self.observableState
}

public subscript<Value>(dynamicMember keyPath: KeyPath<State, Value>) -> Value {
self.state[keyPath: keyPath]
}
Expand Down

0 comments on commit 434c648

Please sign in to comment.