Browse Source

feat(neon): dispose app blocs if a refresh disables the app for the associated account

Signed-off-by: Nikolas Rimikis <leptopoda@users.noreply.github.com>
pull/721/head
Nikolas Rimikis 1 year ago
parent
commit
f0afcbda24
No known key found for this signature in database
GPG Key ID: 85ED1DE9786A4FF2
  1. 7
      packages/neon/neon/lib/src/blocs/apps.dart
  2. 8
      packages/neon/neon/lib/src/models/account_cache.dart
  3. 15
      packages/neon/neon/test/account_cache_test.dart

7
packages/neon/neon/lib/src/blocs/apps.dart

@ -58,6 +58,13 @@ class AppsBloc extends InteractiveBloc implements AppsBlocEvents, AppsBlocStates
return;
}
// dispose unsupported apps
for (final app in _allAppImplementations) {
if (result.requireData.tryFind(app.id) == null) {
app.blocsCache.remove(_account);
}
}
final options = _accountsBloc.getOptionsFor(_account);
final initialApp = options.initialApp.value ?? _getInitialAppFallback();
if (initialApp != null) {

8
packages/neon/neon/lib/src/models/account_cache.dart

@ -30,6 +30,14 @@ class AccountCache<T extends Disposable> implements Disposable {
});
}
/// Removes [account] and its associated value, if present, from the cache.
///
/// If present the value associated with `account` is disposed.
void remove(final Account? account) {
final removed = _cache.remove(account?.id);
removed?.dispose();
}
/// The value for the given [account], or `null` if [account] is not in the cache.
T? operator [](final Account account) => _cache[account.id];

15
packages/neon/neon/test/account_cache_test.dart

@ -55,5 +55,20 @@ void main() {
verify(disposable0.dispose).called(1);
verify(disposable1.dispose).called(1);
});
test('remove', () {
final cache = AccountCache<DisposableMock>();
cache[account0] = disposable0;
cache[account1] = disposable1;
cache.remove(null);
expect(cache[account0], disposable0);
expect(cache[account1], disposable1);
cache.remove(account0);
expect(cache[account0], isNull);
verify(disposable0.dispose).called(1);
});
});
}

Loading…
Cancel
Save