[fenix] For https://github.com/mozilla-mobile/fenix/issues/10342 - Part 1: Remove top sites prefetch and observation of live data
parent
d8fbb2b4b0
commit
1f3f1f481d
@ -1,20 +0,0 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
package org.mozilla.fenix.ext
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.Observer
|
||||
|
||||
/**
|
||||
* Observe a LiveData once and unregister from it as soon as the live data returns a value
|
||||
*/
|
||||
fun <T> LiveData<T>.observeOnce(observer: (T) -> Unit) {
|
||||
observeForever(object : Observer<T> {
|
||||
override fun onChanged(value: T) {
|
||||
removeObserver(this)
|
||||
observer(value)
|
||||
}
|
||||
})
|
||||
}
|
Loading…
Reference in New Issue