Skip to content

Instantly share code, notes, and snippets.

View fvilarino's full-sized avatar

Francesc Vilariño Güell fvilarino

View GitHub Profile
@fvilarino
fvilarino / stability_stable_classes.txt
Created November 29, 2023 23:14
Stability - Stable Classes
stable class State {
stable val value: Int
stable val prompt: String
stable val values: Set<Int>
stable val prompts: List<String>
<runtime stability> =
}
@fvilarino
fvilarino / stability_adding_stability_argument.kts
Created November 29, 2023 23:10
Stability - Adding Stability Argument
kotlinOptions {
val composeReportsDir = "compose_reports"
// 1
freeCompilerArgs += listOf(
"-P",
"plugin:androidx.compose.compiler.plugins.kotlin:stabilityConfigurationPath=$rootDir/stability-config.txt"
)
freeCompilerArgs += listOf(
"-P",
@fvilarino
fvilarino / stability_unstable_composables.txt
Last active November 29, 2023 23:00
Stability - Unstable Composables
restartable scheme("[androidx.compose.ui.UiComposable]") fun SampleUi(
unstable state: State
)
restartable skippable scheme("[androidx.compose.ui.UiComposable]") fun PrimitivesMethod(
stable value: Int
stable prompt: String
stable modifier: Modifier? = @static Companion
)
restartable scheme("[androidx.compose.ui.UiComposable]") fun CollectionsMethod(
unstable values: Set<Int>
@fvilarino
fvilarino / stability_unstable_classes.txt
Created November 29, 2023 22:55
Stability - Unstable Classes
unstable class State {
stable val value: Int
stable val prompt: String
unstable val values: Set<Int>
unstable val prompts: List<String>
<runtime stability> = Unstable
}
@fvilarino
fvilarino / stability_sample_code.kt
Last active November 30, 2023 01:48
Stability - Sample Code
// 1
data class State(
val value: Int,
val prompt: String,
val values: Set<Int>,
val prompts: List<String>,
)
// 2
@Composable
@fvilarino
fvilarino / stability_reports_compiler_flag.kts
Created November 29, 2023 22:32
Stability - Reports Compiler Flag
kotlinOptions {
// 1
val composeReportsDir = "compose_reports"
// 2
freeCompilerArgs += listOf(
// 3
"-P",
"plugin:androidx.compose.compiler.plugins.kotlin:reportsDestination=" +
project.layout.buildDirectory.get().dir(composeReportsDir).asFile.absolutePath,
@fvilarino
fvilarino / mvi_framework_updated_counter_screen.kt
Created September 18, 2023 20:50
MVI Framework - Updated Counter Screen
@Composable
fun CounterScreen(
state: CounterState,
onDecreaseClick: () -> Unit,
onIncreaseClick: () -> Unit,
onGenerateRandom: () -> Unit,
modifier: Modifier = Modifier,
) {
Box(
contentAlignment = Alignment.Center,
@fvilarino
fvilarino / mvi_framework_upadted_counter_middleware.kt
Created September 18, 2023 20:42
MVI Framework - Updated Counter Middleware
class CounterViewModel(
// 1
middleware: CounterMiddleware = CounterMiddleware(),
reducer: CounterReducer = CounterReducer(),
) : MviViewModel<CounterState, CounterAction>(
reducer = reducer,
// 2
middlewares = listOf(middleware),
initialState = CounterState.initial,
) {
@fvilarino
fvilarino / mvi_framework_updated_reducer.kt
Created September 18, 2023 20:38
MVI Framework - Updated Reducer
class CounterReducer : Reducer<CounterState, CounterAction> {
override fun reduce(state: CounterState, action: CounterAction): CounterState {
return when (action) {
// 1
CounterAction.Loading -> state.copy(loading = true)
CounterAction.Decrement -> state.copy(counter = state.counter - 1)
CounterAction.Increment -> state.copy(counter = state.counter + 1)
// 2
is CounterAction.CounterUpdated -> state.copy(
@fvilarino
fvilarino / mvi_framework_counter_middleware.kt
Last active September 18, 2023 20:49
MVI Framework - Counter Middleware
// 1
class CounterMiddleware : Middleware<CounterState, CounterAction>() {
// 2
override suspend fun process(state: CounterState, action: CounterAction) {
// 3
when (action) {
CounterAction.GenerateRandom -> generateRandom()
else -> { /* no-op */ }
}