diff --git a/sample/src/main/java/com/trendyol/transmission/features/colorpicker/ColorPickerTransformer.kt b/sample/src/main/java/com/trendyol/transmission/features/colorpicker/ColorPickerTransformer.kt index 89e2573..0209361 100644 --- a/sample/src/main/java/com/trendyol/transmission/features/colorpicker/ColorPickerTransformer.kt +++ b/sample/src/main/java/com/trendyol/transmission/features/colorpicker/ColorPickerTransformer.kt @@ -4,8 +4,10 @@ import com.trendyol.transmission.DefaultDispatcher import com.trendyol.transmission.features.multioutput.multiOutputTransformerIdentity import com.trendyol.transmission.transformer.Transformer import com.trendyol.transmission.transformer.dataholder.buildDataHolder -import com.trendyol.transmission.transformer.handler.buildGenericEffectHandler -import com.trendyol.transmission.transformer.handler.buildGenericSignalHandler +import com.trendyol.transmission.transformer.handler.HandlerRegistry +import com.trendyol.transmission.transformer.handler.handlerRegistry +import com.trendyol.transmission.transformer.handler.registerEffect +import com.trendyol.transmission.transformer.handler.registerSignal import com.trendyol.transmission.transformer.request.buildDataContract import com.trendyol.transmission.transformer.request.createIdentity import com.trendyol.transmission.ui.ColorPickerUiState @@ -20,27 +22,20 @@ class ColorPickerTransformer @Inject constructor( private val holder = buildDataHolder(ColorPickerUiState(), holderContract) - override val signalHandler = buildGenericSignalHandler { signal -> - when (signal) { - is ColorPickerSignal.SelectColor -> { - holder.update { it.copy(selectedColorIndex = signal.index) } - publish( - ColorPickerEffect.BackgroundColorUpdate(signal.selectedColor.copy(alpha = 0.1f)) - ) - send( - effect = ColorPickerEffect.SelectedColorUpdate(signal.selectedColor), - identity = multiOutputTransformerIdentity - ) - } + override val handlerRegistry: HandlerRegistry = handlerRegistry { + registerSignal { signal -> + holder.update { it.copy(selectedColorIndex = signal.index) } + publish( + ColorPickerEffect.BackgroundColorUpdate(signal.selectedColor.copy(alpha = 0.1f)) + ) + send( + effect = ColorPickerEffect.SelectedColorUpdate(signal.selectedColor), + identity = multiOutputTransformerIdentity + ) } - } - - override val effectHandler = buildGenericEffectHandler { effect -> - when (effect) { - is ColorPickerEffect.BackgroundColorUpdate -> { - holder.update { - it.copy(backgroundColor = effect.color) - } + registerEffect { effect -> + holder.update { + it.copy(backgroundColor = effect.color) } } } diff --git a/sample/src/main/java/com/trendyol/transmission/features/input/InputTransformer.kt b/sample/src/main/java/com/trendyol/transmission/features/input/InputTransformer.kt index 4841422..074b208 100644 --- a/sample/src/main/java/com/trendyol/transmission/features/input/InputTransformer.kt +++ b/sample/src/main/java/com/trendyol/transmission/features/input/InputTransformer.kt @@ -4,8 +4,10 @@ import com.trendyol.transmission.DefaultDispatcher import com.trendyol.transmission.features.colorpicker.ColorPickerEffect import com.trendyol.transmission.transformer.Transformer import com.trendyol.transmission.transformer.dataholder.buildDataHolder -import com.trendyol.transmission.transformer.handler.buildGenericEffectHandler -import com.trendyol.transmission.transformer.handler.buildTypedSignalHandler +import com.trendyol.transmission.transformer.handler.HandlerRegistry +import com.trendyol.transmission.transformer.handler.handlerRegistry +import com.trendyol.transmission.transformer.handler.registerEffect +import com.trendyol.transmission.transformer.handler.registerSignal import com.trendyol.transmission.transformer.request.buildComputationContract import com.trendyol.transmission.transformer.request.buildComputationContractWithArgs import com.trendyol.transmission.transformer.request.buildDataContract @@ -32,20 +34,13 @@ class InputTransformer @Inject constructor( } } - override val signalHandler = buildTypedSignalHandler { signal -> - when (signal) { - is InputSignal.InputUpdate -> { - holder.update { it.copy(writtenText = signal.value) } - publish(effect = InputEffect.InputUpdate(signal.value)) - } + override val handlerRegistry: HandlerRegistry = handlerRegistry { + registerSignal { signal -> + holder.update { it.copy(writtenText = signal.value) } + publish(effect = InputEffect.InputUpdate(signal.value)) } - } - - override val effectHandler = buildGenericEffectHandler { effect -> - when (effect) { - is ColorPickerEffect.BackgroundColorUpdate -> { - holder.update { it.copy(backgroundColor = effect.color) } - } + registerEffect { effect -> + holder.update { it.copy(backgroundColor = effect.color) } } } diff --git a/sample/src/main/java/com/trendyol/transmission/features/multioutput/MultiOutputTransformer.kt b/sample/src/main/java/com/trendyol/transmission/features/multioutput/MultiOutputTransformer.kt index a3a0ee7..729f233 100644 --- a/sample/src/main/java/com/trendyol/transmission/features/multioutput/MultiOutputTransformer.kt +++ b/sample/src/main/java/com/trendyol/transmission/features/multioutput/MultiOutputTransformer.kt @@ -6,7 +6,9 @@ import com.trendyol.transmission.features.input.InputEffect import com.trendyol.transmission.features.output.OutputTransformer import com.trendyol.transmission.transformer.Transformer import com.trendyol.transmission.transformer.dataholder.buildDataHolder -import com.trendyol.transmission.transformer.handler.buildGenericEffectHandler +import com.trendyol.transmission.transformer.handler.HandlerRegistry +import com.trendyol.transmission.transformer.handler.handlerRegistry +import com.trendyol.transmission.transformer.handler.registerEffect import com.trendyol.transmission.transformer.request.createIdentity import com.trendyol.transmission.ui.MultiOutputUiState import kotlinx.coroutines.CoroutineDispatcher @@ -20,23 +22,20 @@ class MultiOutputTransformer @Inject constructor( private val holder = buildDataHolder(MultiOutputUiState()) - override val effectHandler = buildGenericEffectHandler { effect -> - when (effect) { - is InputEffect.InputUpdate -> { - holder.update { it.copy(writtenUppercaseText = effect.value.uppercase()) } - val result = compute(OutputTransformer.outputCalculationContract) - holder.update { - it.copy(writtenUppercaseText = it.writtenUppercaseText + " ${result?.result}") - } - } - - is ColorPickerEffect.BackgroundColorUpdate -> { - holder.update { it.copy(backgroundColor = effect.color) } - } - - is ColorPickerEffect.SelectedColorUpdate -> { - holder.update { it.copy(selectedColor = effect.color) } + override val handlerRegistry: HandlerRegistry = handlerRegistry { + registerEffect { effect -> + holder.update { it.copy(writtenUppercaseText = effect.value.uppercase()) } + val result = compute(OutputTransformer.outputCalculationContract) + holder.update { + it.copy(writtenUppercaseText = it.writtenUppercaseText + " ${result?.result}") } } + registerEffect { effect -> + holder.update { it.copy(backgroundColor = effect.color) } + } + registerEffect { effect -> + holder.update { it.copy(selectedColor = effect.color) } + } } + } diff --git a/sample/src/main/java/com/trendyol/transmission/features/output/OutputTransformer.kt b/sample/src/main/java/com/trendyol/transmission/features/output/OutputTransformer.kt index 39d6bff..4e13738 100644 --- a/sample/src/main/java/com/trendyol/transmission/features/output/OutputTransformer.kt +++ b/sample/src/main/java/com/trendyol/transmission/features/output/OutputTransformer.kt @@ -9,7 +9,9 @@ import com.trendyol.transmission.features.input.InputEffect import com.trendyol.transmission.features.input.InputTransformer import com.trendyol.transmission.transformer.Transformer import com.trendyol.transmission.transformer.dataholder.buildDataHolder -import com.trendyol.transmission.transformer.handler.buildGenericEffectHandler +import com.trendyol.transmission.transformer.handler.HandlerRegistry +import com.trendyol.transmission.transformer.handler.handlerRegistry +import com.trendyol.transmission.transformer.handler.registerEffect import com.trendyol.transmission.transformer.request.buildComputationContract import com.trendyol.transmission.transformer.request.buildExecutionContract import com.trendyol.transmission.transformer.request.computation.registerComputation @@ -47,28 +49,25 @@ class OutputTransformer @Inject constructor( } } - override val effectHandler = buildGenericEffectHandler { effect -> - when (effect) { - is InputEffect.InputUpdate -> { - holder.update { it.copy(outputText = effect.value) } - delay(3.seconds) - val selectedColor = getData(ColorPickerTransformer.holderContract) - selectedColor ?: return@buildGenericEffectHandler - holder.update { - it.copy(outputText = it.outputText + " and Selected color index is ${selectedColor.selectedColorIndex}") - } - delay(1.seconds) - send( - effect = ColorPickerEffect.BackgroundColorUpdate(holder2.getValue().backgroundColor), - identity = colorPickerIdentity - ) - execute(outputExecutionContract) - publish(effect = RouterEffect(holder.getValue())) - } - - is ColorPickerEffect.BackgroundColorUpdate -> { - holder.update { it.copy(backgroundColor = effect.color) } + override val handlerRegistry: HandlerRegistry = handlerRegistry { + registerEffect { effect -> + holder.update { it.copy(outputText = effect.value) } + delay(3.seconds) + val selectedColor = getData(ColorPickerTransformer.holderContract) + selectedColor ?: return@registerEffect + holder.update { + it.copy(outputText = it.outputText + " and Selected color index is ${selectedColor.selectedColorIndex}") } + delay(1.seconds) + send( + effect = ColorPickerEffect.BackgroundColorUpdate(holder2.getValue().backgroundColor), + identity = colorPickerIdentity + ) + execute(outputExecutionContract) + publish(effect = RouterEffect(holder.getValue())) + } + registerEffect { effect -> + holder.update { it.copy(backgroundColor = effect.color) } } } diff --git a/transmission/src/main/java/com/trendyol/transmission/TransmissionRouter.kt b/transmission/src/main/java/com/trendyol/transmission/TransmissionRouter.kt index 91a7c1d..331843b 100644 --- a/transmission/src/main/java/com/trendyol/transmission/TransmissionRouter.kt +++ b/transmission/src/main/java/com/trendyol/transmission/TransmissionRouter.kt @@ -52,7 +52,7 @@ class TransmissionRouter( "transformerSet should not be empty" } routerScope.launch { - transformerSet.map { transformer -> + transformerSet.forEach { transformer -> transformer.run { startSignalCollection(incoming = signalBroadcast.output) startDataPublishing(data = dataBroadcast.producer) diff --git a/transmission/src/main/java/com/trendyol/transmission/router/RequestDelegate.kt b/transmission/src/main/java/com/trendyol/transmission/router/RequestDelegate.kt index 6089589..22b3a4b 100644 --- a/transmission/src/main/java/com/trendyol/transmission/router/RequestDelegate.kt +++ b/transmission/src/main/java/com/trendyol/transmission/router/RequestDelegate.kt @@ -35,7 +35,7 @@ internal class RequestDelegate( init { queryScope.launch { - launch { outGoingQuery.consumeAsFlow().collect { processQuery(it) } } + outGoingQuery.consumeAsFlow().collect { processQuery(it) } } } diff --git a/transmission/src/main/java/com/trendyol/transmission/transformer/Transformer.kt b/transmission/src/main/java/com/trendyol/transmission/transformer/Transformer.kt index acb91e3..167f5dd 100644 --- a/transmission/src/main/java/com/trendyol/transmission/transformer/Transformer.kt +++ b/transmission/src/main/java/com/trendyol/transmission/transformer/Transformer.kt @@ -4,8 +4,7 @@ import com.trendyol.transmission.Transmission import com.trendyol.transmission.effect.EffectWrapper import com.trendyol.transmission.effect.RouterEffect import com.trendyol.transmission.transformer.handler.CommunicationScope -import com.trendyol.transmission.transformer.handler.EffectHandler -import com.trendyol.transmission.transformer.handler.SignalHandler +import com.trendyol.transmission.transformer.handler.HandlerRegistry import com.trendyol.transmission.transformer.request.Contract import com.trendyol.transmission.transformer.request.Query import com.trendyol.transmission.transformer.request.QueryResult @@ -17,6 +16,7 @@ import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job +import kotlinx.coroutines.SupervisorJob import kotlinx.coroutines.cancel import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.channels.SendChannel @@ -26,13 +26,14 @@ import kotlinx.coroutines.flow.filterNot import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.receiveAsFlow import kotlinx.coroutines.launch +import kotlinx.coroutines.supervisorScope open class Transformer( dispatcher: CoroutineDispatcher = Dispatchers.Default, identity: Contract.Identity? = null ) { - val transformerScope = CoroutineScope(dispatcher) + val transformerScope = CoroutineScope(dispatcher + SupervisorJob()) private val internalIdentity: Contract.Identity = identity ?: createIdentity(this::class.simpleName.orEmpty()) @@ -42,8 +43,7 @@ open class Transformer( internal val dataChannel: Channel = Channel(capacity = Channel.BUFFERED) internal val storage = TransformerStorage() - open val signalHandler: SignalHandler? = null - open val effectHandler: EffectHandler? = null + protected open val handlerRegistry: HandlerRegistry? = null protected val executionRegistry: ExecutionRegistry by lazy { ExecutionRegistry(this) } protected val computationRegistry: ComputationRegistry by lazy { ComputationRegistry(this) } @@ -60,10 +60,9 @@ open class Transformer( fun startSignalCollection(incoming: SharedFlow) { transformerScope.launch { incoming.collect { - signalHandler?.apply { - currentSignalProcessing = launch { - communicationScope.onSignal(it) - } + currentSignalProcessing = transformerScope.launch { + handlerRegistry?.signalHandlerRegistry?.get(it::class) + ?.invoke(communicationScope, it) } } } @@ -78,21 +77,22 @@ open class Transformer( incoming: SharedFlow ) { transformerScope.launch { - launch { - incoming - .filterNot { it.effect is RouterEffect } - .filter { it.identity == null || it.identity == internalIdentity } - .map { it.effect } - .collect { - effectHandler?.apply { + supervisorScope { + launch { + incoming + .filterNot { it.effect is RouterEffect } + .filter { it.identity == null || it.identity == internalIdentity } + .map { it.effect } + .collect { currentEffectProcessing = launch { - communicationScope.onEffect(it) + handlerRegistry?.effectHandlerRegistry?.get(it::class) + ?.invoke(communicationScope, it) } } - } - } - launch { - effectChannel.receiveAsFlow().collect { producer.send(it) } + } + launch { + effectChannel.receiveAsFlow().collect { producer.send(it) } + } } } } @@ -102,16 +102,18 @@ open class Transformer( outGoingQuery: SendChannel ) { transformerScope.launch { - launch { - incomingQuery - .filter { it.owner == internalIdentity.key } - .collect { - this@Transformer.requestDelegate.resultBroadcast.producer.trySend(it) + supervisorScope { + launch { + incomingQuery + .filter { it.owner == internalIdentity.key } + .collect { + this@Transformer.requestDelegate.resultBroadcast.producer.trySend(it) + } + } + launch { + this@Transformer.requestDelegate.outGoingQuery.receiveAsFlow().collect { + outGoingQuery.trySend(it) } - } - launch { - this@Transformer.requestDelegate.outGoingQuery.receiveAsFlow().collect { - outGoingQuery.trySend(it) } } } diff --git a/transmission/src/main/java/com/trendyol/transmission/transformer/dataholder/DataHolderExt.kt b/transmission/src/main/java/com/trendyol/transmission/transformer/dataholder/DataHolderExt.kt index e71f740..60a3272 100644 --- a/transmission/src/main/java/com/trendyol/transmission/transformer/dataholder/DataHolderExt.kt +++ b/transmission/src/main/java/com/trendyol/transmission/transformer/dataholder/DataHolderExt.kt @@ -20,7 +20,7 @@ fun Transformer.buildDataHolder( contract: Contract.Data? = null, publishUpdates: Boolean = true ): TransmissionDataHolder { - return TransmissionDataHolderBuilder().buildWith( + return TransmissionDataHolderBuilder.buildWith( initialValue = initialValue, publishUpdates = publishUpdates, transformer = this, diff --git a/transmission/src/main/java/com/trendyol/transmission/transformer/dataholder/TransmissionDataHolder.kt b/transmission/src/main/java/com/trendyol/transmission/transformer/dataholder/TransmissionDataHolder.kt index c631ccf..36539c3 100644 --- a/transmission/src/main/java/com/trendyol/transmission/transformer/dataholder/TransmissionDataHolder.kt +++ b/transmission/src/main/java/com/trendyol/transmission/transformer/dataholder/TransmissionDataHolder.kt @@ -47,5 +47,4 @@ internal class TransmissionDataHolderImpl( override fun update(updater: (T) -> @UnsafeVariance T) { holder.update(updater) } - } diff --git a/transmission/src/main/java/com/trendyol/transmission/transformer/dataholder/TransmissionDataHolderBuilder.kt b/transmission/src/main/java/com/trendyol/transmission/transformer/dataholder/TransmissionDataHolderBuilder.kt index e79dbd7..bcf2ead 100644 --- a/transmission/src/main/java/com/trendyol/transmission/transformer/dataholder/TransmissionDataHolderBuilder.kt +++ b/transmission/src/main/java/com/trendyol/transmission/transformer/dataholder/TransmissionDataHolderBuilder.kt @@ -3,8 +3,9 @@ package com.trendyol.transmission.transformer.dataholder import com.trendyol.transmission.Transmission import com.trendyol.transmission.transformer.Transformer -internal class TransmissionDataHolderBuilder { - fun buildWith( +internal object TransmissionDataHolderBuilder { + + fun buildWith( initialValue: T, publishUpdates: Boolean = true, transformer: Transformer, diff --git a/transmission/src/main/java/com/trendyol/transmission/transformer/handler/EffectHandler.kt b/transmission/src/main/java/com/trendyol/transmission/transformer/handler/EffectHandler.kt deleted file mode 100644 index 80bc133..0000000 --- a/transmission/src/main/java/com/trendyol/transmission/transformer/handler/EffectHandler.kt +++ /dev/null @@ -1,25 +0,0 @@ -package com.trendyol.transmission.transformer.handler - -import com.trendyol.transmission.Transmission - -fun interface EffectHandler { - suspend fun CommunicationScope.onEffect(effect: Transmission.Effect) -} - -fun buildGenericEffectHandler( - onEffect: suspend CommunicationScope.(effect: Transmission.Effect) -> Unit -): EffectHandler { - return EffectHandler { effect -> - onEffect(effect) - } -} - -inline fun buildTypedEffectHandler( - crossinline onEffect: suspend CommunicationScope.(effect: E) -> Unit -): EffectHandler { - return EffectHandler { incomingEffect -> - incomingEffect.takeIf { it is E }?.let { effect -> - onEffect(effect as E) - } - } -} diff --git a/transmission/src/main/java/com/trendyol/transmission/transformer/handler/HandlerRegistry.kt b/transmission/src/main/java/com/trendyol/transmission/transformer/handler/HandlerRegistry.kt new file mode 100644 index 0000000..fed2ee9 --- /dev/null +++ b/transmission/src/main/java/com/trendyol/transmission/transformer/handler/HandlerRegistry.kt @@ -0,0 +1,47 @@ +@file:Suppress("UNCHECKED_CAST") + +package com.trendyol.transmission.transformer.handler + +import com.trendyol.transmission.Transmission +import com.trendyol.transmission.transformer.Transformer +import kotlin.reflect.KClass + +class HandlerScope(val handlerRegistry: HandlerRegistry) + +fun Transformer.handlerRegistry(scope: HandlerScope.() -> Unit): HandlerRegistry { + val handlerRegistry = HandlerRegistry() + HandlerScope(handlerRegistry).apply(scope) + return handlerRegistry +} + +inline fun HandlerScope.registerEffect(noinline lambda: suspend CommunicationScope.(effect: T) -> Unit) { + handlerRegistry.registerEffect(lambda) +} + +inline fun HandlerScope.registerSignal(noinline lambda: suspend CommunicationScope.(signal: T) -> Unit) { + handlerRegistry.registerSignal(lambda) +} + +class HandlerRegistry internal constructor() { + + @PublishedApi + internal val signalHandlerRegistry = + mutableMapOf, suspend CommunicationScope.(effect: Transmission.Signal) -> Unit>() + + @PublishedApi + internal val effectHandlerRegistry = + mutableMapOf, suspend CommunicationScope.(effect: Transmission.Effect) -> Unit>() + + @PublishedApi + internal inline fun registerSignal(noinline lambda: suspend CommunicationScope.(signal: T) -> Unit) { + signalHandlerRegistry[T::class] = + lambda as suspend CommunicationScope.(Transmission.Signal) -> Unit + } + + @PublishedApi + internal inline fun registerEffect(noinline lambda: suspend CommunicationScope.(effect: T) -> Unit) { + effectHandlerRegistry[T::class] = + lambda as suspend CommunicationScope.(Transmission.Effect) -> Unit + } + +} diff --git a/transmission/src/main/java/com/trendyol/transmission/transformer/handler/SignalHandler.kt b/transmission/src/main/java/com/trendyol/transmission/transformer/handler/SignalHandler.kt deleted file mode 100644 index 93d957b..0000000 --- a/transmission/src/main/java/com/trendyol/transmission/transformer/handler/SignalHandler.kt +++ /dev/null @@ -1,21 +0,0 @@ -package com.trendyol.transmission.transformer.handler - -import com.trendyol.transmission.Transmission - -fun interface SignalHandler { - suspend fun CommunicationScope.onSignal(signal: Transmission.Signal) -} - -fun buildGenericSignalHandler( - onSignal: suspend CommunicationScope.(signal: Transmission.Signal) -> Unit -): SignalHandler { - return SignalHandler { signal -> onSignal(signal) } -} - -inline fun buildTypedSignalHandler( - crossinline onSignal: suspend CommunicationScope.(signal: S) -> Unit -): SignalHandler { - return SignalHandler { incomingSignal -> - incomingSignal.takeIf { it is S }?.let { signal -> onSignal(signal as S) } - } -} diff --git a/transmission/src/main/java/com/trendyol/transmission/transformer/request/computation/ComputationOwner.kt b/transmission/src/main/java/com/trendyol/transmission/transformer/request/computation/ComputationOwner.kt index febfe75..ccb8d99 100644 --- a/transmission/src/main/java/com/trendyol/transmission/transformer/request/computation/ComputationOwner.kt +++ b/transmission/src/main/java/com/trendyol/transmission/transformer/request/computation/ComputationOwner.kt @@ -14,5 +14,4 @@ internal sealed interface ComputationOwner { interface Default: ComputationOwner { suspend fun getResult(scope: RequestHandler, invalidate: Boolean = false): Any? } - } diff --git a/transmission/src/main/java/com/trendyol/transmission/transformer/request/computation/ComputationRegistry.kt b/transmission/src/main/java/com/trendyol/transmission/transformer/request/computation/ComputationRegistry.kt index e14ae12..f29026c 100644 --- a/transmission/src/main/java/com/trendyol/transmission/transformer/request/computation/ComputationRegistry.kt +++ b/transmission/src/main/java/com/trendyol/transmission/transformer/request/computation/ComputationRegistry.kt @@ -3,7 +3,7 @@ package com.trendyol.transmission.transformer.request.computation import com.trendyol.transmission.transformer.Transformer import com.trendyol.transmission.transformer.request.RequestHandler -class ComputationRegistry(private val transformer: Transformer) { +class ComputationRegistry internal constructor(private val transformer: Transformer) { internal fun buildWith( key: String, diff --git a/transmission/src/main/java/com/trendyol/transmission/transformer/request/execution/ExecutionRegistry.kt b/transmission/src/main/java/com/trendyol/transmission/transformer/request/execution/ExecutionRegistry.kt index 98c0231..a1af1fc 100644 --- a/transmission/src/main/java/com/trendyol/transmission/transformer/request/execution/ExecutionRegistry.kt +++ b/transmission/src/main/java/com/trendyol/transmission/transformer/request/execution/ExecutionRegistry.kt @@ -3,7 +3,7 @@ package com.trendyol.transmission.transformer.request.execution import com.trendyol.transmission.transformer.Transformer import com.trendyol.transmission.transformer.request.RequestHandler -class ExecutionRegistry(private val transformer: Transformer) { +class ExecutionRegistry internal constructor(private val transformer: Transformer) { internal fun buildWith( key: String, diff --git a/transmission/src/test/kotlin/com/trendyol/transmission/transformer/FakeTransformer.kt b/transmission/src/test/kotlin/com/trendyol/transmission/transformer/FakeTransformer.kt index 4707f49..19d8d68 100644 --- a/transmission/src/test/kotlin/com/trendyol/transmission/transformer/FakeTransformer.kt +++ b/transmission/src/test/kotlin/com/trendyol/transmission/transformer/FakeTransformer.kt @@ -4,25 +4,29 @@ import com.trendyol.transmission.Transmission import com.trendyol.transmission.effect.RouterEffect import com.trendyol.transmission.transformer.data.TestData import com.trendyol.transmission.transformer.data.TestEffect +import com.trendyol.transmission.transformer.data.TestSignal import com.trendyol.transmission.transformer.dataholder.buildDataHolder -import com.trendyol.transmission.transformer.handler.buildGenericEffectHandler -import com.trendyol.transmission.transformer.handler.buildGenericSignalHandler +import com.trendyol.transmission.transformer.handler.HandlerRegistry +import com.trendyol.transmission.transformer.handler.handlerRegistry +import com.trendyol.transmission.transformer.handler.registerEffect +import com.trendyol.transmission.transformer.handler.registerSignal import kotlinx.coroutines.CoroutineDispatcher open class FakeTransformer(dispatcher: CoroutineDispatcher) : Transformer(dispatcher) { - val signalList = mutableListOf() - val effectList = mutableListOf() + val signalList = mutableListOf() + val effectList = mutableListOf() - private val holder = buildDataHolder(null) + private val holder = buildDataHolder(null) - override val signalHandler = buildGenericSignalHandler { signal -> - signalList.add(signal) - publish(TestEffect) - publish(RouterEffect("")) - holder.update { TestData("update with ${this@FakeTransformer.javaClass.simpleName}") } - } - - override val effectHandler = buildGenericEffectHandler { effect -> - effectList.add(effect) - } + override val handlerRegistry: HandlerRegistry = handlerRegistry { + registerSignal { signal -> + signalList.add(signal) + publish(TestEffect) + publish(RouterEffect("")) + holder.update { TestData("update with ${this@FakeTransformer.javaClass.simpleName}") } + } + registerEffect { effect -> + effectList.add(effect) + } + } }