Skip to content

Commit 4d58dfc

Browse files
committed
make public toList
1 parent b868c27 commit 4d58dfc

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

lib/src/impl/real_storage.dart

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class RealRxStorage<Key extends Object, Options,
7070

7171
_keyValuesSubject
7272
.map<LoggerEvent<Key, Options>>(
73-
(map) => KeysChangedEvent(_mapToList(map)))
73+
(map) => KeysChangedEvent(map.toListOfKeyAndValues()))
7474
.listen(_loggerEventController!.add)
7575
.disposedBy(_bag);
7676
}
@@ -205,7 +205,8 @@ class RealRxStorage<Key extends Object, Options,
205205
(s) => s.readAll(options),
206206
(value, _) {
207207
if (_isLogEnabled) {
208-
_publishLog(ReadAllSuccessEvent(_mapToList(value), options));
208+
_publishLog(
209+
ReadAllSuccessEvent(value.toListOfKeyAndValues(), options));
209210
}
210211
},
211212
(error, _) {
@@ -333,13 +334,6 @@ class RealRxStorage<Key extends Object, Options,
333334
}
334335
}
335336

336-
List<KeyAndValue<Key, Object?>> _mapToList<Key extends Object>(
337-
Map<Key, Object?> map) {
338-
final pairs =
339-
map.entries.map((e) => KeyAndValue<Key, Object?>(e.key, e.value));
340-
return List.unmodifiable(pairs);
341-
}
342-
343337
/// Scope function extension
344338
extension _ScopeFunctionExtension<T> on T {
345339
/// Returns result from calling [f].

lib/src/model/key_and_value.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,13 @@ class KeyAndValue<K extends Object, V> {
1212
@override
1313
String toString() => "{ '$key': $value }";
1414
}
15+
16+
/// Convert a map to list of [KeyAndValue]s.
17+
extension MapToListOfKeyAndValuesExtension<Key extends Object>
18+
on Map<Key, Object?> {
19+
/// Convert this map to list of [KeyAndValue]s.
20+
List<KeyAndValue<Key, Object?>> toListOfKeyAndValues() {
21+
final pairs = entries.map((e) => KeyAndValue<Key, Object?>(e.key, e.value));
22+
return List.unmodifiable(pairs);
23+
}
24+
}

0 commit comments

Comments
 (0)