Kotlin reactive library inspired by Vue.js. It seeks to provide reactive primitives to kotlin for building functionally coupled systems.
In your build.gradle.kts
file:
repositories {
//...
maven { url = URI("https://jitpack.io") }
}
dependencies {
implementation("com.github.bendgk:effekt:1.0.0")
}
EffeKt brings the following reactive primitives from vue to kotlin:
A ref is a reactive primitive that can be read and written to. Ref's store a single value and a list of subscribers. When a ref is used as a dependency of another primitive (such as computed
or watchEffect
), that primitive is added as a subscriber to that ref.
when a ref is updated we need to update all the subscribers too.
A computed is a reactive primitive that can only be read. Whenever a computed value is read its value is recomputed according to its dependencies.
watchEffect is a reactive helper function that can watch dependencies for changes. It runs the given side effect when a dependency change occurs.
var price by ref(2.00)
var quantity by ref(1000)
val revenue by computed { price * quantity }
watchEffect {
println("revenue: $revenue")
}
price /= 2
price *= 10
quantity += 500
Output:
> revenue: 2000.0
> revenue: 1000.0
> revenue: 10000.0
> revenue: 15000.0