Skip to content

Commit 17bd019

Browse files
committed
refactor
1 parent e2c2f87 commit 17bd019

File tree

7 files changed

+155
-128
lines changed

7 files changed

+155
-128
lines changed

.idea/libraries/Dart_Packages.xml

Lines changed: 100 additions & 100 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/libraries/Dart_SDK.xml

Lines changed: 21 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/src/impl/real_storage.dart

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import '../logger/logger.dart';
99
import '../model/key_and_value.dart';
1010
import '../stream_extensions/map_not_null_stream_transformer.dart';
1111
import '../stream_extensions/single_subscription.dart';
12-
import '../synchronous_future.dart';
1312

1413
/// Default [RxStorage] implementation
1514
class RealRxStorage implements RxStorage {
@@ -98,13 +97,13 @@ class RealRxStorage implements RxStorage {
9897
String key,
9998
T value,
10099
) {
100+
assert(key != null);
101+
101102
if (T == dynamic) {
102103
assert(value == null);
103104
return storage.remove(key);
104105
}
105106

106-
assert(key != null);
107-
108107
// TODO(40014): Remove cast when type promotion works.
109108
// This would normally be `as T` but we use `as dynamic` to make the
110109
// unneeded check be implicit to match dart2js unsound optimizations in the
@@ -137,9 +136,8 @@ class RealRxStorage implements RxStorage {
137136
.mapNotNull(
138137
(map) => map.containsKey(key) ? KeyAndValue(key, map[key]) : null)
139138
.startWith(null) // Dummy value to trigger initial load.
140-
.asyncMap<T>((entry) => entry == null
141-
? _getValue<T>(key)
142-
: SynchronousFuture(entry.value as T));
139+
.asyncMap<T>(
140+
(entry) => entry == null ? _getValue<T>(key) : entry.value as T);
143141

144142
if (_logger == null) {
145143
return stream;

test/fake_storage.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'package:rx_storage/src/interface/storage.dart';
2-
import 'package:rx_storage/src/synchronous_future.dart';
2+
3+
import 'utils/synchronous_future.dart';
34

45
Future<T> _wrap<T>(T value) => SynchronousFuture(value);
56

test/perf.dart

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'dart:async';
2+
13
import 'package:rx_storage/rx_storage.dart';
24

35
import 'fake_storage.dart';
@@ -39,6 +41,26 @@ void main() async {
3941
stopwatch.stop();
4042
print(stopwatch.elapsedMilliseconds);
4143

44+
final completer = Completer<void>.sync();
45+
stopwatch
46+
..reset()
47+
..start();
48+
print('Start 2...');
49+
rxStorage.getStringStream('key').listen((event) {
50+
if (event == 10000.toString()) {
51+
print('End 2...');
52+
53+
stopwatch.stop();
54+
print(stopwatch.elapsedMilliseconds);
55+
completer.complete();
56+
}
57+
});
58+
for (var i = 0; i <= 10000; i++) {
59+
await rxStorage.setString('key', i.toString());
60+
}
61+
62+
await completer.future;
63+
4264
/*for (var i = 0; i < 10000; i++) {
4365
await Future.value(1)
4466
.then((value) => SynchronousFuture(value + 1))
File renamed without changes.

0 commit comments

Comments
 (0)