Skip to content

Commit

Permalink
Rename BindableState to BindingState (#1855)
Browse files Browse the repository at this point in the history
The -`able` naming evokes protocols in Swift, and is an outlier when
considered alongside the rest of TCA's binding tools:

- `BindingAction`: concrete type
- `BindableAction`: protocol
- `BindingReducer`: concrete type

So, let's make things consistent.

The one caveat is that Swift diagnostics for such a deprecation aren't
great, so users won't get proactive warnings here for the time being:

swiftlang/swift#63139

We may just want to keep the deprecation around till it does...

(cherry picked from commit 52c4a01437aa1429dab4e6b460062a8b7d6aeab6)

# Conflicts:
#	Sources/ComposableArchitecture/Internal/Deprecations.swift
#	Sources/ComposableArchitecture/SwiftUI/Binding.swift
#	Tests/ComposableArchitectureTests/DebugTests.swift
  • Loading branch information
stephencelis authored and p4checo committed Jan 26, 2023
1 parent 37d99ca commit 90ea5d4
Show file tree
Hide file tree
Showing 9 changed files with 649 additions and 641 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ private let readMe = """
Bindable state and actions allow you to safely eliminate the boilerplate caused by needing to \
have a unique action for every UI control. Instead, all UI bindings can be consolidated into a \
single `binding` action that holds onto a `BindingAction` value, and all bindable state can be \
safeguarded with the `BindableState` property wrapper.
safeguarded with the `BindingState` property wrapper.
It is instructive to compare this case study to the "Binding Basics" case study.
"""
Expand All @@ -17,10 +17,10 @@ private let readMe = """

struct BindingForm: ReducerProtocol {
struct State: Equatable {
@BindableState var sliderValue = 5.0
@BindableState var stepCount = 10
@BindableState var text = ""
@BindableState var toggleIsOn = false
@BindingState var sliderValue = 5.0
@BindingState var stepCount = 10
@BindingState var text = ""
@BindingState var toggleIsOn = false
}

enum Action: BindableAction, Equatable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ private let readMe = """

struct FocusDemo: ReducerProtocol {
struct State: Equatable {
@BindableState var focusedField: Field?
@BindableState var password: String = ""
@BindableState var username: String = ""
@BindingState var focusedField: Field?
@BindingState var password: String = ""
@BindingState var username: String = ""

enum Field: String, Hashable {
case username, password
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,20 +177,20 @@ struct Settings: ReducerProtocol {
```

This is a _lot_ of boilerplate for something that should be simple. Luckily, we can dramatically
eliminate this boilerplate using ``BindableState``, ``BindableAction``, and ``BindingReducer``.
eliminate this boilerplate using ``BindingState``, ``BindableAction``, and ``BindingReducer``.

First, we can annotate each bindable value of state with the ``BindableState`` property wrapper:
First, we can annotate each bindable value of state with the ``BindingState`` property wrapper:

```swift
struct Settings: ReducerProtocol {
struct State: Equatable {
@BindableState var digest = Digest.daily
@BindableState var displayName = ""
@BindableState var enableNotifications = false
@BindingState var digest = Digest.daily
@BindingState var displayName = ""
@BindingState var enableNotifications = false
var isLoading = false
@BindableState var protectMyPosts = false
@BindableState var sendEmailNotifications = false
@BindableState var sendMobileNotifications = false
@BindingState var protectMyPosts = false
@BindingState var sendEmailNotifications = false
@BindingState var sendMobileNotifications = false
}

// ...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ The Composable Architecture can be used to power applications built in many fram

- <doc:Bindings>
- ``ViewStore/binding(get:send:)-65xes``
- ``BindableState``
- ``BindingState``
- ``BindableAction``
- ``BindingAction``
- ``BindingReducer``
Expand Down
Loading

0 comments on commit 90ea5d4

Please sign in to comment.