bloc icon indicating copy to clipboard operation
bloc copied to clipboard

feat: Allow providing 'dispose' to RepositoryProvider

Open AlexanderFarkas opened this issue 2 years ago • 1 comments

Description

Sometimes you want to recreate Repository. Usually repositories have StreamControllers for entity streams.

class EntityRepository {

  final entityUpdated = StreamController<Entity>.broadcast();
  final entityCreated = StreamController<Entity>.broadcast();
  final entityDeleted = StreamController<int>.broadcast(); // by id
  
  Future<void> dispose() => Future.wait([
    entityUpdated.dispose(),
    entityCreated.dispose(),
    entityDeleted.dispose(),
  ]);

  Future<void> createEntity() async {
    final entity = await makeHttpCreateCall();
    entityCreated.add(entity);
  }
  
  Future<void> updateEntity() async {
    final entity = await makeHttpUpdateCall();
    entityUpdated.add(entity);
  }
  
  Future<void> deleteEntity() async {
    final entityId = await makeHttpDeleteCall();
    entityDeleted.add(entityId);
  }
}

Desired Solution

It would be useful to have dispose in RepositoryProvider, considering it's already implemented in Provider.

AlexanderFarkas avatar Jun 19 '22 08:06 AlexanderFarkas

I've seen that a couple of such feature proposals were rejected. But I believe that these StreamControllers are part of internal implementation of repository. So they need to be managed by repository, including disposal.

AlexanderFarkas avatar Jun 19 '22 09:06 AlexanderFarkas