* For #11660:added prefetch for topsites TopSites will be prefetched with observerOnce (wrapper around observerForever). Also, the SessionControlView.update() is called right away instead of waiting from consumeFrom in the HomeFragment.onCreateView() which will allow the UI to render all at once on its first perform traversal * Removed the submitList(null) since it retriggered a drawing on lower end devicefennec/production
parent
44ff29bdc0
commit
b52091ed34
@ -0,0 +1,20 @@
|
|||||||
|
/* 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