Skip to content

Commit

Permalink
refactor: use riverpod's update api
Browse files Browse the repository at this point in the history
  • Loading branch information
lishaduck committed Sep 27, 2024
1 parent 6cca130 commit 0ac3e8b
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions packages/app/lib/src/features/home/application/feed_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,19 @@ base class FeedService extends _$FeedService {
);
}

// TODO(MattsAttack): This is just an unused example. It should be used or removed.
/// Replace the current posts with newly generated posts.
Future<void> replacePosts(List<PostEntity> newPosts) async {
Future<FeedModel> addPosts(List<PostEntity> newPosts) async {

Check warning on line 42 in packages/app/lib/src/features/home/application/feed_service.dart

View check run for this annotation

Codecov / codecov/patch

packages/app/lib/src/features/home/application/feed_service.dart#L42

Added line #L42 was not covered by tests
// You can only change a Notifier's `state` by adding methods that assign a new value.
// You can't mutate the state directly, nor can you change it outside of a method.
if (state case AsyncData<FeedModel>(:final value)) {
state = AsyncData(
value.copyWith(
posts: [
// Spread the new list into the generated list.
...value.posts,
...newPosts,
],
),
return await update((value) {
return value.copyWith(
posts: [

Check warning on line 47 in packages/app/lib/src/features/home/application/feed_service.dart

View check run for this annotation

Codecov / codecov/patch

packages/app/lib/src/features/home/application/feed_service.dart#L45-L47

Added lines #L45 - L47 were not covered by tests
// Spread the new list into the generated list.
...value.posts,
...newPosts,

Check warning on line 50 in packages/app/lib/src/features/home/application/feed_service.dart

View check run for this annotation

Codecov / codecov/patch

packages/app/lib/src/features/home/application/feed_service.dart#L49-L50

Added lines #L49 - L50 were not covered by tests
],
);
}
});
}
}

0 comments on commit 0ac3e8b

Please sign in to comment.