rxdart_ext 0.1.1
rxdart_ext: ^0.1.1 copied to clipboard
Some extension methods and classes built on top of RxDart - RxDart extension.
rxdart_ext #
Author: Petrus Nguyễn Thái Học #
Some extension methods and classes built on top of RxDart
- RxDart
extension.
API #
Single #
A Stream which emits single event, either data or error, and then close with a done-event.
Success case: ------------(*)|------
data done
Failure case: ------------(x)|------
error done
NOTE: Single extends Stream, so all operators and transformers for Stream are available for Single as well.
Single
is suitable for one-shot operations (likes Future
but lazy - executes when listening), eg. making API request, reading local storage, ...
import 'package:http/http.dart' as http;
Single<User> fetchUser(String id) {
return Single.fromCallable(() => http.get(Uri.parse('$baseUrl/users/$id')))
.flatMapSingle((res) => res.statusCode == HttpStatus.ok
? Single.value(res.body)
: Single.error(Exception('Cannot fetch user with id=$id')))
.map((body) => User.fromJson(jsonEncode(body)));
}
-
Create Single
-
Factory constructors.
-
Static methods provided by RxSingles class
-
Convert others to Single via extensions.
-
-
Operators for Single (returns a Single instead of Stream)
Operators for Stream #
- debug, collect
- ForwardingSinkMixin
- BaseEventSink
- forwardSingleWithSink
- distinctUniqueBy
- distinctBy
- ignoreElements, ignoreErrors
- mapNotNull
- toSingleSubscription
- asVoid
- whereNotNull
NotReplayValueStream #
A Stream that provides synchronous access to the last emitted item, but not replay the latest value.
- Broadcast
- Single-subscription
RxDart compatibility #
rxdart | rxdart_ext |
---|---|
^0.26.0 | ^0.0.1 |
^0.27.0 | ^0.1.0 |