Skip to content

Commit

Permalink
Add equatable to Reducer macro for Destination and Path
Browse files Browse the repository at this point in the history
  • Loading branch information
kalupas226 committed Mar 9, 2024
1 parent 40e9508 commit e68d1dd
Show file tree
Hide file tree
Showing 14 changed files with 26 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ extension AlertState where Action == RepositoryList.Action.Alert {
}

extension RepositoryList {
@Reducer
@Reducer(state: .equatable)
public enum Destination {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ extension AlertState where Action == RepositoryList.Action.Alert {
}

extension RepositoryList {
@Reducer
@Reducer(state: .equatable)
public enum Destination {
case alert(AlertState<Alert>)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ extension AlertState where Action == RepositoryList.Destination.Alert {
}

extension RepositoryList {
@Reducer
@Reducer(state: .equatable)
public enum Destination {
case alert(AlertState<Alert>)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ extension AlertState where Action == RepositoryList.Destination.Alert {
}

extension RepositoryList {
@Reducer
@Reducer(state: .equatable)
public enum Destination {
case alert(AlertState<Alert>)
case repositoryDetail(RepositoryDetail)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ extension AlertState where Action == RepositoryList.Destination.Alert {
}

extension RepositoryList {
@Reducer
@Reducer(state: .equatable)
public enum Destination {
case alert(AlertState<Alert>)
case repositoryDetail(RepositoryDetail)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,11 @@ extension AlertState where Action == RepositoryList.Destination.Alert {
}

extension RepositoryList {
@Reducer
@Reducer(state: .equatable)
public enum Destination {
case alert(AlertState<Alert>)
case repositoryDetail(RepositoryDetail)

public enum Alert {}
public enum Alert: Equatable {}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ extension AlertState where Action == RepositoryList.Destination.Alert {
}

extension RepositoryList {
@Reducer
@Reducer(state: .equatable)
public enum Destination {
case alert(AlertState<Alert>)
case repositoryDetail(RepositoryDetail)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,15 @@ extension AlertState where Action == RepositoryList.Destination.Alert {
}

extension RepositoryList {
@Reducer
@Reducer(state: .equatable)
public enum Destination {
case alert(AlertState<Alert>)
case repositoryDetail(RepositoryDetail)

public enum Alert: Equatable {}
}

@Reducer
@Reducer(state: .equatable)
public enum Path {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,15 @@ extension AlertState where Action == RepositoryList.Destination.Alert {
}

extension RepositoryList {
@Reducer
@Reducer(state: .equatable)
public enum Destination {
case alert(AlertState<Alert>)
// repositoryDetail case の削除

public enum Alert: Equatable {}
}

@Reducer
@Reducer(state: .equatable)
public enum Path {
case repositoryDetail(RepositoryDetail)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,14 @@ extension AlertState where Action == RepositoryList.Destination.Alert {
}

extension RepositoryList {
@Reducer
@Reducer(state: .equatable)
public enum Destination {
case alert(AlertState<Action.Alert>)

public enum Alert: Equatable {}
}

@Reducer
@Reducer(state: .equatable)
public enum Path {
case repositoryDetail(RepositoryDetail)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,14 @@ extension AlertState where Action == RepositoryList.Destination.Alert {
}

extension RepositoryList {
@Reducer
@Reducer(state: .equatable)
public enum Destination {
case alert(AlertState<Action.Alert>)

public enum Alert: Equatable {}
}

@Reducer
@Reducer(state: .equatable)
public enum Path {
case repositoryDetail(RepositoryDetail)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,14 @@ extension AlertState where Action == RepositoryList.Destination.Alert {
}

extension RepositoryList {
@Reducer
@Reducer(state: .equatable)
public enum Destination {
case alert(AlertState<Action.Alert>)

public enum Alert: Equatable {}
}

@Reducer
@Reducer(state: .equatable)
public enum Path {
case repositoryDetail(RepositoryDetail)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,14 @@ extension AlertState where Action == RepositoryList.Destination.Alert {
}

extension RepositoryList {
@Reducer
@Reducer(state: .equatable)
public enum Destination {
case alert(AlertState<Action.Alert>)

public enum Alert: Equatable {}
}

@Reducer
@Reducer(state: .equatable)
public enum Path {
case repositoryDetail(RepositoryDetail)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,14 @@
現在のままだと Alert, Confirmation Dialog, Sheet など、Navigation の対象が増える度に `State`, `Action` それぞれに `@Presents`, `PresentationAction` を利用したものを増やしていかなければいけません。
Navigation を管理するための新しい Reducer を定義し、この問題を解決します。
まずは、そのための `Destination` Reducer を作成します。
この Reducer は struct ではなく enum で表現します。Sheet, Alert などの Navigation は複数の種類が同時に発生することはあり得ないため、enum で表現することが適切です。
この Reducer は struct ではなく enum で表現します。Sheet, Alert などの Navigation は複数の種類が同時に発生することはあり得ないため、enum で表現することが適切です。
また、ここで利用する Reducer macro では `state` に `.equatable` を指定することで、macro によって生成される Reducer の `State` が `Equatable` になるようにします。
これによって `Destination` を利用する Parent State の Equatable を保つことができます。

@Code(name: "RepositoryListView.swift", file: 06-02-code-0001.swift, previousFile: 06-01-code-0003.swift)

> Reducer macro の `state` は Swift のバグを回避する方法として用意されているものです。(将来不要となる可能性はあります)
> 詳しくは [Synthesizing protocol conformances on State and Action](https://pointfreeco.github.io/swift-composable-architecture/main/documentation/composablearchitecture/reducers#Synthesizing-protocol-conformances-on-State-and-Action) を参照してください。
}
@Step {
次に `Destination` Reducer に case を追加します。
Expand Down

0 comments on commit e68d1dd

Please sign in to comment.