package net.pokeranalytics.android.util.data

import androidx.lifecycle.LiveData
import io.realm.RealmChangeListener
import io.realm.RealmModel
import io.realm.RealmResults


class LiveRealmData<T : RealmModel>(private val results: RealmResults<T>) : LiveData<RealmResults<T>>() {
	private val listener = RealmChangeListener<RealmResults<T>> { results -> value = results }
	
	override fun onActive() {
		results.addChangeListener(listener)
		value = results
	}
	
	override fun onInactive() {
		results.removeChangeListener(listener)
	}
	
}