-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor/#16 : 업데이트 버전 BaseViewModel, Intent 동시 실행 방지 함수 core/ui 모듈에 선언
- Loading branch information
Showing
7 changed files
with
67 additions
and
73 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
core/ui/src/main/kotlin/com/boostcamp/mapisode/ui/base/RetainFirstIfNavigating.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.boostcamp.mapisode.ui.base | ||
|
||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.delay | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.channelFlow | ||
import kotlinx.coroutines.flow.collectLatest | ||
import kotlinx.coroutines.launch | ||
import kotlin.reflect.KClass | ||
|
||
fun Flow<UiIntent>.retainFirstIfNavigating(vararg intents: KClass<out UiIntent>) = channelFlow { | ||
var isFirst = true | ||
collectLatest { value -> | ||
if (isFirst) { | ||
launch(Dispatchers.IO) { | ||
isFirst = false | ||
send(value) | ||
if (intents.any { it.isInstance(value) }) { | ||
delay(400) | ||
} | ||
isFirst = true | ||
} | ||
} | ||
} | ||
} |
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
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
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
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
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
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