Skip to content

Code in intermediate step does not match expected final code in Step 9 #98

@alvindizon

Description

@alvindizon

In Step 9, we are asked to complete the initSearch with the following lines of code:

        // Scroll to top when the list is refreshed from network.
        lifecycleScope.launch {
            adapter.loadStateFlow
                   // Only emit when REFRESH LoadState changes.
                   .distinctUntilChangedBy { it.refresh }
                   // Only react to cases where REFRESH completes i.e., NotLoading.
                   .filter { it.refresh is LoadState.NotLoading }
                   .collect { binding.list.scrollToPosition(0) }
        }

However, at the end of the Step 9, the finished code for initSearch uses the following:

        lifecycleScope.launch {
            @OptIn(ExperimentalPagingApi::class)
            adapter.dataRefreshFlow.collect {
                binding.list.scrollToPosition(0)
            }
        }

Did I miss anything during the course of doing Step 9? Or is something really missing? I guess the final code is functionally the same with the intermediate code, but it's a little bit puzzling for me.

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