From 0fe87415990e7e258623b8b2bf871c7b940a92cb Mon Sep 17 00:00:00 2001 From: fragarsie Date: Mon, 2 Jul 2018 17:06:29 +0200 Subject: [PATCH] Fix code generation for multiple stores related to the same action --- .../main/java/mini/processor/ActionReducerModel.kt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/mini-processor/src/main/java/mini/processor/ActionReducerModel.kt b/mini-processor/src/main/java/mini/processor/ActionReducerModel.kt index 6bdb5ae..54cf9bf 100644 --- a/mini-processor/src/main/java/mini/processor/ActionReducerModel.kt +++ b/mini-processor/src/main/java/mini/processor/ActionReducerModel.kt @@ -8,7 +8,7 @@ import javax.tools.StandardLocation const val DEBUG_MODE = false class ActionReducerModel(reducerFunctions: List) { - private val reducersMaps = mutableMapOf>() + private val reducersMaps = mutableMapOf>() private val stores: List companion object { @@ -23,11 +23,12 @@ class ActionReducerModel(reducerFunctions: List) { logMessage(Diagnostic.Kind.NOTE, "Filtering actions") //Reverse the map for code-gen reducerFunctions - .forEach { reducersMaps.getOrPut(it.action) { ArrayList() }.add(it) } + .forEach { reducersMaps.getOrPut(it.action.actionName) { ArrayList() }.add(it) } logMessage(Diagnostic.Kind.NOTE, "${reducerFunctions.size} Actions retrieved. Starting stores mapping") stores = reducersMaps.values .flatten() - .distinctBy { it.parentClass.toString() }.map { StoreModel(it.parentClass) } + .distinctBy { it.parentClass.toString() } + .map { StoreModel(it.parentClass) } } fun generateDispatcherFile() { @@ -75,12 +76,11 @@ class ActionReducerModel(reducerFunctions: List) { "action.tags.forEach { tag ->", "%>when (tag) {%>", "")) reducersMaps - .map { ReduceBlockModel(it.key, it.value) } + .map { ReduceBlockModel(it.value[0].action, it.value) } .forEach { reduceBlock -> val actionClass = ClassName(reduceBlock.action.packageName, reduceBlock.action.actionName) addCode(CodeBlock.of("%T::class.java -> {\n%>action as %T\n", actionClass, actionClass)) - addCode(reduceBlock.methodCalls - .joinToString(separator = "\n") { it.methodCall }) + addCode(reduceBlock.methodCalls.joinToString(separator = "\n") { it.methodCall }) addCode(linesOfCode("%<", "}", "")) } addCode(linesOfCode("%<", "}%<", "}", ""))