Skip to content

Commit

Permalink
Route enum cases without associated values
Browse files Browse the repository at this point in the history
  • Loading branch information
kmcbride committed May 31, 2022
1 parent 2170f40 commit d2ff1e6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
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

0 comments on commit d2ff1e6

Please sign in to comment.