rxdart 0.8.0

  • Readme
  • Changelog
  • Installing
  • 50

RxDart #

Build Status Coverage Status Pub Gitter

About #

RxDart is a reactive functional programming library for Google Dart, based on ReactiveX.
Google Dart comes with a very decent Streams API out-of-the-box; rather than attempting to provide an alternative to this API, RxDart adds functionality on top of it.

How To Use RxDart #

For Example: Reading the Konami Code #

import 'package:rxdart/rxdart.dart';

void main() {

  var codes = <int>[38, 38, 40, 40, 37, 39, 37, 39, 66, 65];
  var result = querySelector('#result');
  var controller = new StreamController<KeyboardEvent>();
  var stream = observable(controller.stream);

  document.addEventListener('keyup', (event) => controller.add(event));

    .map((event) => event.keyCode ) // Get the key code
    .bufferWithCount(10, 1) // Get the last 10 keys
    .where((list) => _areTwoListsEqual(list, codes)) // Check for matching values
    .listen((_) => result.innerHtml = 'KONAMI!');

bool _areTwoListsEqual(List<int> a, List<int> b) {
  for (int i=0; i<10; i++) if (a[i] != b[i]) return false;
  return true;

API Overview #

RxDart's Observables extend the Stream class. This has two major implications:

Instantiation #

Generally speaking, creating a new Observable is either done by wrapping a Dart Stream using the top-level method observable(), or by calling a factory method on the Observable class.
But to better support Dart's strong mode, combineLatest and zip have been pulled apart into fixed-length constructors. These methods are supplied as static methods, since Dart's factory methods don't support generic types.

Available Top-level Method
  • observable
var myObservable = observable(myStream);
Available Factory Methods
  • amb
  • concat
  • defer
  • just
  • merge
  • periodic
  • tween
var myObservable = new Observable.merge([myFirstStream, mySecondStream]);
Available Static Methods
  • combineLatest (combineLatest2, combineLatest3, combineLatest4, ..., combineLatest9)
  • zip (zip2, zip3, zip4, ..., zip9)
var myObservable = Observable.combineLatest3(
    (firstData, secondData, thirdData) => print(firstData + ' ' + secondData + ' ' + thirdData));

Transformations #

Available Methods
  • bufferWithCount
  • call
  • debounce
  • flatMapLatest
  • flatMap
  • groupBy
  • interval
  • max
  • min
  • pluck
  • repeat
  • retry
  • sample
  • scan
  • startWith
  • startWithMany
  • takeUntil
  • timeInterval
  • tap
  • throttle
  • windowWithCount
  • withLatestFrom
var myObservable = observable(myStream)

Objects #

  • Observable
  • BehaviourSubject
  • ReplaySubject

Notable References #

Changelog #

Refer to the Changelog to get all release notes.

0.8.0 #

  • BREAKING: tap is replaced by call(onData)
  • added call, which can take any combination of the following event methods: onCancel, onData, onDone, onError, onListen, onPause, onResume

0.7.1+1 #

  • improved the README file

0.7.1 #

  • added ignoreElements
  • added onErrorResumeNext
  • added onErrorReturn
  • added switchIfEmpty
  • added empty factory constructor

0.7.0 #

  • BREAKING: rename combineXXXLatest and zipXXX to a numbered equivalent, for example: combineThreeLatest becomes combineLatest3
  • internal refactoring, expose streams/stream transformers as a separate library

0.6.3+4 #

  • changed ofType to use TypeToken

0.6.3+3 #

  • added ofType

0.6.3+2 #

  • added defaultIfEmpty

0.6.3+1 #

  • changed concat, old concat is now concatEager, new concat behaves as expected

0.6.3 #

  • Added withLatestFrom
  • Added defer ctr (both thanks to brianegan)

0.6.2 #

  • Added just (thanks to brianegan)
  • Added groupBy
  • Added amb

0.6.1 #

  • Added concat

0.6.0 #

  • BREAKING: startWith now takes just one parameter instead of an Iterable. To add multiple starting events, please use startWithMany.
  • Added BehaviourSubject and ReplaySubject. These implement StreamController.
  • BehaviourSubject will notify the last added event upon listening.
  • ReplaySubject will notify all past events upon listening.
  • DEPRECATED: zip and combineLatest, use their strong-type-friendly alternatives instead (available as static methods on the Observable class, i.e. Observable.combineThreeLatest, Observable.zipFour, ...)

0.5.1 #

  • Added documentation (thanks to dustinlessard-wf)
  • Fix tests breaking due to deprecation of expectAsync
  • Fix tests to satisfy strong mode requirements

0.5.0 #

  • As of this version, rxdart depends on SDK v1.21.0, to support the newly added generic method type syntax

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  rxdart: ^0.8.0

2. Install it

You can install packages from the command line:

with pub:

$ pub get

Alternatively, your editor might support pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:rxdart/rxdart.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

This package version is not analyzed, because it is more than two years old. Check the latest stable version for its analysis.

The package version is not analyzed, because it does not support Dart 2. Until this is resolved, the package will receive a health and maintenance score of 0.

Analysis issues and suggestions

Support Dart 2 in pubspec.yaml.

The SDK constraint in pubspec.yaml doesn't allow the Dart 2.0.0 release. For information about upgrading it to be Dart 2 compatible, please see https://dart.cn/dart-2#migration.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.21.0