rx_storage 0.0.2 rx_storage: ^0.0.2 copied to clipboard
Reactive storage for Dart/Flutter. RxDart Storage for Dart/Flutter.
rx_storage #
Reactive storage for Dart/Flutter. RxDart Storage for Dart/Flutter.
Author: Petrus Nguyễn Thái Học #
Note: rx_shared_preferences is an extension of this package. #
More detail about returned Stream
#
-
It's a single-subscription
Stream
(ie. it can only be listened once). -
Stream
will emit the value (nullable) or aTypeError
as its first event when it is listen to. -
It will automatic emits value when value associated with key was changed successfully (emit
null
when value associated with key wasremoved
or set tonull
). -
When value read from Storage has a type other than expected type:
- If value is
null
, theStream
will emitnull
(this occurred becausenull
can be cast to any nullable type). - Otherwise, the
Stream
will emit aTypeError
.
- If value is
-
Can emit two consecutive data events that are equal. You should use Rx operator like
distinct
(More commonly known asdistinctUntilChanged
in other Rx implementations) to create anStream
where data events are skipped if they are equal to the previous data event.
Key changed: |----------K1---K2------K1----K1-----K2---------
|
Value stream: |-----@----@------------@-----@-----------------
| ^
| |
| Listen(key=K1)
|
| @: nullable value or TypeError
Usage #
A simple usage example:
import 'package:rx_storage/rx_storage.dart';
class StorageAdapter implements Storage { ... }
main() {
final Storage adapter = StorageAdapter();
final RxStorage rxStorage = RxStorage(adapter);
rxStorage.getStringStream('key').listen((value) { ... });
}
Features and bugs #
Please file feature requests and bugs at the issue tracker.