From 3c8606893d608d71f4dd53e4b415d3bb219789bd Mon Sep 17 00:00:00 2001 From: Matheus Barbieri Corregiari Date: Mon, 8 Jul 2024 17:59:27 -0300 Subject: [PATCH] [Hotfix] Adjust MirrorFlow --- .../br/com/arch/toolkit/splinter/strategy/MirrorFlow.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/toolkit/splinter/src/main/kotlin/br/com/arch/toolkit/splinter/strategy/MirrorFlow.kt b/toolkit/splinter/src/main/kotlin/br/com/arch/toolkit/splinter/strategy/MirrorFlow.kt index b7b0bdd0..a4de7035 100644 --- a/toolkit/splinter/src/main/kotlin/br/com/arch/toolkit/splinter/strategy/MirrorFlow.kt +++ b/toolkit/splinter/src/main/kotlin/br/com/arch/toolkit/splinter/strategy/MirrorFlow.kt @@ -7,6 +7,7 @@ import br.com.arch.toolkit.splinter.Splinter import br.com.arch.toolkit.splinter.extension.emitError import br.com.arch.toolkit.splinter.extension.emitLoading import br.com.arch.toolkit.splinter.extension.invokeCatching +import br.com.arch.toolkit.util.dataResultLoading import br.com.arch.toolkit.util.dataResultSuccess import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.FlowCollector @@ -48,7 +49,9 @@ class MirrorFlow : Strategy() { .collect { data -> executor.logInfo("\t[MirrorFlow] Received new data, data: $data") executor.logInfo("\t[MirrorFlow] Emit - Loading Data! - $data") - collector.emitLoading(data) + if (config.emitOnlyDistinct && executor.get() != dataResultLoading(data)) { + collector.emitLoading(data) + } } executor.logInfo("\t[MirrorFlow] Finished flow!") if (executor.error == null) { @@ -73,8 +76,10 @@ class MirrorFlow : Strategy() { inner class Config internal constructor() { internal var mapError: (suspend (Throwable) -> Throwable)? = null internal var fallback: (suspend (Throwable) -> RESULT)? = null + internal var emitOnlyDistinct: Boolean = false internal var flow: (suspend () -> Flow)? = null fun flow(flow: suspend () -> Flow) = apply { this.flow = flow } + fun emitOnlyDistinct(enable: Boolean) = apply { this.emitOnlyDistinct = enable } } }