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

Route enum cases without associated values #194

Merged
merged 1 commit into from
May 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions MobiusCore/Source/EffectHandlers/EnumRoute.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,21 @@ public extension EffectRouter {
_ enumCase: @escaping (EffectParameters) -> Effect
) -> _PartialEffectRouter<Effect, EffectParameters, Event> {
let casePath = /enumCase
return routeEffects(withParameters: { effect in
casePath.extract(from: effect)
})
return routeEffects(withParameters: casePath.extract)
}

func routeCase(
_ enumCase: Effect
) -> _PartialEffectRouter<Effect, Void, Event> {
let casePath = /enumCase
return routeEffects(withParameters: casePath.extract)
}
}

public extension EffectRouter where Effect: Equatable {
func routeCase(
_ enumCase: Effect
) -> _PartialEffectRouter<Effect, Void, Event> {
return routeEffects(withParameters: { effect in
if enumCase == effect {
return ()
} else {
return nil
}
})
return routeEffects(withParameters: { effect in effect == enumCase ? () : nil })
}
}
2 changes: 1 addition & 1 deletion MobiusCore/Test/EffectHandlers/EnumRouteTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import Quick

private typealias Event = ()

private enum Effect: Equatable {
private enum Effect {
case justEffect
case effectWithString(String)
case effectWithTuple(left: String, right: Int)
Expand Down