52 lines
1.3 KiB
Swift
52 lines
1.3 KiB
Swift
![]() |
//
|
||
|
// DiscoveryNewsViewModel.swift
|
||
|
// Mastodon
|
||
|
//
|
||
|
// Created by MainasuK on 2022-4-13.
|
||
|
//
|
||
|
|
||
|
import os.log
|
||
|
import UIKit
|
||
|
import Combine
|
||
|
import GameplayKit
|
||
|
import CoreData
|
||
|
import CoreDataStack
|
||
|
import MastodonSDK
|
||
|
|
||
|
final class DiscoveryNewsViewModel {
|
||
|
|
||
|
var disposeBag = Set<AnyCancellable>()
|
||
|
|
||
|
// input
|
||
|
let context: AppContext
|
||
|
let listBatchFetchViewModel = ListBatchFetchViewModel()
|
||
|
|
||
|
// output
|
||
|
@Published var links: [Mastodon.Entity.Link] = []
|
||
|
var diffableDataSource: UITableViewDiffableDataSource<DiscoverySection, DiscoveryItem>?
|
||
|
private(set) lazy var stateMachine: GKStateMachine = {
|
||
|
let stateMachine = GKStateMachine(states: [
|
||
|
State.Initial(viewModel: self),
|
||
|
State.Reloading(viewModel: self),
|
||
|
State.Fail(viewModel: self),
|
||
|
State.Idle(viewModel: self),
|
||
|
State.Loading(viewModel: self),
|
||
|
State.NoMore(viewModel: self),
|
||
|
])
|
||
|
stateMachine.enter(State.Initial.self)
|
||
|
return stateMachine
|
||
|
}()
|
||
|
|
||
|
let didLoadLatest = PassthroughSubject<Void, Never>()
|
||
|
|
||
|
init(context: AppContext) {
|
||
|
self.context = context
|
||
|
// end init
|
||
|
}
|
||
|
|
||
|
deinit {
|
||
|
os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s", ((#file as NSString).lastPathComponent), #line, #function)
|
||
|
}
|
||
|
|
||
|
}
|