Skip to content

Instantly share code, notes, and snippets.

@aleweichandt
Last active August 17, 2021 20:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aleweichandt/2696924f70b2b7a7ff408147182b8e9c to your computer and use it in GitHub Desktop.
Save aleweichandt/2696924f70b2b7a7ff408147182b8e9c to your computer and use it in GitHub Desktop.
Repository resource creation example
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