bloc
bloc copied to clipboard
feat: Allow providing 'dispose' to RepositoryProvider
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.
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.