com.github.mvysny.vokdataloader.SortedDataLoader.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of vok-dataloader Show documentation
Show all versions of vok-dataloader Show documentation
VOK-DataLoader: The Paged/Filtered/Sorted DataLoader API
The newest version!
package com.github.mvysny.vokdataloader
/**
* Returns a new data loader which appends given [sortBy] to any sorting criteria provided to the [DataLoader.fetch].
* This means that anything provided to [DataLoader.fetch] takes precedence over [sortBy].
*/
public fun DataLoader.sortedBy(vararg sortBy: SortClause): DataLoader =
SortedDataLoader(sortBy.toList(), this)
/**
* Wraps [delegate] data loader and always appends given [sortBy] to any sorting criteria provided to the [DataLoader.fetch].
* This means that anything provided to [DataLoader.fetch] takes precedence over [sortBy].
*
* You can use [DataLoader.sortedBy] convenience method to produce instances of this class.
*/
public class SortedDataLoader(
public val sortBy: List,
public val delegate: DataLoader
) : DataLoader {
override fun getCount(filter: Filter?): Long = delegate.getCount(filter)
override fun fetch(filter: Filter?, sortBy: List, range: LongRange): List =
delegate.fetch(filter, sortBy + this.sortBy, range)
override fun toString(): String = "SortedDataLoader(sortBy=$sortBy, $delegate)"
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy