Last active
November 10, 2022 19:03
-
-
Save arkivanov/34bb84e73e56c22a4e7c752421d5f02c to your computer and use it in GitHub Desktop.
IDEA Live Templates for MVIKotlin Store creation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This IDEA live template generates a dummy Store factory. The name of the Store is | |
Installation: | |
1. Open IDEA preferences -> Editor -> Live Templates | |
2. Create a new group using the "+" button or select an existing group | |
3. Copy the content of the template below and paste it under the selected group (Ctrl+C/Ctrl+V) | |
Usage: | |
1. Create a new Kotlin file with the name "FooStoreFactory.kt", where "Foo" is the name of the Store | |
2. Type "mvisf" and press Enter | |
<template name="mvisf" value="import com.arkivanov.mvikotlin.core.store.Reducer import com.arkivanov.mvikotlin.core.store.Store import com.arkivanov.mvikotlin.core.store.StoreFactory import com.arkivanov.mvikotlin.extensions.reaktive.ReaktiveBootstrapper import com.arkivanov.mvikotlin.extensions.reaktive.ReaktiveExecutor import example.todo.common.main.$name$Store.Intent import example.todo.common.main.$name$Store.Label import example.todo.common.main.$name$Store.State internal class $name$StoreFactory( private val storeFactory: StoreFactory ) { fun create(): $name$Store = object : $name$Store, Store<Intent, State, Label> by storeFactory.create( name = "$name$Store", initialState = State(), bootstrapper = BootstrapperImpl(), executorFactory = ::ExecutorImpl, reducer = ReducerImpl ) {} private sealed interface Action { } private sealed interface Result { } private class BootstrapperImpl : ReaktiveBootstrapper<Action>() { } private class ExecutorImpl : ReaktiveExecutor<Intent, Action, State, Result, Label>() { } private object ReducerImpl : Reducer<State, Result> { override fun State.reduce(result: Result): State = when (result) { } } } " description="MVIKotlin Store factory" toReformat="true" toShortenFQNames="true"> | |
<variable name="name" expression="groovyScript("if (_1.endsWith('StoreFactory')) return _1.substring(0, _1.length() - 12) else return _1", fileNameWithoutExtension())" defaultValue="" alwaysStopAt="true" /> | |
<context> | |
<option name="KOTLIN_TOPLEVEL" value="true" /> | |
</context> | |
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This IDEA live template generates a dummy Store interface. | |
Installation: | |
1. Open IDEA preferences -> Editor -> Live Templates | |
2. Create a new group using the "+" button or select an existing group | |
3. Copy the content of the template below and paste it under the selected group (Ctrl+C/Ctrl+V) | |
Usage: | |
1. Create a new Kotlin file with the required name | |
2. Type "mvisi" and press Enter | |
<template name="mvisi" value="import com.arkivanov.mvikotlin.core.store.Store import example.todo.common.main.$name$Store.Intent import example.todo.common.main.$name$Store.Label import example.todo.common.main.$name$Store.State internal interface $name$Store : Store<Intent, State, Label> { sealed interface Intent { } data class State( ) sealed interface Label { } } " description="MVIKotlin Store interface" toReformat="true" toShortenFQNames="true"> | |
<variable name="name" expression="fileNameWithoutExtension()" defaultValue="" alwaysStopAt="true" /> | |
<context> | |
<option name="KOTLIN_TOPLEVEL" value="true" /> | |
</context> | |
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This IDEA live template generates both a dummy Store interface and its factory. | |
Installation: | |
1. Open IDEA preferences -> Editor -> Live Templates | |
2. Create a new group using the "+" button or select an existing group | |
3. Copy the content of the template below and paste it under the selected group (Ctrl+C/Ctrl+V) | |
Usage: | |
1. Create a new Kotlin file with the required name | |
2. Type "mvis" and press Enter | |
<template name="mvis" value="import com.arkivanov.mvikotlin.core.store.Reducer import com.arkivanov.mvikotlin.core.store.Store import com.arkivanov.mvikotlin.core.store.StoreFactory import com.arkivanov.mvikotlin.extensions.reaktive.ReaktiveBootstrapper import com.arkivanov.mvikotlin.extensions.reaktive.ReaktiveExecutor import example.todo.common.main.$name$Store.Intent import example.todo.common.main.$name$Store.Label import example.todo.common.main.$name$Store.State internal interface $name$Store : Store<Intent, State, Label> { sealed interface Intent { } data class State( ) sealed interface Label { } } internal class SomeStoreFactory( private val storeFactory: StoreFactory ) { fun create(): $name$Store = object : $name$Store, Store<Intent, State, Label> by storeFactory.create( name = "$name$Store", initialState = State(), bootstrapper = BootstrapperImpl(), executorFactory = ::ExecutorImpl, reducer = ReducerImpl ) {} private sealed interface Action { } private sealed interface Result { } private class BootstrapperImpl : ReaktiveBootstrapper<Action>() { } private class ExecutorImpl : ReaktiveExecutor<Intent, Action, State, Result, Label>() { } private object ReducerImpl : Reducer<State, Result> { override fun State.reduce(result: Result): State = when (result) { } } } " description="MVIKotlin Store factory" toReformat="true" toShortenFQNames="true"> | |
<variable name="name" expression="fileNameWithoutExtension()" defaultValue="" alwaysStopAt="true" /> | |
<context> | |
<option name="KOTLIN_TOPLEVEL" value="true" /> | |
</context> | |
</template> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment