Created
March 21, 2019 13:37
-
-
Save jorgecasariego/f86d0ca18c66c0b165c53447d8e21632 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import java.util.* | |
import kotlin.properties.Delegates | |
interface ValueChangedListener { | |
fun onValueChanged(newValue: String) | |
} | |
class PrintingTextChangedListener: ValueChangedListener { | |
override fun onValueChanged(newValue: String) { | |
println("Value of the text is: $newValue") | |
} | |
} | |
class ObservableText(listener: ValueChangedListener) { | |
var text: String by Delegates.observable( | |
initialValue = "", | |
onChange = { | |
property, oldValue, newValue -> | |
listener.onValueChanged(newValue) | |
} | |
) | |
} | |
fun main(args: Array<String>) { | |
val initialObservableObject = ObservableText(PrintingTextChangedListener()) | |
initialObservableObject.text = "Hello" | |
initialObservableObject.text = "World" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment