You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
session-ios/Session/Shared/Types/PagedObservationSource.swift

28 lines
878 B
Swift

// Copyright © 2023 Rangeproof Pty Ltd. All rights reserved.
import Foundation
import GRDB
import SessionUtilitiesKit
protocol PagedObservationSource {
associatedtype PagedTable: TableRecord & ColumnExpressible & Identifiable
associatedtype PagedDataModel: FetchableRecordWithRowId & Identifiable
var pagedDataObserver: PagedDatabaseObserver<PagedTable, PagedDataModel>? { get }
func didInit(using dependencies: Dependencies)
func loadPageBefore()
func loadPageAfter()
}
extension PagedObservationSource {
public func didInit(using dependencies: Dependencies) {
dependencies.storage.addObserver(pagedDataObserver)
}
}
extension PagedObservationSource where PagedTable.ID: SQLExpressible {
func loadPageBefore() { pagedDataObserver?.load(.pageBefore) }
func loadPageAfter() { pagedDataObserver?.load(.pageAfter) }
}