Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some cleanup #2759

Merged
merged 5 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ extension WebSocketClient: DependencyKey {
let socket = try self.socket(id: id)
return try await withCheckedThrowingContinuation { continuation in
socket.sendPing { error in
if let error = error {
if let error {
continuation.resume(throwing: error)
} else {
continuation.resume()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ final class IfLetStoreController<State, Action>: UIViewController {
private var cancellables: Set<AnyCancellable> = []
private var viewController = UIViewController() {
willSet {
self.viewController.willMove(toParent: nil)
self.viewController.view.removeFromSuperview()
self.viewController.removeFromParent()
self.addChild(newValue)
self.view.addSubview(newValue.view)
viewController.willMove(toParent: nil)
viewController.view.removeFromSuperview()
viewController.removeFromParent()
addChild(newValue)
view.addSubview(newValue.view)
newValue.didMove(toParent: self)
}
}
Expand All @@ -37,16 +37,16 @@ final class IfLetStoreController<State, Action>: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()

self.store.ifLet(
store.ifLet(
then: { [weak self] store in
guard let self = self else { return }
self.viewController = self.ifDestination(store)
guard let self else { return }
viewController = ifDestination(store)
},
else: { [weak self] in
guard let self = self else { return }
self.viewController = self.elseDestination()
guard let self else { return }
viewController = elseDestination()
}
)
.store(in: &self.cancellables)
.store(in: &cancellables)
}
}
2 changes: 1 addition & 1 deletion Examples/Search/Search/SearchView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ struct SearchView: View {

@ViewBuilder
func weatherView(locationWeather: Search.State.Weather?) -> some View {
if let locationWeather = locationWeather {
if let locationWeather {
let days = locationWeather.days
.enumerated()
.map { idx, weather in formattedWeather(day: weather, isToday: idx == 0) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ public class LoginViewController: UIViewController {
])

var alertController: UIAlertController?
var twoFactorViewController: TwoFactorViewController?
var twoFactorController: TwoFactorViewController?

observe { [weak self] in
guard let self = self else { return }
guard let self else { return }
emailTextField.text = store.email
emailTextField.isEnabled = store.isEmailTextFieldEnabled
passwordTextField.text = store.password
Expand All @@ -110,16 +110,16 @@ public class LoginViewController: UIViewController {
}

if let store = store.scope(state: \.twoFactor, action: \.twoFactor.presented),
twoFactorViewController == nil
twoFactorController == nil
stephencelis marked this conversation as resolved.
Show resolved Hide resolved
{
twoFactorViewController = TwoFactorViewController(store: store)
twoFactorController = TwoFactorViewController(store: store)
navigationController?.pushViewController(
twoFactorViewController!,
twoFactorController!,
animated: true
)
} else if store.alert == nil, twoFactorViewController != nil {
twoFactorViewController?.dismiss(animated: true)
twoFactorViewController = nil
} else if store.twoFactor == nil, twoFactorController != nil {
navigationController?.popToViewController(self, animated: true)
twoFactorController = nil
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public class NewGameViewController: UIViewController {
var gameController: GameViewController?

observe { [weak self] in
guard let self = self else { return }
guard let self else { return }
playerOTextField.text = store.oPlayerName
playerXTextField.text = store.xPlayerName
letsPlayButton.isEnabled = store.isLetsPlayButtonEnabled
Expand All @@ -97,8 +97,8 @@ public class NewGameViewController: UIViewController {
{
gameController = GameViewController(store: store)
navigationController?.pushViewController(gameController!, animated: true)
} else if gameController != nil {
gameController?.dismiss(animated: true)
} else if store.game == nil, gameController != nil {
navigationController?.popToViewController(self, animated: true)
gameController = nil
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public final class TwoFactorViewController: UIViewController {
var alertController: UIAlertController?

observe { [weak self] in
guard let self = self else { return }
guard let self else { return }
activityIndicator.isHidden = store.isActivityIndicatorHidden
codeTextField.text = store.code
loginButton.isEnabled = store.isLoginButtonEnabled
Expand Down
6 changes: 3 additions & 3 deletions Sources/ComposableArchitecture/Effect.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ extension Effect {
} catch is CancellationError {
return
} catch {
guard let handler = handler else {
guard let handler else {
#if DEBUG
var errorDump = ""
customDump(error, to: &errorDump, indent: 4)
Expand Down Expand Up @@ -324,12 +324,12 @@ extension Effect {
case let (.run(lhsPriority, lhsOperation), .run(rhsPriority, rhsOperation)):
return Self(
operation: .run { send in
if let lhsPriority = lhsPriority {
if let lhsPriority {
await Task(priority: lhsPriority) { await lhsOperation(send) }.cancellableValue
} else {
await lhsOperation(send)
}
if let rhsPriority = rhsPriority {
if let rhsPriority {
await Task(priority: rhsPriority) { await rhsOperation(send) }.cancellableValue
} else {
await rhsOperation(send)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ extension View {
Button(role: button.role.map(ButtonRole.init)) {
switch button.action.type {
case let .send(action):
if let action = action {
if let action {
store?.send(action)
}
case let .animatedSend(action, animation):
if let action = action {
if let action {
store?.send(action, animation: animation)
}
}
Expand Down Expand Up @@ -54,11 +54,11 @@ extension View {
Button(role: button.role.map(ButtonRole.init)) {
switch button.action.type {
case let .send(action):
if let action = action {
if let action {
store?.send(action)
}
case let .animatedSend(action, animation):
if let action = action {
if let action {
store?.send(action, animation: animation)
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/ComposableArchitecture/RootStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public final class RootStore {
self?.effectCancellables[uuid] = nil
},
receiveValue: { [weak self] effectAction in
guard let self = self else { return }
guard let self else { return }
if let task = continuation.yield({
self.send(effectAction, originatingFrom: action)
}) {
Expand Down
4 changes: 2 additions & 2 deletions Sources/ComposableArchitecture/Store.swift
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public final class Store<State, Action> {
@ReducerBuilder<State, Action> reducer: () -> R,
withDependencies prepareDependencies: ((inout DependencyValues) -> Void)? = nil
) where R.State == State, R.Action == Action {
if let prepareDependencies = prepareDependencies {
if let prepareDependencies {
let (initialState, reducer, dependencies) = withDependencies(prepareDependencies) {
@Dependency(\.self) var dependencies
return (initialState(), reducer(), dependencies)
Expand Down Expand Up @@ -353,7 +353,7 @@ public final class Store<State, Action> {
isInvalid?(self.currentState) == true || self._isInvalidated()
}
: { [weak self] in
guard let self = self else { return true }
guard let self else { return true }
return isInvalid?(self.currentState) == true || self._isInvalidated()
}
childStore.canCacheChildren = self.canCacheChildren && id != nil
Expand Down
4 changes: 2 additions & 2 deletions Sources/ComposableArchitecture/SwiftUI/Alert.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ extension View {
Button(role: button.role.map(ButtonRole.init)) {
switch button.action.type {
case let .send(action):
if let action = action {
if let action {
store.send(.presented(fromDestinationAction(action)))
}
case let .animatedSend(action, animation):
if let action = action {
if let action {
store.send(.presented(fromDestinationAction(action)), animation: animation)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ extension View {
Button(role: button.role.map(ButtonRole.init)) {
switch button.action.type {
case let .send(action):
if let action = action {
if let action {
store.send(.presented(fromDestinationAction(action)))
}
case let .animatedSend(action, animation):
if let action = action {
if let action {
store.send(.presented(fromDestinationAction(action)), animation: animation)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ extension View {
let actionSheetState = store.withState { $0.wrappedValue.flatMap(toDestinationState) }
self.actionSheet(item: $item) { _ in
ActionSheet(actionSheetState!) { action in
if let action = action {
if let action {
store.send(.presented(fromDestinationAction(action)))
} else {
store.send(.dismiss)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ extension View {
let alertState = store.withState { $0.wrappedValue.flatMap(toDestinationState) }
self.alert(item: $item) { _ in
Alert(alertState!) { action in
if let action = action {
if let action {
store.send(.presented(fromDestinationAction(action)))
} else {
store.send(.dismiss)
Expand Down
6 changes: 3 additions & 3 deletions Sources/ComposableArchitecture/TestStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1007,7 +1007,7 @@ extension TestStore where State: Equatable {
switch self.exhaustivity {
case .on:
var expectedWhenGivenPreviousState = expected
if let updateStateToExpectedResult = updateStateToExpectedResult {
if let updateStateToExpectedResult {
try Dependencies.withDependencies {
$0 = self.reducer.dependencies
} operation: {
Expand All @@ -1024,7 +1024,7 @@ extension TestStore where State: Equatable {

case .off:
var expectedWhenGivenActualState = actual
if let updateStateToExpectedResult = updateStateToExpectedResult {
if let updateStateToExpectedResult {
try Dependencies.withDependencies {
$0 = self.reducer.dependencies
} operation: {
Expand All @@ -1041,7 +1041,7 @@ extension TestStore where State: Equatable {
&& expectedWhenGivenActualState == actual
{
var expectedWhenGivenPreviousState = current
if let updateStateToExpectedResult = updateStateToExpectedResult {
if let updateStateToExpectedResult {
XCTExpectFailure(strict: false) {
do {
try Dependencies.withDependencies {
Expand Down
8 changes: 4 additions & 4 deletions Sources/ComposableArchitecture/UIKit/AlertStateUIKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
/// viewStore.publisher
/// .settingsAlert
/// .sink { [weak self] alert in
/// guard let self = self else { return }
/// if let alert = alert {
/// let alertController = UIAlertController(state: alert, send: {
/// guard let self else { return }
/// if let alert {
/// let alertController = UIAlertController(state: alert) {
/// self.viewStore.send(.settings($0))
/// })
/// }
/// self.present(alertController, animated: true, completion: nil)
/// self.alertController = alertController
/// } else {
Expand Down
2 changes: 1 addition & 1 deletion Sources/ComposableArchitecture/UIKit/IfLetUIKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ extension Store {
/// )
/// },
/// else: { [weak self] in
/// guard let self = self else { return }
/// guard let self else { return }
/// self.navigationController?.popToViewController(self, animated: true)
/// }
/// )
Expand Down