From 0ac3e8bf0d56464c6d77a2e67db9f6b726cb6a8b Mon Sep 17 00:00:00 2001 From: Eli <88557639+lishaduck@users.noreply.github.com> Date: Sat, 21 Sep 2024 20:54:03 -0500 Subject: [PATCH] refactor: use riverpod's update api --- .../home/application/feed_service.dart | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/packages/app/lib/src/features/home/application/feed_service.dart b/packages/app/lib/src/features/home/application/feed_service.dart index 07db04cd..7afe47fd 100644 --- a/packages/app/lib/src/features/home/application/feed_service.dart +++ b/packages/app/lib/src/features/home/application/feed_service.dart @@ -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 replacePosts(List newPosts) async { + Future addPosts(List newPosts) async { // 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(: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: [ + // Spread the new list into the generated list. + ...value.posts, + ...newPosts, + ], ); - } + }); } }