Skip to content

Commit 0fe8741

Browse files
fragarsiefragarsie
authored andcommitted
Fix code generation for multiple stores related to the same action
1 parent af75567 commit 0fe8741

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

mini-processor/src/main/java/mini/processor/ActionReducerModel.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import javax.tools.StandardLocation
88
const val DEBUG_MODE = false
99

1010
class ActionReducerModel(reducerFunctions: List<ReducerFuncModel>) {
11-
private val reducersMaps = mutableMapOf<ActionModel, MutableList<ReducerFuncModel>>()
11+
private val reducersMaps = mutableMapOf<String, MutableList<ReducerFuncModel>>()
1212
private val stores: List<StoreModel>
1313

1414
companion object {
@@ -23,11 +23,12 @@ class ActionReducerModel(reducerFunctions: List<ReducerFuncModel>) {
2323
logMessage(Diagnostic.Kind.NOTE, "Filtering actions")
2424
//Reverse the map for code-gen
2525
reducerFunctions
26-
.forEach { reducersMaps.getOrPut(it.action) { ArrayList() }.add(it) }
26+
.forEach { reducersMaps.getOrPut(it.action.actionName) { ArrayList() }.add(it) }
2727
logMessage(Diagnostic.Kind.NOTE, "${reducerFunctions.size} Actions retrieved. Starting stores mapping")
2828
stores = reducersMaps.values
2929
.flatten()
30-
.distinctBy { it.parentClass.toString() }.map { StoreModel(it.parentClass) }
30+
.distinctBy { it.parentClass.toString() }
31+
.map { StoreModel(it.parentClass) }
3132
}
3233

3334
fun generateDispatcherFile() {
@@ -75,12 +76,11 @@ class ActionReducerModel(reducerFunctions: List<ReducerFuncModel>) {
7576
"action.tags.forEach { tag ->",
7677
"%>when (tag) {%>", ""))
7778
reducersMaps
78-
.map { ReduceBlockModel(it.key, it.value) }
79+
.map { ReduceBlockModel(it.value[0].action, it.value) }
7980
.forEach { reduceBlock ->
8081
val actionClass = ClassName(reduceBlock.action.packageName, reduceBlock.action.actionName)
8182
addCode(CodeBlock.of("%T::class.java -> {\n%>action as %T\n", actionClass, actionClass))
82-
addCode(reduceBlock.methodCalls
83-
.joinToString(separator = "\n") { it.methodCall })
83+
addCode(reduceBlock.methodCalls.joinToString(separator = "\n") { it.methodCall })
8484
addCode(linesOfCode("%<", "}", ""))
8585
}
8686
addCode(linesOfCode("%<", "}%<", "}", ""))

0 commit comments

Comments
 (0)