Created
March 7, 2020 14:16
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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