Replies: 2 comments
-
@Jeehut We've definitely seen folks break each case out into a |
Beta Was this translation helpful? Give feedback.
-
Okay, so after playing around a bit with So now, something that looked like this before (shortened): let myReducer = Reducer<MyState, MyAction, MyEnv> { state, action, env in
switch action {
case .didAppear:
// some code
// some code
// some code
// some code
// some code
// some code
// some code
// some code
// some code
// some code
return .none
case let .someOtherAction(param):
// some code
// some code
// some code
// some code
// some code
// some code
// some code
state.param = param
// some code
// some code
// some code
// some code
// some code
// some code
// some code
return .none
}
} Now looks like this: let myReducer = Reducer<MyState, MyAction, MyEnv> { state, action, env in
let actionHandler = MyActionHandler(env: env)
switch action {
case .didAppear:
return actionHandler.didAppear(state: &state)
case let .someOtherAction(param):
return actionHandler. someOtherAction(state: &state, param: param)
}
}
fileprivate struct MyActionHandler {
typealias State = MyState
typealias Action = MyAction
let env: MyEnv
func didAppear(state: inout State) -> Effect<Action, Never> {
// some code
// some code
// some code
// some code
// some code
// some code
// some code
// some code
// some code
// some code
return .none
}
func someOtherAction(state: inout State, param: String) -> Effect<Action, Never> {
// some code
// some code
// some code
// some code
// some code
// some code
// some code
state.param = param
// some code
// some code
// some code
// some code
// some code
// some code
// some code
return .none
}
} My jump bar problem is fixed and navigating to a specific case is easy. I like this, but even better would be if I could get rid of the |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I have a
Reducer
that has become more than 400 lines long. While I know that I should probably be refactoring some of the logic out of it, this situation happens and it will probably happen in the future again (until I had the time to refactor). In other types 400 lines of code don't slow me down because I can use the Xcode jump bar to find my functions, types, extensions and properties.But because the
Reducer
is basically just one closure with many cases, the jump bar doesn't help at all as it doesn't seem to showcases
. Do you have any solution to this? Do I have to really add a// - MARK: <case name>
comments everywhere manually to help navigate to a specific case inside a long Reducer? Or is there some easy & clean way of splitting the Reducer into many small parts that I can navigate easily?fileprivate
global functions maybe? Any ideas?Beta Was this translation helpful? Give feedback.
All reactions