| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- import Foundation
- import RxSwift
- import RxCocoa
- import RxDataSources
- public typealias MessageSource = MessageRepositorable & Gettable & Deletable
- public struct MessageViewModel<T: MessageSource> {
-
- let repository: T
-
- public init(repository: T) {
- self.repository = repository
- }
-
- public var messageContents: Observable<[AnimatableSectionModel<Int, MessageItem>]> {
- return repository.content.map({ model in
- return [AnimatableSectionModel(model: 0, items: model)]
- })
- }
-
- public func reload() {
- repository.loadContent(isRefresh: true)
- }
-
- public func preload() {
- repository.loadContent(isRefresh: false)
- }
-
- public func remove(of index: Int) {
- repository.remove(of: index)
- }
-
- public func removeAll() {
- repository.removeAll()
- }
-
- public var hasData: Observable<Bool> {
- return repository.content.flatMap({ (items) in
- Observable.just(items.count > 0)
- }).share()
- }
- }
|