-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from Trendyol/handler-api-v2
Handler api v2
- Loading branch information
Showing
9 changed files
with
137 additions
and
147 deletions.
There are no files selected for viewing
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
25 changes: 0 additions & 25 deletions
25
transmission/src/main/java/com/trendyol/transmission/transformer/handler/EffectHandler.kt
This file was deleted.
Oops, something went wrong.
47 changes: 47 additions & 0 deletions
47
transmission/src/main/java/com/trendyol/transmission/transformer/handler/HandlerRegistry.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,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 <reified T : Transmission.Effect> HandlerScope.registerEffect(noinline lambda: suspend CommunicationScope.(effect: T) -> Unit) { | ||
handlerRegistry.registerEffect<T>(lambda) | ||
} | ||
|
||
inline fun <reified T : Transmission.Signal> HandlerScope.registerSignal(noinline lambda: suspend CommunicationScope.(signal: T) -> Unit) { | ||
handlerRegistry.registerSignal<T>(lambda) | ||
} | ||
|
||
class HandlerRegistry internal constructor() { | ||
|
||
@PublishedApi | ||
internal val signalHandlerRegistry = | ||
mutableMapOf<KClass<out Transmission.Signal>, suspend CommunicationScope.(effect: Transmission.Signal) -> Unit>() | ||
|
||
@PublishedApi | ||
internal val effectHandlerRegistry = | ||
mutableMapOf<KClass<out Transmission.Effect>, suspend CommunicationScope.(effect: Transmission.Effect) -> Unit>() | ||
|
||
@PublishedApi | ||
internal inline fun <reified T : Transmission.Signal> registerSignal(noinline lambda: suspend CommunicationScope.(signal: T) -> Unit) { | ||
signalHandlerRegistry[T::class] = | ||
lambda as suspend CommunicationScope.(Transmission.Signal) -> Unit | ||
} | ||
|
||
@PublishedApi | ||
internal inline fun <reified T : Transmission.Effect> registerEffect(noinline lambda: suspend CommunicationScope.(effect: T) -> Unit) { | ||
effectHandlerRegistry[T::class] = | ||
lambda as suspend CommunicationScope.(Transmission.Effect) -> Unit | ||
} | ||
|
||
} |
21 changes: 0 additions & 21 deletions
21
transmission/src/main/java/com/trendyol/transmission/transformer/handler/SignalHandler.kt
This file was deleted.
Oops, something went wrong.
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