Skip to content

Instantly share code, notes, and snippets.

@devxoul
Last active March 31, 2018 14:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devxoul/42892f2a700b26976b3701a2caab5259 to your computer and use it in GitHub Desktop.
Save devxoul/42892f2a700b26976b3701a2caab5259 to your computer and use it in GitHub Desktop.
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