Last active
March 31, 2018 14:42
-
-
Save devxoul/42892f2a700b26976b3701a2caab5259 to your computer and use it in GitHub Desktop.
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
func mutate(action: Action) -> Observable<Mutation> { | |
switch action { | |
case .follow: | |
return UserService.follow() | |
.map { Mutation.setFollowing(true) } | |
.catchErrorJustReturn(Mutation.setFollowing(false)) | |
case .unfollow: | |
return UserService.unfollow() | |
.map { Mutation.setFollowing(false) } | |
.catchErrorJustReturn(Mutation.setFollowing(true)) | |
} | |
} | |
func reduce(state: State, mutation: Mutation) -> State { | |
var newState = state | |
switch mutation { | |
case let setFollowing(isFollowing): | |
newState.isFollowing = isFollowing | |
} | |
return newState | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment