Remove duplicate publisher (#898)
This commit is contained in:
parent
3ee2024c3b
commit
e2ff0c8deb
|
@ -20,8 +20,7 @@ final class HomeTimelineNavigationBarTitleViewModel {
|
||||||
// input
|
// input
|
||||||
let context: AppContext
|
let context: AppContext
|
||||||
var networkErrorCount = CurrentValueSubject<Int, Never>(0)
|
var networkErrorCount = CurrentValueSubject<Int, Never>(0)
|
||||||
var networkErrorPublisher = PassthroughSubject<Void, Never>()
|
|
||||||
|
|
||||||
// output
|
// output
|
||||||
let state = CurrentValueSubject<State, Never>(.logo)
|
let state = CurrentValueSubject<State, Never>(.logo)
|
||||||
let hasNewPosts = CurrentValueSubject<Bool, Never>(false)
|
let hasNewPosts = CurrentValueSubject<Bool, Never>(false)
|
||||||
|
@ -32,15 +31,7 @@ final class HomeTimelineNavigationBarTitleViewModel {
|
||||||
|
|
||||||
init(context: AppContext) {
|
init(context: AppContext) {
|
||||||
self.context = context
|
self.context = context
|
||||||
|
|
||||||
networkErrorPublisher
|
|
||||||
.receive(on: DispatchQueue.main)
|
|
||||||
.sink { [weak self] _ in
|
|
||||||
guard let self = self else { return }
|
|
||||||
self.networkErrorCount.value = self.networkErrorCount.value + 1
|
|
||||||
}
|
|
||||||
.store(in: &disposeBag)
|
|
||||||
|
|
||||||
networkErrorCount
|
networkErrorCount
|
||||||
.receive(on: DispatchQueue.main)
|
.receive(on: DispatchQueue.main)
|
||||||
.map { count in
|
.map { count in
|
||||||
|
@ -131,23 +122,18 @@ extension HomeTimelineNavigationBarTitleViewModel {
|
||||||
|
|
||||||
// MARK: - Offline state
|
// MARK: - Offline state
|
||||||
extension HomeTimelineNavigationBarTitleViewModel {
|
extension HomeTimelineNavigationBarTitleViewModel {
|
||||||
|
|
||||||
func resetOfflineCounterListener() {
|
|
||||||
networkErrorCount.value = 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func receiveLoadingStateCompletion(_ completion: Subscribers.Completion<Error>) {
|
func receiveLoadingStateCompletion(_ completion: Subscribers.Completion<Error>) {
|
||||||
switch completion {
|
switch completion {
|
||||||
case .failure:
|
case .failure:
|
||||||
networkErrorPublisher.send()
|
networkErrorCount.value += 1
|
||||||
case .finished:
|
case .finished:
|
||||||
resetOfflineCounterListener()
|
networkErrorCount.value = 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleScrollViewDidScroll(_ scrollView: UIScrollView) {
|
func handleScrollViewDidScroll(_ scrollView: UIScrollView) {
|
||||||
guard hasNewPosts.value else { return }
|
guard hasNewPosts.value else { return }
|
||||||
|
|
||||||
let contentOffsetY = scrollView.contentOffset.y
|
let contentOffsetY = scrollView.contentOffset.y
|
||||||
let isScrollToTop = contentOffsetY < -scrollView.contentInset.top
|
let isScrollToTop = contentOffsetY < -scrollView.contentInset.top
|
||||||
guard isScrollToTop else { return }
|
guard isScrollToTop else { return }
|
||||||
|
@ -155,28 +141,3 @@ extension HomeTimelineNavigationBarTitleViewModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: Publish post state
|
|
||||||
//extension HomeTimelineNavigationBarTitleViewModel {
|
|
||||||
//
|
|
||||||
// func setupPublishingProgress() {
|
|
||||||
// let progressUpdatePublisher = Timer.publish(every: 0.016, on: .main, in: .common) // ~ 60FPS
|
|
||||||
// .autoconnect()
|
|
||||||
// .share()
|
|
||||||
// .eraseToAnyPublisher()
|
|
||||||
//
|
|
||||||
// publishingProgressSubscription = progressUpdatePublisher
|
|
||||||
// .map { _ in Float(0) }
|
|
||||||
// .scan(0.0) { progress, _ -> Float in
|
|
||||||
// return 0.95 * progress + 0.05 // progress + 0.05 * (1.0 - progress). ~ 1 sec to 0.95 (under 60FPS)
|
|
||||||
// }
|
|
||||||
// .subscribe(publishingProgress)
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// func suspendPublishingProgress() {
|
|
||||||
// publishingProgressSubscription = nil
|
|
||||||
// publishingProgress.send(0)
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//}
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue