Skip to content

Instantly share code, notes, and snippets.

@HarryTylenol
Created August 5, 2019 14:17
Show Gist options
  • Save HarryTylenol/810142da09c967f5b162c7e189bf45b6 to your computer and use it in GitHub Desktop.
Save HarryTylenol/810142da09c967f5b162c7e189bf45b6 to your computer and use it in GitHub Desktop.
0003_4
fun getFestival( ... ): ResponseWrapper<FestivalData> {
val request: suspend () -> Unit = {
val festival = festivalAPI.get( ... )
("Festival API" to "Fetched from API").debug()
festivalDAO.insert(festival)
("Festival DAO" to "Inserted to DB").debug()
}
val refreshTrigger = MutableLiveData<Unit>()
val refreshState = refresh.switchMap {
("Festival Refresh" to "Refresh Request").debug()
createStateForRequest(request)
}
return ResponseWrapper(
festivalDAO.get( ... ), // 캐시 상태
createStateForRequest(request), // 첫 요청 상태
refreshState // 새로고침 요청 상태
) { refreshTrigger.value = null } // 새로고침 트리거
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment