mastodon-ios/Mastodon/Scene/Profile/Favorite/FavoriteViewModel.swift

51 lines
1.4 KiB
Swift
Raw Normal View History

2021-04-07 08:24:28 +02:00
//
// FavoriteViewModel.swift
// Mastodon
//
// Created by MainasuK Cirno on 2021-4-6.
//
import UIKit
import Combine
import CoreData
import CoreDataStack
import GameplayKit
2022-10-08 07:43:06 +02:00
import MastodonCore
2021-04-07 08:24:28 +02:00
final class FavoriteViewModel {
var disposeBag = Set<AnyCancellable>()
// input
let context: AppContext
let authContext: AuthContext
2021-04-07 08:24:28 +02:00
let statusFetchedResultsController: StatusFetchedResultsController
let listBatchFetchViewModel = ListBatchFetchViewModel()
2021-04-07 08:24:28 +02:00
// output
var diffableDataSource: UITableViewDiffableDataSource<StatusSection, StatusItem>?
2021-04-07 08:24:28 +02:00
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
}()
init(context: AppContext, authContext: AuthContext) {
2021-04-07 08:24:28 +02:00
self.context = context
self.authContext = authContext
2021-04-07 08:24:28 +02:00
self.statusFetchedResultsController = StatusFetchedResultsController(
managedObjectContext: context.managedObjectContext,
domain: authContext.mastodonAuthenticationBox.domain,
additionalTweetPredicate: nil
2021-04-07 08:24:28 +02:00
)
}
}