Open
Conversation
…nt signals/effects
… add type aware handler scope addition
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Currently, Transmission Library offers inheritance based signal and effect override/extension mechanism.
This MR Introduces a
TransformerModulewhich can be added to any Transformer byapplyModuleorapplyModules.The most important change proposed is the refactor of HandlerRegistry. Each signal or effect now can contain multiple
StackedLambda's.If you define a handler logic to a super type, like
Transmission.Signal, it will be applied to every signal defined in that Transformer.Here is the Module:
Here is an example Implementation
If we apply this module, and set TransformerConfig to
TypeAware, all the signals and effects inside the Transformer will also be able to execute the handler logicHere is an updated SignalHandler addition implementation which accounts for type aware signals and effects
@PublishedApi internal fun <T : Transmission.Signal> addSignalHandler( signalClass: KClass<T>, sourceClass: KClass<*>, handler: suspend CommunicationScope.(signal: T) -> Unit ) { // Create a new stacked lambda for this handler val stackedLambda = StackedLambda<Transmission.Signal>() @Suppress("UNCHECKED_CAST") stackedLambda.addOperation(handler as SignalLambda) // Create the identified handler val identifiedHandler = IdentifiedHandler(sourceClass, stackedLambda) // Register the handler for the specified signal class signalHandlerRegistry.getOrPut(signalClass) { mutableListOf() }.add(identifiedHandler) // If type hierarchy awareness is enabled, register for subtypes too if (config.typeHierarchyAwarenessEnabled) { // Find all registered subclasses of this signal class and register the handler for them too // Only do this for supertypes, not for specific types for (registeredClass in signalHandlerRegistry.keys.toList()) { if (registeredClass != signalClass && registeredClass.isSubclassOf(signalClass)) { // For each subclass, add this handler val subclassHandlers = signalHandlerRegistry.getOrPut(registeredClass) { mutableListOf() } // Create a new stacked lambda with the same operation val subclassStackedLambda = StackedLambda<Transmission.Signal>() @Suppress("UNCHECKED_CAST") subclassStackedLambda.addOperation(handler as SignalLambda) // Add as a new identified handler subclassHandlers.add(IdentifiedHandler(sourceClass, subclassStackedLambda)) } } } }