Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
yigitozgumus committed Aug 14, 2024
2 parents ae9cfb4 + 12f1989 commit f7df530
Show file tree
Hide file tree
Showing 34 changed files with 467 additions and 349 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.lifecycle.viewModelScope
import com.trendyol.transmission.effect.RouterEffect
import com.trendyol.transmission.features.colorpicker.ColorPickerTransformer
import com.trendyol.transmission.features.input.InputTransformer
import com.trendyol.transmission.router.TransmissionRouter
import com.trendyol.transmission.router.onEach
import com.trendyol.transmission.router.toState
import com.trendyol.transmission.ui.ColorPickerUiState
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.trendyol.transmission.features

import com.trendyol.transmission.TransmissionRouter
import com.trendyol.transmission.router.TransmissionRouter
import com.trendyol.transmission.features.colorpicker.ColorPickerTransformer
import com.trendyol.transmission.features.input.InputTransformer
import com.trendyol.transmission.features.multioutput.MultiOutputTransformer
Expand Down Expand Up @@ -44,7 +44,7 @@ interface FeaturesModule {
transformerSet: @JvmSuppressWildcards Set<Transformer>
): TransmissionRouter {
return TransmissionRouterBuilder.build {
withTransformerSet(transformerSet)
addTransformerSet(transformerSet)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,28 @@ package com.trendyol.transmission.features.colorpicker
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.dataholder.dataHolder
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.transformer.handler.onEffect
import com.trendyol.transmission.transformer.handler.handlers
import com.trendyol.transmission.transformer.handler.onSignal
import com.trendyol.transmission.transformer.request.Contracts
import com.trendyol.transmission.transformer.request.dataHolder
import com.trendyol.transmission.transformer.request.identity
import com.trendyol.transmission.ui.ColorPickerUiState
import kotlinx.coroutines.CoroutineDispatcher
import javax.inject.Inject

val colorPickerIdentity = createIdentity("ColorPicker")
val colorPickerIdentity = Contracts.identity("ColorPicker")

class ColorPickerTransformer @Inject constructor(
@DefaultDispatcher private val defaultDispatcher: CoroutineDispatcher
) : Transformer(defaultDispatcher, colorPickerIdentity) {

private val holder = buildDataHolder(ColorPickerUiState(), holderContract)
private val holder = dataHolder(ColorPickerUiState(), holderContract)

override val handlerRegistry: HandlerRegistry = handlerRegistry {
registerSignal<ColorPickerSignal.SelectColor> { signal ->
override val handlers: HandlerRegistry = handlers {
onSignal<ColorPickerSignal.SelectColor> { signal ->
holder.update { it.copy(selectedColorIndex = signal.index) }
publish(
ColorPickerEffect.BackgroundColorUpdate(signal.selectedColor.copy(alpha = 0.1f))
Expand All @@ -33,14 +34,14 @@ class ColorPickerTransformer @Inject constructor(
identity = multiOutputTransformerIdentity
)
}
registerEffect<ColorPickerEffect.BackgroundColorUpdate> { effect ->
onEffect<ColorPickerEffect.BackgroundColorUpdate> { effect ->
holder.update {
it.copy(backgroundColor = effect.color)
}
}
}

companion object {
val holderContract = buildDataContract<ColorPickerUiState>("ColorPickerUiState")
val holderContract = Contracts.dataHolder<ColorPickerUiState>("ColorPickerUiState")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@ package com.trendyol.transmission.features.input
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.dataholder.dataHolder
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
import com.trendyol.transmission.transformer.handler.onEffect
import com.trendyol.transmission.transformer.handler.handlers
import com.trendyol.transmission.transformer.handler.onSignal
import com.trendyol.transmission.transformer.request.Contracts
import com.trendyol.transmission.transformer.request.computation
import com.trendyol.transmission.transformer.request.computation.ComputationRegistry
import com.trendyol.transmission.transformer.request.computation.computationRegistry
import com.trendyol.transmission.transformer.request.computation.registerComputation
import com.trendyol.transmission.transformer.request.computation.computations
import com.trendyol.transmission.transformer.request.computation.register
import com.trendyol.transmission.transformer.request.computationWithArgs
import com.trendyol.transmission.transformer.request.dataHolder
import com.trendyol.transmission.ui.InputUiState
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.delay
Expand All @@ -24,32 +25,32 @@ class InputTransformer @Inject constructor(
@DefaultDispatcher private val defaultDispatcher: CoroutineDispatcher
) : Transformer(defaultDispatcher) {

private val holder = buildDataHolder(InputUiState(), holderContract)
private val holder = dataHolder(InputUiState(), holderContract)

override val computationRegistry: ComputationRegistry = computationRegistry {
registerComputation(writtenInputContract) {
override val computations: ComputationRegistry = computations {
register(writtenInputContract) {
delay(1.seconds)
WrittenInput(holder.getValue().writtenText)
}
registerComputation(writtenInputWithArgs) {
register(writtenInputWithArgs) {
WrittenInput(it)
}
}

override val handlerRegistry: HandlerRegistry = handlerRegistry {
registerSignal<InputSignal.InputUpdate> { signal ->
override val handlers: HandlerRegistry = handlers {
onSignal<InputSignal.InputUpdate> { signal ->
holder.update { it.copy(writtenText = signal.value) }
publish(effect = InputEffect.InputUpdate(signal.value))
}
registerEffect<ColorPickerEffect.BackgroundColorUpdate> { effect ->
onEffect<ColorPickerEffect.BackgroundColorUpdate> { effect ->
holder.update { it.copy(backgroundColor = effect.color) }
}
}

companion object {
val writtenInputWithArgs =
buildComputationContractWithArgs<String, WrittenInput>("WrittenInputWithArgs")
val writtenInputContract = buildComputationContract<WrittenInput>("WrittenInput")
val holderContract = buildDataContract<InputUiState>("InputUiState")
Contracts.computationWithArgs<String, WrittenInput>("WrittenInputWithArgs")
val writtenInputContract = Contracts.computation<WrittenInput>("WrittenInput")
val holderContract = Contracts.dataHolder<InputUiState>("InputUiState")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,36 @@ import com.trendyol.transmission.features.colorpicker.ColorPickerEffect
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.dataholder.dataHolder
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.transformer.handler.onEffect
import com.trendyol.transmission.transformer.handler.handlers
import com.trendyol.transmission.transformer.request.Contracts
import com.trendyol.transmission.transformer.request.identity
import com.trendyol.transmission.ui.MultiOutputUiState
import kotlinx.coroutines.CoroutineDispatcher
import javax.inject.Inject

val multiOutputTransformerIdentity = createIdentity("MultiOutput")
val multiOutputTransformerIdentity = Contracts.identity("MultiOutput")

class MultiOutputTransformer @Inject constructor(
@DefaultDispatcher private val defaultDispatcher: CoroutineDispatcher
) : Transformer(defaultDispatcher, multiOutputTransformerIdentity) {

private val holder = buildDataHolder(MultiOutputUiState())
private val holder = dataHolder(MultiOutputUiState())

override val handlerRegistry: HandlerRegistry = handlerRegistry {
registerEffect<InputEffect.InputUpdate> { effect ->
override val handlers: HandlerRegistry = handlers {
onEffect<InputEffect.InputUpdate> { effect ->
holder.update { it.copy(writtenUppercaseText = effect.value.uppercase()) }
val result = compute(OutputTransformer.outputCalculationContract)
holder.update {
it.copy(writtenUppercaseText = it.writtenUppercaseText + " ${result?.result}")
}
}
registerEffect<ColorPickerEffect.BackgroundColorUpdate> { effect ->
onEffect<ColorPickerEffect.BackgroundColorUpdate> { effect ->
holder.update { it.copy(backgroundColor = effect.color) }
}
registerEffect<ColorPickerEffect.SelectedColorUpdate> { effect ->
onEffect<ColorPickerEffect.SelectedColorUpdate> { effect ->
holder.update { it.copy(selectedColor = effect.color) }
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,19 @@ import com.trendyol.transmission.features.colorpicker.colorPickerIdentity
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.dataholder.dataHolder
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.handler.onEffect
import com.trendyol.transmission.transformer.handler.handlers
import com.trendyol.transmission.transformer.request.Contracts
import com.trendyol.transmission.transformer.request.computation
import com.trendyol.transmission.transformer.request.computation.ComputationRegistry
import com.trendyol.transmission.transformer.request.computation.computationRegistry
import com.trendyol.transmission.transformer.request.computation.registerComputation
import com.trendyol.transmission.transformer.request.computation.computations
import com.trendyol.transmission.transformer.request.computation.register
import com.trendyol.transmission.transformer.request.execution
import com.trendyol.transmission.transformer.request.execution.ExecutionRegistry
import com.trendyol.transmission.transformer.request.execution.executionRegistry
import com.trendyol.transmission.transformer.request.execution.registerExecution
import com.trendyol.transmission.transformer.request.execution.executions
import com.trendyol.transmission.transformer.request.execution.register
import com.trendyol.transmission.ui.ColorPickerUiState
import com.trendyol.transmission.ui.OutputUiState
import com.trendyol.transmission.ui.theme.Pink80
Expand All @@ -34,12 +35,12 @@ class OutputTransformer @Inject constructor(
@DefaultDispatcher private val defaultDispatcher: CoroutineDispatcher
) : Transformer(defaultDispatcher) {

private val holder = buildDataHolder(OutputUiState())
private val holder = dataHolder(OutputUiState())

private val holder2 = buildDataHolder(ColorPickerUiState(), publishUpdates = false)
private val holder2 = dataHolder(ColorPickerUiState(), publishUpdates = false)

override val computationRegistry: ComputationRegistry = computationRegistry {
registerComputation(outputCalculationContract) {
override val computations: ComputationRegistry = computations {
register(outputCalculationContract) {
delay(2.seconds)
val data = getData(ColorPickerTransformer.holderContract)?.selectedColorIndex
val writtenOutput = compute(InputTransformer.writtenInputContract)
Expand All @@ -48,8 +49,8 @@ class OutputTransformer @Inject constructor(
}
}

override val executionRegistry: ExecutionRegistry = executionRegistry {
registerExecution(outputExecutionContract) {
override val executions: ExecutionRegistry = executions {
register(outputExecutionContract) {
delay(4.seconds)
communicationScope.publish(ColorPickerEffect.BackgroundColorUpdate(Pink80))
throw RuntimeException(
Expand All @@ -59,12 +60,12 @@ class OutputTransformer @Inject constructor(
}
}

override val handlerRegistry: HandlerRegistry = handlerRegistry {
registerEffect<InputEffect.InputUpdate> { effect ->
override val handlers: HandlerRegistry = handlers {
onEffect<InputEffect.InputUpdate> { effect ->
holder.update { it.copy(outputText = effect.value) }
delay(3.seconds)
val selectedColor = getData(ColorPickerTransformer.holderContract)
selectedColor ?: return@registerEffect
selectedColor ?: return@onEffect
holder.update {
it.copy(outputText = it.outputText + " and Selected color index is ${selectedColor.selectedColorIndex}")
}
Expand All @@ -76,7 +77,7 @@ class OutputTransformer @Inject constructor(
execute(outputExecutionContract)
publish(effect = RouterEffect(holder.getValue()))
}
registerEffect<ColorPickerEffect.BackgroundColorUpdate> { effect ->
onEffect<ColorPickerEffect.BackgroundColorUpdate> { effect ->
holder.update { it.copy(backgroundColor = effect.color) }
}
}
Expand All @@ -89,8 +90,8 @@ class OutputTransformer @Inject constructor(
companion object {
private const val TAG = "OutputTransformer"
val outputCalculationContract =
buildComputationContract<OutputCalculationResult>("OutputCalculationResult")
Contracts.computation<OutputCalculationResult>("OutputCalculationResult")
val outputExecutionContract =
buildExecutionContract("outputExecutionContract")
Contracts.execution("outputExecutionContract")
}
}
2 changes: 1 addition & 1 deletion transmission-test/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ publishing {
create<MavenPublication>("release") {
groupId = "com.trendyol"
artifactId = "transmission-test"
version = "1.1.0"
version = "1.2.0"
afterEvaluate {
from(components["java"])
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.trendyol.transmissiontest

import com.trendyol.transmission.Transmission
import com.trendyol.transmission.TransmissionRouter
import com.trendyol.transmission.router.TransmissionRouter
import com.trendyol.transmission.router.RegistryScope
import com.trendyol.transmission.router.builder.TransmissionTestingRouterBuilder
import com.trendyol.transmission.transformer.Transformer
Expand Down Expand Up @@ -42,8 +42,8 @@ class TestSuite {
scope: suspend TransformerTestScope.(scope: TestScope) -> Unit
) {
router = TransmissionTestingRouterBuilder.build {
withDispatcher(UnconfinedTestDispatcher())
this@TestSuite.transformer?.let { withTransformerSet(setOf(it)) }
addDispatcher(UnconfinedTestDispatcher())
this@TestSuite.transformer?.let { addTransformerSet(setOf(it)) }
testing(this@TestSuite.registryScope)
}

Expand Down
2 changes: 1 addition & 1 deletion transmission/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ publishing {
create<MavenPublication>("release") {
groupId = "com.trendyol"
artifactId = "transmission"
version = "1.1.0"
version = "1.2.0"
afterEvaluate {
from(components["java"])
}
Expand Down
Loading

0 comments on commit f7df530

Please sign in to comment.