Skip to content

Commit

Permalink
feat(neon_framework): Add keys() methods for Persistence and Settings…
Browse files Browse the repository at this point in the history
…Store

Signed-off-by: provokateurin <[email protected]>
  • Loading branch information
provokateurin committed Sep 13, 2024
1 parent b630bde commit 9a80984
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/neon_framework/lib/src/storage/persistence.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ abstract interface class Persistence<T extends Object> {
/// Whether a value exists at the given [key].
FutureOr<bool> containsKey(String key);

/// Returns all keys in the persistent storage.
FutureOr<List<String>> keys();

/// Clears all values from persistent storage.
FutureOr<bool> clear();

Expand Down Expand Up @@ -53,6 +56,9 @@ abstract class CachedPersistence<T extends Object> implements Persistence<T> {
/// when the app is restarted.
void setCache(String key, T value) => cache[key] = value;

@override
List<String> keys() => cache.keys.toList();

@override
bool containsKey(String key) => cache.containsKey(key);

Expand Down
6 changes: 6 additions & 0 deletions packages/neon_framework/lib/src/storage/settings_store.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ abstract interface class SettingsStore {

/// Removes an entry from persistent storage.
Future<bool> remove(String key);

/// Returns all keys in the persistent storage.
List<String> keys();
}

/// Default implementation of the [SettingsStore] backed by the given [persistence].
Expand Down Expand Up @@ -62,4 +65,7 @@ final class DefaultSettingsStore implements SettingsStore {

@override
Future<bool> setBool(String key, bool value) => persistence.setValue(key, value);

@override
List<String> keys() => persistence.keys();
}

0 comments on commit 9a80984

Please sign in to comment.