Skip to content

Commit

Permalink
Refactor next() -> nextBatch()
Browse files Browse the repository at this point in the history
  • Loading branch information
alfogrillo committed Jan 24, 2023
1 parent ff229ff commit 11f605b
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,17 @@ enum MockPollHistoryScreenState: MockScreenState, CaseIterable {
pollHistoryMode = .past
case .activeEmpty:
pollHistoryMode = .active
pollService.nextPublisher = Empty(completeImmediately: true,
pollService.nextBatchPublisher = Empty(completeImmediately: true,
outputType: TimelinePollDetails.self,
failureType: Error.self).eraseToAnyPublisher()
case .pastEmpty:
pollHistoryMode = .past
pollService.nextPublisher = Empty(completeImmediately: true,
pollService.nextBatchPublisher = Empty(completeImmediately: true,
outputType: TimelinePollDetails.self,
failureType: Error.self).eraseToAnyPublisher()
case .loading:
pollHistoryMode = .active
pollService.nextPublisher = Empty(completeImmediately: false,
pollService.nextBatchPublisher = Empty(completeImmediately: false,
outputType: TimelinePollDetails.self,
failureType: Error.self).eraseToAnyPublisher()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private extension PollHistoryViewModel {
state.isLoading = true

pollService
.next()
.nextBatch()
.collect()
.sink { [weak self] _ in
#warning("Handle errors")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ final class PollHistoryService: PollHistoryServiceProtocol {
setup(timeline: timeline)
}

func next() -> AnyPublisher<TimelinePollDetails, Error> {
func nextBatch() -> AnyPublisher<TimelinePollDetails, Error> {
currentBatchSubject?.eraseToAnyPublisher() ?? startPagination()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ final class MockPollHistoryService: PollHistoryServiceProtocol {
pollErrorPublisher
}

lazy var nextPublisher: AnyPublisher<TimelinePollDetails, Error> = (activePollsData + pastPollsData)
lazy var nextBatchPublisher: AnyPublisher<TimelinePollDetails, Error> = (activePollsData + pastPollsData)
.publisher
.setFailureType(to: Error.self)
.eraseToAnyPublisher()

func next() -> AnyPublisher<TimelinePollDetails, Error> {
nextPublisher
func nextBatch() -> AnyPublisher<TimelinePollDetails, Error> {
nextBatchPublisher
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//
//
// Copyright 2023 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -18,13 +18,13 @@ import Combine

protocol PollHistoryServiceProtocol {
/// Returns a Publisher publishing the polls in the next batch.
/// Implementations should return the same publisher if `next()` is called again before the previous publisher completes.
func next() -> AnyPublisher<TimelinePollDetails, Error>
/// Implementations should return the same publisher if `nextBatch()` is called again before the previous publisher completes.
func nextBatch() -> AnyPublisher<TimelinePollDetails, Error>

/// Publishes updates for the polls previously pusblished by the `next()` publishers.
/// Publishes updates for the polls previously pusblished by the `nextBatch()` publishers.
var updates: AnyPublisher<TimelinePollDetails, Never> { get }

/// Publishes errors regarding poll aggregations.
/// Note: `next()` will continue to publish new polls even if some poll isn't being aggregated correctly.
/// Note: `nextBatch()` will continue to publish new polls even if some poll isn't being aggregated correctly.
var pollErrors: AnyPublisher<Error, Never> { get }
}

0 comments on commit 11f605b

Please sign in to comment.