badoo / MVIKotlin

Extendable MVI framework for Kotlin Multiplatform with powerful debugging tools (logging and time travel), inspired by Badoo MVICore library
https://arkivanov.github.io/MVIKotlin
Apache License 2.0
825 stars 66 forks source link

BypassReducer does nothing #279

Closed dalewking closed 3 years ago

dalewking commented 3 years ago

The bypass reducer seems to me to be completely worthless. The documentation does not really talk about it, but my thought of why you would want to not provide a reducer and just rely on the bypass reducer is when you don't want to create a Result type and your state is so simple that instead of the executor having to send Results that specify how to change the state and can just output the new state directly.

But that is not how the bypass reducer operates. The implementation returns this, which is the current state. It basically does nothing and the output state of the store will never change from its initial state.

So what is the point of the bypass reducer? It would make more sense for me for the bypass reducer to output the object sent from the Executor

arkivanov commented 3 years ago

There is no such a thing BypassReducer, there is a private property bypassReducer defined in the StoreFactory interface. It is private and is used when you don't supply a reducer when creating a Store.

The use case is when your Store does not have any meaningful State: interface SomeStore : Store<Intent, Unit, Label>. Such a Store may handle Intents and do some job with its dependencies, it can also produce Labels. The type of the State is Unit and so it never changes.

dalewking commented 3 years ago

That sounds like a pretty rare use case. I would think the use case of where Result and State are the same object are the same type and you just want to output whatever state the executor outputs as the new state would be more common.

But no matter, I can easily workaround it by setting the reducer to { it }

FYI, my use case where I am running into this is trying to create a MockStore and I just want to feed the new state directly