Skip to content

Commit

Permalink
Merge pull request #27 from pardom/composite-dispatcher-cleanup
Browse files Browse the repository at this point in the history
Normalize naming. Don't enforce single dispatcher. Formatting.
  • Loading branch information
pardom committed May 2, 2016
2 parents 9fd4291 + ed98b2e commit 5e4d5dc
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions android/src/main/kotlin/clean/news/flow/CompositeDispatcher.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import flow.TraversalCallback
import kotlin.reflect.KClass

class CompositeDispatcher : KeyChanger() {
private val dispatchers = mutableMapOf<KClass<*>, KeyChanger>()
private val dispatchers = mutableMapOf<KClass<out Any>, KeyChanger>()

fun addDispatcher(clz: KClass<*>, dispatcher: KeyChanger) {
dispatchers.put(clz, dispatcher)
fun addDispatcher(cls: KClass<out Any>, dispatcher: KeyChanger) {
dispatchers.put(cls, dispatcher)
}

override fun changeKey(
Expand All @@ -20,17 +20,11 @@ class CompositeDispatcher : KeyChanger() {
incomingContexts: MutableMap<Any, Context>,
callback: TraversalCallback) {

val destination: Any = incomingState.getKey()
val destination = incomingState.getKey<Any>()

for ((cls, dispatcher) in dispatchers) {
if (cls.java.isAssignableFrom(destination.javaClass)) {
dispatcher.changeKey(
outgoingState,
incomingState,
direction,
incomingContexts,
callback)
return
dispatcher.changeKey(outgoingState, incomingState, direction, incomingContexts, callback)
}
}
}
Expand Down

0 comments on commit 5e4d5dc

Please sign in to comment.