Skip to content

Section 18: PREPEND Section, some unclear issues #84

@RoarGronmo

Description

@RoarGronmo
val page = when (loadType) {
   LoadType.PREPEND -> {
        val remoteKeys = getRemoteKeyForFirstItem(state)
        if (remoteKeys == null) {
            // The LoadType is PREPEND so some data was loaded before,
            // so we should have been able to get remote keys
            // If the remoteKeys are null, then we're an invalid state and we have a bug
            throw InvalidObjectException("Remote key and the prevKey should not be null")
        }
        // If the previous key is null, then we can't request more data
        val prevKey = remoteKeys.prevKey
        if (prevKey == null) {
            return MediatorResult.Success(endOfPaginationReached = true)
        }
        remoteKeys.prevKey
    }
  }
  1. The throw statement above says "Remote key and the prevKey should not be null", but you only test on remoteKey's nullability, not the prevKey. Please change to correct message or behavior
  2. The latter if statement tests prevKey, in a separate value. That is in principle not necessary, please omit the prevKey value and test on remoteKeys.prevKey instead.

RG

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions