Davide Giuseppe Farella
05/06/2023, 1:24 PMLazyPagingItems
to my model/state (I do that in the presenter, using Molecule, if you’re wondering)
In order to test that, I created this convenience mock (since LPI
has internal constructor)
fun <T : Any> mockLazyPagingItems(isEmpty: Boolean, refresh: LoadState): LazyPagingItems<T> = mockk {
every { loadState } returns mockk loadState@{
every { this@loadState.refresh } returns refresh
every { this@loadState.append } returns LoadState.Loading
every { this@loadState.prepend } returns LoadState.Loading
}
every { itemCount } returns if (isEmpty) 0 else 1
}
Updating to alpha19 I now have this exception (full stacktrace in thread)
java.lang.NullPointerException: Cannot invoke “androidx.compose.runtime.State.getValue()” because “$this$getValue$iv” is nullHow would I fix that?
shikasd
05/06/2023, 6:41 PMDavide Giuseppe Farella
05/06/2023, 8:12 PM$iv
is something from the IR, no? 🤔LPI
, but I'm not sure in which scenarios that would be useful besides mine, as it would be impossible to get a LPI
outside of the UI without Molecule (as collectAsLazyPagingItems
is the only way)loadState
is now a delegate.
I instantiated a LPI
using reflection, but I’ve not been able to run my tests correctly, as I’ve not been able to update the snapshot list under test 😞LPI
and create a surrogate mapper in between, so I can test my mapper (m2
) using the surrogate
LazyPagingItems (m1)-> LazyPagingItemsSurrogate (m2)-> PagingItemsState
Ian Lake
05/07/2023, 7:46 PMI have a mapper that maps from LazyPagingItems to my model/state (I do that in the presenter, using Molecule, if you're wondering)
This is the wrong thing to do in the first place. Map your Flow<PagingData> using the operators provided by Paging at that level
Davide Giuseppe Farella
05/07/2023, 7:50 PMIan Lake
05/07/2023, 7:56 PMDavide Giuseppe Farella
05/07/2023, 7:59 PMIan Lake
05/07/2023, 7:59 PMDavide Giuseppe Farella
05/07/2023, 7:59 PMIan Lake
05/07/2023, 8:01 PMflowOf(PagingData.from(...)).collectAsLazyPagingItems()
Davide Giuseppe Farella
05/07/2023, 8:03 PMIan Lake
05/07/2023, 8:04 PMDavide Giuseppe Farella
05/07/2023, 8:05 PMIan Lake
05/07/2023, 8:13 PMMutableStateFlow(PagingData.from...))
)Davide Giuseppe Farella
05/08/2023, 5:55 AM