Skip to content

Commit e524434

Browse files
authored
Merge pull request #47 from Ryu0118/refactor
Refactor
2 parents 2687151 + cf81b51 commit e524434

36 files changed

+290
-237
lines changed

Examples/Github-App/Github-App/Client/GithubRepositoryClient.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
import Foundation
21
import Dependencies
32
import DependenciesMacro
3+
import Foundation
44

55
@Dependencies
66
struct RepositoryClient {
77
var fetchRepositories: @Sendable (_ query: String) async throws -> [Repository]
88
}
99

1010
extension RepositoryClient: DependencyKey {
11-
static let liveValue: RepositoryClient = RepositoryClient(
11+
static let liveValue: RepositoryClient = .init(
1212
fetchRepositories: { query in
1313
var component = URLComponents()
1414
component.scheme = "https"
1515
component.host = "api.github.com"
1616
component.path = "/search/repositories"
1717
component.queryItems = [
18-
URLQueryItem(name: "q", value: query)
18+
URLQueryItem(name: "q", value: query),
1919
]
2020

2121
guard let url = component.url else {

Examples/Github-App/Github-App/Model/Repository.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ struct Repository: Identifiable, Equatable, Hashable {
1010
let stargazersCount: Int
1111

1212
init(item: Response.Item) {
13-
self.id = item.id
14-
self.url = item.svnUrl
15-
self.fullName = item.fullName
16-
self.avatarUrl = item.owner.avatarUrl
17-
self.description = item.description
18-
self.language = item.language
19-
self.stargazersCount = item.stargazersCount
13+
id = item.id
14+
url = item.svnUrl
15+
fullName = item.fullName
16+
avatarUrl = item.owner.avatarUrl
17+
description = item.description
18+
language = item.language
19+
stargazersCount = item.stargazersCount
2020
}
2121
}
2222

Examples/Github-App/Github-App/View/RepositoryView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import SwiftUI
21
import SimplexArchitecture
2+
import SwiftUI
33

44
@Reducer
55
struct RepositoryReducer {

Examples/Github-App/Github-App/View/RootView.swift

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import SwiftUI
21
import SimplexArchitecture
2+
import SwiftUI
33

44
@Reducer
55
struct RootReducer {
@@ -19,16 +19,13 @@ struct RootReducer {
1919

2020
@Dependency(\.repositoryClient.fetchRepositories) var fetchRepositories
2121

22-
func reduce(
23-
into state: StateContainer<RootView>,
24-
action: Action
25-
) -> SideEffect<Self> {
22+
func reduce(into state: StateContainer<RootView>, action: Action) -> SideEffect<Self> {
2623
switch action {
2724
case .onSearchButtonTapped:
2825
state.isLoading = true
29-
return fetchRepositories(query: state.text)
26+
return fetchRepositories(query: state.searchText)
3027

31-
case .onTextChanged(let text):
28+
case let .onTextChanged(text):
3229
if text.isEmpty {
3330
state.repositories = []
3431
}
@@ -57,7 +54,7 @@ struct RootReducer {
5754

5855
case .alert(.retry):
5956
state.isLoading = true
60-
return fetchRepositories(query: state.text)
57+
return fetchRepositories(query: state.searchText)
6158
}
6259
}
6360

@@ -74,7 +71,7 @@ struct RootReducer {
7471

7572
@ViewState
7673
struct RootView: View {
77-
@State var text = ""
74+
@State var searchText = ""
7875
@State var isLoading = false
7976
@State var repositories: [Repository] = []
8077
@State var alertState: AlertState<Reducer.ReducerAction>?
@@ -96,11 +93,11 @@ struct RootView: View {
9693
ProgressView()
9794
}
9895
}
99-
.searchable(text: $text)
96+
.searchable(text: $searchText)
10097
.onSubmit(of: .search) {
10198
send(.onSearchButtonTapped)
10299
}
103-
.onChange(of: text) { _, newValue in
100+
.onChange(of: searchText) { _, newValue in
104101
send(.onTextChanged(newValue))
105102
}
106103
.alert(target: self, unwrapping: $alertState)

Examples/Github-App/Github-AppTests/RepositoryReducerTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import XCTest
21
import Dependencies
3-
import SimplexArchitecture
42
@testable import Github_App
3+
import SimplexArchitecture
4+
import XCTest
55

66
@MainActor
77
final class RepositoryReducerTests: XCTestCase {

Examples/Github-App/Github-AppTests/RootReducerTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import XCTest
2-
import SimplexArchitecture
31
@testable import Github_App
2+
import SimplexArchitecture
3+
import XCTest
44

55
@MainActor
66
final class RootReducerTests: XCTestCase {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
@_exported import SwiftUINavigation
21
@_exported import Dependencies
2+
@_exported import SwiftUINavigation

Sources/SimplexArchitecture/Internal/TestOnly.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ struct TestOnly<T> {
1010
var wrappedValue: T {
1111
_read {
1212
#if DEBUG
13-
if !isTesting {
14-
runtimeWarning("\(Self.self) is accessible only during Unit tests")
15-
}
13+
if !isTesting {
14+
runtimeWarning("\(Self.self) is accessible only during Unit tests")
15+
}
1616
#endif
1717
yield _value
1818
}
1919
set {
2020
#if DEBUG
21-
if isTesting {
22-
_value = newValue
23-
}
21+
if isTesting {
22+
_value = newValue
23+
}
2424
#endif
2525
}
2626
}

Sources/SimplexArchitecture/Macros.swift

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,7 @@
66
/// ```
77
/// @ViewState
88
/// struct MyView: View {
9-
/// let store: Store<MyReducer>
10-
///
11-
/// init(authRepository: AuthRepository, selfRepository: SelfRepository) {
12-
/// store = Store(
13-
/// reducer: MyReducer(
14-
/// authRepository: authRepository,
15-
/// selfRepository: selfRepository
16-
/// )
17-
/// )
18-
/// }
9+
/// let store: Store<MyReducer> = Store(reducer: MyReducer())
1910
///
2011
/// var body: some View {
2112
/// Text("MyView")

Sources/SimplexArchitecture/Reducer/DependenciesOverrideModifier.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public struct _DependenciesOverrideModifier<Base: ReducerProtocol>: ReducerModif
2222
_ keyPath: WritableKeyPath<DependencyValues, Value>,
2323
value: Value
2424
) -> Self {
25-
Self(base: self.base) { values in
25+
Self(base: base) { values in
2626
values[keyPath: keyPath] = value
2727
override(&values)
2828
}

0 commit comments

Comments
 (0)