added CharacterListViewModel and states with tests#4
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Title: feat: add CharacterListViewModel with pagination and dedupe guard
What this adds
CharacterListViewModel — the state and pagination logic behind the character list, built test-first with no UI attached yet.
Why the guard matters
await releases the actor it's isolated to. When loadNextPageIfNeeded() suspends at the network call, the @mainactor is free, and if the method is called again before that first call resumes, it walks straight through and starts a second fetch for the same page.
This isn't a hypothetical. In a List, onAppear can fire multiple times in quick succession as rows near the bottom during a fast scroll, well before a slow network response returns. Without a guard, that produces duplicate API calls and duplicate rows appended to the list.
The guard closes the gap: the first call sets isLoading = true before it suspends, and any call that arrives while it's still in flight returns immediately instead of starting another fetch.
How it's proven, not just asserted
concurrentLoadsRequestPageOnlyOnce launches three concurrent calls via withTaskGroup, with an artificial delay in the mock repository to force them to genuinely overlap rather than run sequentially. It asserts the repository received the request exactly once.
Confirmed the test is real by temporarily removing the guard: the test failed with requestedPages == [1, 1, 1] and characters.count == 60, then passed again once the guard was restored.
Tests