Annotate your data class
:
@AutoEmit
data class SignupForm(
val name: String? = null,
val favoriteColor: Color? = null,
)
Create a StateFlow
using the generated .emitter()
method:
val signupFormState = SignupForm().emitter()
Mutate any field and get emissions:
signupFormState.name = "Collin"
signupFormState.favoriteColor = Color.Red
// state flow emissions ->
// SignupForm(name = null, favoriteColor = null)
// SignupForm(name = "Collin", favoriteColor = null)
// SignupForm(name = "Collin", favoriteColor = Color.Red)
auto-emit
is available through Github Packages
.
Follow the standard instructions in the Github Documentation for how to add Github Packages as a remote maven repo.
For example,
repositories {
maven {
url = uri("https://maven.pkg.github.com/livefront/auto-emit")
credentials {
// supply your local machine credentials through a git-ignored properties file,
// environment variables, or through any other means you prefer.
// Never commit credentials to git.
username = project.findProperty("gpr.user") as String? ?: System.getenv("USERNAME")
password = project.findProperty("gpr.key") as String? ?: System.getenv("TOKEN")
}
}
}
Apply the ksp
plugin
plugins {
id("com.google.devtools.ksp") version "2.1.0-1.0.29"
}
Add auto-emit
in your dependencies block
implementation("com.github.livefront.auto-emit:annotation:0.1.0")
ksp("com.github.livefront.auto-emit:generate:0.1.0")
-
Avoid needing verbose
combine()
calls on many flows:val nameState = MutableStateFlow<String?>(null) val colorState = MutableStateFlow<Color?>(null) // ... and more values you need to track combine(nameState, colorState, /*...*/) { name, color, /* more and more fields */ -> handleChanges(name, color, /*...*/) }
-
Avoid lengthy copy/assignments that obscure changes:
state.value = state.value.copy(/*...*/)
Copyright 2025 Livefront
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.