Created
August 5, 2019 14:17
-
-
Save HarryTylenol/810142da09c967f5b162c7e189bf45b6 to your computer and use it in GitHub Desktop.
0003_4
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
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