https://kotlinlang.org logo
Title
a

Arkadii Ivanov

10/29/2021, 8:33 PM
Hello everyone! A few times I received feedback that there is some boilerplate when implementing a Store. I have some ideas of how to improve things, but I would like to run a poll first. Could you please vote how do you like the current experience? Thanks! 🙂 - I like the current experience, don't touch! 😐 - Would be good to improve 🙁 - Definitely needs improvement! 🙃 - I don't care
😐 9
a

aiidziis

11/03/2021, 9:34 AM
Can you share your ideas?
a

Arkadii Ivanov

11/03/2021, 9:41 AM
Well, I could not find any way to somehow significantly improve it. Taking into account the following requirements: 1. Compile time safety - if you add e.g. a new Intent, Result, Action, etc. then the code does not compile until covered 2. Logging of communications between store components 3. Time travel This is what I have in mind at the moment, it doesn't even require API changes: https://gist.github.com/arkivanov/77c41c3545fbe81358bd4627c3346506 I will keep thinking about it for a while.
🙏🏻 1
i

iamsteveholmes

01/22/2022, 7:26 PM
I like that a lot! Anything to make it simpler and easier to reason about it a benefit.
a

Arkadii Ivanov

01/22/2022, 7:28 PM
Well, there is no need to change anything. The demonstrated approach can be used with the current API.
I keep thinking about boilerplate concerns when writing stores with MVIKotlin. Got a DSL idea. Pros - less code and classes to write, no need to change the existing APi, fancy Cons - less compile-time safety, worse scalability (e.g. writing a 300 line store) https://pastebin.com/JDLNZqkF
❤️ 1
n

Nikita Klimenko [JB]

04/10/2022, 12:12 PM
Looks neat! You say
less compile-time safety
. From looking at the code i see that building executorFactory is less safe because you could forget to process new intent, right? Is there anything else?
a

Arkadii Ivanov

04/10/2022, 2:39 PM
Yes exactly. You may forget to handle newly added intents or actions.
t

trashcoder

04/10/2022, 5:52 PM
Maybe the MVIKotlin IDEA Plugin could provide an Inspection on unhandled Intents/Actions? Or would it even be possible to configure such Inspection?
a

Arkadii Ivanov

04/10/2022, 8:14 PM
Yeah maybe, not sure yet. If the DSL will be released, I would collect feedback first.
a

aiidziis

04/11/2022, 6:44 AM
Boilerplate can be solved by creating a template for the initial Store setup. Creating just the structure of Store and its Model + Intents. Personally I don't like this DSL approach. As you already pointed out it is less compile-time safe and a lot of developers I know nowadays prefer compile-time safety. If I would present this as a PR to my team, it would most likely get rejected.
a

Arkadii Ivanov

04/11/2022, 8:22 AM
Thanks for the feedback! Templates are indeed good. Please note, the proposed DSL is just an idea and is on top of the existing API. So for example it can be used only in a simple Store implementation.