Skip to content

Commit 9f849e7

Browse files
authored
Leverage dynamic case writability in example code (#2885)
* Support chainable writability for dynamic case lookup * wip * wip * wip * wip
1 parent dfe8e57 commit 9f849e7

File tree

11 files changed

+33
-93
lines changed

11 files changed

+33
-93
lines changed

ComposableArchitecture.xcworkspace/contents.xcworkspacedata

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ComposableArchitecture.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Examples/SyncUps/SyncUps/AppFeature.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,15 @@ struct AppFeature {
6767
return .none
6868
}
6969

70-
state.path[id: id, case: \.detail]?.syncUp.meetings.insert(
70+
state.path[id: id]?.detail?.syncUp.meetings.insert(
7171
Meeting(
7272
id: Meeting.ID(self.uuid()),
7373
date: self.now,
7474
transcript: transcript
7575
),
7676
at: 0
7777
)
78-
guard let syncUp = state.path[id: id, case: \.detail]?.syncUp
78+
guard let syncUp = state.path[id: id]?.detail?.syncUp
7979
else { return .none }
8080
state.syncUpsList.syncUps[id: syncUp.id] = syncUp
8181
return .none

Examples/SyncUps/SyncUpsTests/AppFeatureTests.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ final class AppFeatureTests: XCTestCase {
2222
}
2323

2424
await store.send(\.path[id:0].detail.deleteButtonTapped) {
25-
$0.path[id: 0, case: \.detail]?.destination = .alert(.deleteSyncUp)
25+
$0.path[id: 0]?.detail?.destination = .alert(.deleteSyncUp)
2626
}
2727

2828
await store.send(\.path[id:0].detail.destination.alert.confirmDeletion) {
29-
$0.path[id: 0, case: \.detail]?.destination = nil
29+
$0.path[id: 0]?.detail?.destination = nil
3030
}
3131

3232
await store.receive(\.path[id:0].detail.delegate.deleteSyncUp) {
@@ -59,19 +59,19 @@ final class AppFeatureTests: XCTestCase {
5959
}
6060

6161
await store.send(\.path[id:0].detail.editButtonTapped) {
62-
$0.path[id: 0, case: \.detail]?.destination = .edit(
62+
$0.path[id: 0]?.detail?.destination = .edit(
6363
SyncUpForm.State(syncUp: syncUp)
6464
)
6565
}
6666

6767
syncUp.title = "Blob"
6868
await store.send(\.path[id:0].detail.destination.edit.syncUp, syncUp) {
69-
$0.path[id: 0, case: \.detail]?.$destination[case: \.edit]?.syncUp.title = "Blob"
69+
$0.path[id: 0]?.detail?.destination?.edit?.syncUp.title = "Blob"
7070
}
7171

7272
await store.send(\.path[id:0].detail.doneEditingButtonTapped) {
73-
$0.path[id: 0, case: \.detail]?.destination = nil
74-
$0.path[id: 0, case: \.detail]?.syncUp.title = "Blob"
73+
$0.path[id: 0]?.detail?.destination = nil
74+
$0.path[id: 0]?.detail?.syncUp.title = "Blob"
7575
}
7676

7777
await store.receive(\.path[id:0].detail.delegate.syncUpUpdated) {
@@ -127,7 +127,7 @@ final class AppFeatureTests: XCTestCase {
127127

128128
await store.send(\.path[id:1].record.onTask)
129129
await store.receive(\.path[id:1].record.delegate.save) {
130-
$0.path[id: 0, case: \.detail]?.syncUp.meetings = [
130+
$0.path[id: 0]?.detail?.syncUp.meetings = [
131131
Meeting(
132132
id: Meeting.ID(UUID(0)),
133133
date: Date(timeIntervalSince1970: 1_234_567_890),

Examples/SyncUps/SyncUpsTests/SyncUpDetailTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ final class SyncUpDetailTests: XCTestCase {
9797

9898
syncUp.title = "Blob's Meeting"
9999
await store.send(\.destination.edit.syncUp, syncUp) {
100-
$0.$destination[case: \.edit]?.syncUp.title = "Blob's Meeting"
100+
$0.destination?.edit?.syncUp.title = "Blob's Meeting"
101101
}
102102

103103
await store.send(.doneEditingButtonTapped) {

Examples/SyncUps/SyncUpsTests/SyncUpsListTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ final class SyncUpsListTests: XCTestCase {
2626

2727
syncUp.title = "Engineering"
2828
await store.send(\.destination.add.syncUp, syncUp) {
29-
$0.$destination[case: \.add]?.syncUp.title = "Engineering"
29+
$0.destination?.add?.syncUp.title = "Engineering"
3030
}
3131

3232
await store.send(.confirmAddSyncUpButtonTapped) {

Examples/TicTacToe/tic-tac-toe/Tests/AppCoreTests/AppCoreTests.swift

Lines changed: 14 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,20 @@ final class AppCoreTests: XCTestCase {
1818
}
1919

2020
await store.send(\.login.view.email, "[email protected]") {
21-
$0.modify(\.login) {
22-
$0.email = "[email protected]"
23-
}
21+
$0.login?.email = "[email protected]"
2422
}
2523
await store.send(\.login.view.password, "bl0bbl0b") {
26-
$0.modify(\.login) {
27-
$0.password = "bl0bbl0b"
28-
$0.isFormValid = true
29-
}
24+
$0.login?.password = "bl0bbl0b"
25+
$0.login?.isFormValid = true
3026
}
3127
await store.send(\.login.view.loginButtonTapped) {
32-
$0.modify(\.login) {
33-
$0.isLoginRequestInFlight = true
34-
}
28+
$0.login?.isLoginRequestInFlight = true
3529
}
3630
await store.receive(\.login.loginResponse.success) {
3731
$0 = .newGame(NewGame.State())
3832
}
3933
await store.send(\.newGame.oPlayerName, "Blob Sr.") {
40-
$0.modify(\.newGame) {
41-
$0.oPlayerName = "Blob Sr."
42-
}
34+
$0.newGame?.oPlayerName = "Blob Sr."
4335
}
4436
await store.send(\.newGame.logoutButtonTapped) {
4537
$0 = .login(Login.State())
@@ -59,41 +51,29 @@ final class AppCoreTests: XCTestCase {
5951
}
6052

6153
await store.send(\.login.view.email, "[email protected]") {
62-
$0.modify(\.login) {
63-
$0.email = "[email protected]"
64-
}
54+
$0.login?.email = "[email protected]"
6555
}
6656

6757
await store.send(\.login.view.password, "bl0bbl0b") {
68-
$0.modify(\.login) {
69-
$0.password = "bl0bbl0b"
70-
$0.isFormValid = true
71-
}
58+
$0.login?.password = "bl0bbl0b"
59+
$0.login?.isFormValid = true
7260
}
7361

7462
await store.send(\.login.view.loginButtonTapped) {
75-
$0.modify(\.login) {
76-
$0.isLoginRequestInFlight = true
77-
}
63+
$0.login?.isLoginRequestInFlight = true
7864
}
7965
await store.receive(\.login.loginResponse.success) {
80-
$0.modify(\.login) {
81-
$0.isLoginRequestInFlight = false
82-
$0.twoFactor = TwoFactor.State(token: "deadbeef")
83-
}
66+
$0.login?.isLoginRequestInFlight = false
67+
$0.login?.twoFactor = TwoFactor.State(token: "deadbeef")
8468
}
8569

8670
await store.send(\.login.twoFactor.view.code, "1234") {
87-
$0.modify(\.login) {
88-
$0.twoFactor?.code = "1234"
89-
$0.twoFactor?.isFormValid = true
90-
}
71+
$0.login?.twoFactor?.code = "1234"
72+
$0.login?.twoFactor?.isFormValid = true
9173
}
9274

9375
await store.send(\.login.twoFactor.view.submitButtonTapped) {
94-
$0.modify(\.login) {
95-
$0.twoFactor?.isTwoFactorRequestInFlight = true
96-
}
76+
$0.login?.twoFactor?.isTwoFactorRequestInFlight = true
9777
}
9878
await store.receive(\.login.twoFactor.twoFactorResponse.success) {
9979
$0 = .newGame(NewGame.State())

Package.resolved

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ let package = Package(
2121
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),
2222
.package(url: "https://github.com/google/swift-benchmark", from: "0.1.0"),
2323
.package(url: "https://github.com/pointfreeco/combine-schedulers", from: "1.0.0"),
24-
.package(url: "https://github.com/pointfreeco/swift-case-paths", from: "1.1.0"),
24+
.package(url: "https://github.com/pointfreeco/swift-case-paths", from: "1.3.0"),
2525
.package(url: "https://github.com/pointfreeco/swift-concurrency-extras", from: "1.1.0"),
2626
.package(url: "https://github.com/pointfreeco/swift-custom-dump", from: "1.0.0"),
2727
.package(url: "https://github.com/pointfreeco/swift-dependencies", from: "1.0.0"),

[email protected]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ let package = Package(
2323
.package(url: "https://github.com/apple/swift-syntax", from: "509.0.0"),
2424
.package(url: "https://github.com/google/swift-benchmark", from: "0.1.0"),
2525
.package(url: "https://github.com/pointfreeco/combine-schedulers", from: "1.0.0"),
26-
.package(url: "https://github.com/pointfreeco/swift-case-paths", from: "1.1.0"),
26+
.package(url: "https://github.com/pointfreeco/swift-case-paths", from: "1.3.0"),
2727
.package(url: "https://github.com/pointfreeco/swift-concurrency-extras", from: "1.1.0"),
2828
.package(url: "https://github.com/pointfreeco/swift-custom-dump", from: "1.0.0"),
2929
.package(url: "https://github.com/pointfreeco/swift-dependencies", from: "1.1.0"),

0 commit comments

Comments
 (0)