-
-
Save aleweichandt/2696924f70b2b7a7ff408147182b8e9c to your computer and use it in GitHub Desktop.
Repository resource creation example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TodoRepository( | |
private val localSource: ITodoCache, // Cache injection | |
private val remoteSource: ITodoApi | |
) { | |
// new resource to query List<Todo> | |
private val todoResource = Resource<Unit, List<Todo>>( | |
{ remoteSource.getAllTodos() }, | |
{ localSource.getAllTodos() }, | |
localSource::storeAllTodos, | |
localSource::deleteAllTodos, | |
// detached RefreshControl with 5 mins rate | |
RefrehsControl(TimeUnit.MINUTES.toMillis(5)) | |
) | |
//... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment