-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Configuration): migrate Configuration to modern TCA
- Loading branch information
1 parent
d0d1213
commit 2d59735
Showing
2 changed files
with
39 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,42 @@ | ||
import SwiftClockUI | ||
import ComposableArchitecture | ||
import SwiftClockUI | ||
|
||
struct ConfigurationState: Equatable { | ||
var clock = ClockConfiguration() | ||
var clockStyle: ClockStyle = .classic | ||
var isPresented = false | ||
} | ||
|
||
enum ConfigurationAction: Equatable { | ||
case setMinuteIndicatorsShown(Bool) | ||
case setHourIndicatorsShown(Bool) | ||
case setLimitedHoursShown(Bool) | ||
case setClockStyle(ClockStyle) | ||
case present | ||
case hide | ||
} | ||
struct Configuration: ReducerProtocol { | ||
struct State: Equatable { | ||
var clock = ClockConfiguration() | ||
var clockStyle: ClockStyle = .classic | ||
var isPresented = false | ||
} | ||
|
||
struct ConfigurationEnvironment { } | ||
enum Action: Equatable { | ||
case setMinuteIndicatorsShown(Bool) | ||
case setHourIndicatorsShown(Bool) | ||
case setLimitedHoursShown(Bool) | ||
case setClockStyle(ClockStyle) | ||
case present | ||
case hide | ||
} | ||
|
||
typealias ConfigurationReducer = Reducer<ConfigurationState, ConfigurationAction, ConfigurationEnvironment> | ||
let configurationReducer = ConfigurationReducer { state, action, _ in | ||
switch action { | ||
case let .setMinuteIndicatorsShown(isShown): | ||
state.clock.isMinuteIndicatorsShown = isShown | ||
return .none | ||
case let .setHourIndicatorsShown(isShown): | ||
state.clock.isHourIndicatorsShown = isShown | ||
return .none | ||
case let .setLimitedHoursShown(isShown): | ||
state.clock.isLimitedHoursShown = isShown | ||
return .none | ||
case let .setClockStyle(clockStyle): | ||
state.clockStyle = clockStyle | ||
return .none | ||
case .present: | ||
state.isPresented = true | ||
return .none | ||
case .hide: | ||
state.isPresented = false | ||
return .none | ||
func reduce(into state: inout State, action: Action) -> EffectTask<Action> { | ||
switch action { | ||
case let .setMinuteIndicatorsShown(isShown): | ||
state.clock.isMinuteIndicatorsShown = isShown | ||
return .none | ||
case let .setHourIndicatorsShown(isShown): | ||
state.clock.isHourIndicatorsShown = isShown | ||
return .none | ||
case let .setLimitedHoursShown(isShown): | ||
state.clock.isLimitedHoursShown = isShown | ||
return .none | ||
case let .setClockStyle(clockStyle): | ||
state.clockStyle = clockStyle | ||
return .none | ||
case .present: | ||
state.isPresented = true | ||
return .none | ||
case .hide: | ||
state.isPresented = false | ||
return .none | ||
} | ||
} | ||
} |