Skip to content

Instantly share code, notes, and snippets.

@Lamartio
Last active September 24, 2018 07:33
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 Lamartio/b3dc52bfaf7e7c6aab3e563c8d82895c to your computer and use it in GitHub Desktop.
Save Lamartio/b3dc52bfaf7e7c6aab3e563c8d82895c to your computer and use it in GitHub Desktop.
kotlins_simple_layout_trick_pt2_bind_implementation.kt
open class BindableLayout<T, V : ViewGroup>(layout: V) : Layout<V>(layout) {
private val observers = Observers()
fun bind(observer: Observer<T>) {
observers.add(observer)
}
private inner class Observers : ArrayList<Observer<T>>(), Consumer<T> {
override fun accept(value: T) =
forEach { observer -> observer(value, value) }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment