diff --git a/packages/brick_offline_first/lib/src/offline_first_repository.dart b/packages/brick_offline_first/lib/src/offline_first_repository.dart index 1c3b23b3..e976116f 100644 --- a/packages/brick_offline_first/lib/src/offline_first_repository.dart +++ b/packages/brick_offline_first/lib/src/offline_first_repository.dart @@ -302,6 +302,7 @@ abstract class OfflineFirstRepository /// Iterate through subscriptions after an upsert and notify any [subscribe] listeners. @protected @visibleForTesting + @visibleForOverriding Future notifySubscriptionsWithLocalData({ bool notifyWhenEmpty = true, Map>>? subscriptionsByQuery, diff --git a/packages/brick_offline_first_with_supabase/lib/src/offline_first_with_supabase_repository.dart b/packages/brick_offline_first_with_supabase/lib/src/offline_first_with_supabase_repository.dart index 9f59cbd8..473a5c5c 100644 --- a/packages/brick_offline_first_with_supabase/lib/src/offline_first_with_supabase_repository.dart +++ b/packages/brick_offline_first_with_supabase/lib/src/offline_first_with_supabase_repository.dart @@ -147,6 +147,28 @@ abstract class OfflineFirstWithSupabaseRepository await offlineRequestQueue.client.requestManager.migrate(); } + @override + Future notifySubscriptionsWithLocalData({ + bool notifyWhenEmpty = true, + Map>>? subscriptionsByQuery, + }) async { + final supabaseControllers = supabaseRealtimeSubscriptions[TModel] + ?.values + .fold(>>{}, (acc, eventMap) { + acc.addEntries(eventMap.entries); + return acc; + }); + final subs = { + ...?subscriptionsByQuery, + ...?subscriptions[TModel], + ...?supabaseControllers, + }; + await super.notifySubscriptionsWithLocalData( + notifyWhenEmpty: notifyWhenEmpty, + subscriptionsByQuery: subs, + ); + } + /// Supabase's realtime payload only returns unique columns; /// the instance must be discovered from these values so it /// can be deleted by all providers. @@ -303,9 +325,7 @@ abstract class OfflineFirstWithSupabaseRepository memoryCacheProvider.upsert(instance, repository: this); } - await notifySubscriptionsWithLocalData( - subscriptionsByQuery: supabaseRealtimeSubscriptions[TModel]![eventType]!, - ); + await notifySubscriptionsWithLocalData(); }, ) .subscribe(); diff --git a/packages/brick_offline_first_with_supabase/test/__mocks__.dart b/packages/brick_offline_first_with_supabase/test/__mocks__.dart index 6f6300a7..dd72d9cd 100644 --- a/packages/brick_offline_first_with_supabase/test/__mocks__.dart +++ b/packages/brick_offline_first_with_supabase/test/__mocks__.dart @@ -47,6 +47,11 @@ class Customer extends OfflineFirstWithSupabaseModel { other.id == id && other.firstName == firstName && other.lastName == lastName; + + @override + String toString() { + return 'Customer(id: $id, firstName: $firstName, lastName: $lastName, pizzas: $pizzas)'; + } } @ConnectOfflineFirstWithSupabase( diff --git a/packages/brick_offline_first_with_supabase/test/offline_first_with_supabase_repository_test.dart b/packages/brick_offline_first_with_supabase/test/offline_first_with_supabase_repository_test.dart index 34e0ddc7..4d76a27b 100644 --- a/packages/brick_offline_first_with_supabase/test/offline_first_with_supabase_repository_test.dart +++ b/packages/brick_offline_first_with_supabase/test/offline_first_with_supabase_repository_test.dart @@ -432,6 +432,7 @@ void main() async { expect( customers, emitsInOrder([ + [], [], [customer], ]), @@ -473,6 +474,7 @@ void main() async { expect( customers, emitsInOrder([ + [customer], [customer], [], ]), @@ -522,6 +524,7 @@ void main() async { expect( customers, emitsInOrder([ + [customer1], [customer1], [customer2], ]), @@ -557,6 +560,7 @@ void main() async { expect( customers, emitsInOrder([ + [], [], [customer], ]), @@ -597,6 +601,7 @@ void main() async { expect( customers, emitsInOrder([ + [customer], [customer], [], ]), @@ -645,6 +650,7 @@ void main() async { expect( customers, emitsInOrder([ + [customer1], [customer1], [customer2], ]), @@ -683,6 +689,7 @@ void main() async { expect( customers, emitsInOrder([ + [], [], [customer1], [customer2], diff --git a/packages/brick_supabase/lib/src/testing/supabase_response.dart b/packages/brick_supabase/lib/src/testing/supabase_response.dart index 0e9f7033..fa3a59b7 100644 --- a/packages/brick_supabase/lib/src/testing/supabase_response.dart +++ b/packages/brick_supabase/lib/src/testing/supabase_response.dart @@ -33,6 +33,6 @@ class SupabaseResponse { this.data, { this.headers, this.realtimeSubsequentReplies = const [], - this.realtimeSubsequentReplyDelay = const Duration(milliseconds: 10), + this.realtimeSubsequentReplyDelay = const Duration(milliseconds: 30), }); }