-> Observable<Mutation> { switch action { case .load: return projectRepository.project(id: currentState.projectId) .asObservable() .map(Mutation.setProject) } } func reduce(state: State, mutation: Mutation) -> State { var state = state switch mutation { case let .setProject(project): state.isBookmarking = project.bookmarked } return state }
-> Observable<Mutation> { let projectId = currentState.projectId let fromProjectEvent = ProjectEvent.stream .flatMap { event -> Observable<Mutation> in switch event { case let .updateBookmarking(id, isBookmarking): return id == projectId ? .just(.setBookmarking(isBookmarking)) : .empty() } } return Observable.merge(mutation, fromProjectEvent) } func reduce(state: State, mutation: Mutation) -> State { var state = state switch mutation { case let .setBookmarking(isBookmarking): state.isBookmarking = isBookmarking } return state }