Brak opisu

GroupViewModel.swift 1.1KB

    // // GroupViewModel.swift // PaiAi // // Created by LISA on 2017/5/8. // Copyright © 2017年 yb. All rights reserved. // import UIKit import RxSwift import RxCocoa import RxDataSources protocol GroupViewModelDelegate: class { func didSelect(_ item: GroupItem) } public typealias GroupSource = GroupRepositorable & Gettable & Deletable & Readable public struct GroupViewModel<T: GroupSource> { let respository: T weak var delegate: GroupViewModelDelegate? public init(respository: T) { self.respository = respository } public var groupContents: Observable<[AnimatableSectionModel<Int, T.Content.Element>]> { return respository.content.map({ model in return [AnimatableSectionModel(model: 0, items: model)] }) } public func reload() { respository.loadContent(isRefresh: true) } public func preload() { respository.loadContent(isRefresh: false) } public func remove(of index: Int) { respository.remove(of: index) } public func didSelect(_ item: GroupItem) { delegate?.didSelect(item) } }