Change status updates be combine code instead of selectors
This commit is contained in:
parent
b25c8634ca
commit
1b5c9da2d7
@ -48,15 +48,7 @@ final class SceneModel: ObservableObject {
|
|||||||
self.articleIconSchemeHandler = ArticleIconSchemeHandler(sceneModel: self)
|
self.articleIconSchemeHandler = ArticleIconSchemeHandler(sceneModel: self)
|
||||||
self.webViewProvider = WebViewProvider(articleIconSchemeHandler: self.articleIconSchemeHandler!)
|
self.webViewProvider = WebViewProvider(articleIconSchemeHandler: self.articleIconSchemeHandler!)
|
||||||
|
|
||||||
NotificationCenter.default.addObserver(self, selector: #selector(statusesDidChange(_:)), name: .StatusesDidChange, object: nil)
|
subscribeToToolbarChangeEvents()
|
||||||
|
|
||||||
timelineModel.$articles.sink { [weak self] articles in
|
|
||||||
self?.updateMarkAllAsReadButtonsState(articles: articles)
|
|
||||||
}.store(in: &cancellables)
|
|
||||||
|
|
||||||
timelineModel.$selectedArticles.sink { [weak self] articles in
|
|
||||||
self?.updateArticleButtonsState(selectedArticles: articles)
|
|
||||||
}.store(in: &cancellables)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: Article Management API
|
// MARK: Article Management API
|
||||||
@ -126,17 +118,15 @@ extension SceneModel: TimelineModelDelegate {
|
|||||||
|
|
||||||
private extension SceneModel {
|
private extension SceneModel {
|
||||||
|
|
||||||
// MARK: Notifications
|
// MARK: Subscriptions
|
||||||
|
func subscribeToToolbarChangeEvents() {
|
||||||
|
let combinedPublisher = timelineModel.$articles.combineLatest(timelineModel.$selectedArticles,
|
||||||
|
NotificationCenter.default.publisher(for: .StatusesDidChange))
|
||||||
|
|
||||||
@objc func statusesDidChange(_ note: Notification) {
|
combinedPublisher.sink { [weak self] (articles, selectedArticles, _) in
|
||||||
guard let articleIDs = note.userInfo?[Account.UserInfoKey.articleIDs] as? Set<String> else {
|
self?.updateMarkAllAsReadButtonsState(articles: articles)
|
||||||
return
|
self?.updateArticleButtonsState(selectedArticles: selectedArticles)
|
||||||
}
|
}.store(in: &cancellables)
|
||||||
updateMarkAllAsReadButtonsState(articles: timelineModel.articles)
|
|
||||||
let selectedArticleIDs = timelineModel.selectedArticles.map { $0.articleID }
|
|
||||||
if !articleIDs.intersection(selectedArticleIDs).isEmpty {
|
|
||||||
updateArticleButtonsState(selectedArticles: timelineModel.selectedArticles)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: Button State Updates
|
// MARK: Button State Updates
|
||||||
|
Loading…
x
Reference in New Issue
Block a user