Created
May 6, 2022 19:31
-
-
Save herrbert74/509fad657708a8e7bb7edfbdb3162605 to your computer and use it in GitHub Desktop.
MVIKotlin Store Interface
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. | |
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.coroutines.CoroutineBootstrapper import com.arkivanov.mvikotlin.extensions.coroutines.CoroutineExecutor import $package$.$name$Store.Intent import $package$.$name$Store.Label import $package$.$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 : CoroutineBootstrapper<Action>() { } private class ExecutorImpl : CoroutineExecutor<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="package" expression="kotlinPackageName()" defaultValue="" alwaysStopAt="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 $package$.$name$.Intent import $package$.$name$.Label import $package$.$name$.State internal interface $name$ : Store<Intent, State, Label> { sealed interface Intent { } data class State( ) sealed interface Label { } } " description="MVIKotlin Store interface" toReformat="true" toShortenFQNames="true"> | |
<variable name="package" expression="kotlinPackageName()" defaultValue="" alwaysStopAt="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