Skip to content

Instantly share code, notes, and snippets.

@DawnImpulse
Created March 7, 2020 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DawnImpulse/8f3e73f5fd2327c2c9d061b1e08fe800 to your computer and use it in GitHub Desktop.
Save DawnImpulse/8f3e73f5fd2327c2c9d061b1e08fe800 to your computer and use it in GitHub Desktop.
a live variable of any type in kotlin which actively listens and propagates change to it
package com.dawnimpulse.wallup.utils.reusables
import kotlin.properties.Delegates
class Live<T>(private val value1: T) {
private lateinit var change: (T) -> Unit
var value: T by Delegates.observable(value1) { _, _, new ->
if (::change.isInitialized)
change(new)
}
fun onChange(change: (T) -> Unit) {
this.change = change
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment