diff --git a/packages/neon/neon/lib/src/blocs/apps.dart b/packages/neon/neon/lib/src/blocs/apps.dart index 1492f9f7..54fd9fa7 100644 --- a/packages/neon/neon/lib/src/blocs/apps.dart +++ b/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) { diff --git a/packages/neon/neon/lib/src/models/account_cache.dart b/packages/neon/neon/lib/src/models/account_cache.dart index 0a759e62..967e5234 100644 --- a/packages/neon/neon/lib/src/models/account_cache.dart +++ b/packages/neon/neon/lib/src/models/account_cache.dart @@ -30,6 +30,14 @@ class AccountCache 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]; diff --git a/packages/neon/neon/test/account_cache_test.dart b/packages/neon/neon/test/account_cache_test.dart index 26dc80ee..5cf09b65 100644 --- a/packages/neon/neon/test/account_cache_test.dart +++ b/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(); + 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); + }); }); }