Skip to content

bendgk/effekt

Repository files navigation

EffeKt logo

Kotlin

EffeKt

Kotlin reactive library inspired by Vue.js. It seeks to provide reactive primitives to kotlin for building functionally coupled systems.

Quick Start

In your build.gradle.kts file:

repositories {
    //...
    maven { url = URI("https://jitpack.io") }
}

dependencies {
    implementation("com.github.bendgk:effekt:1.0.0")
}

Usage

EffeKt brings the following reactive primitives from vue to kotlin:

ref

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.

computed

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

watchEffect is a reactive helper function that can watch dependencies for changes. It runs the given side effect when a dependency change occurs.

Example

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

About

Kotlin reactive library (inspired by Vue.js)

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages