rxdart 0.10.0


Native Dart rx implementation

RxDart #

Build Status codecov 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 #

void main() {
  const konamiKeyCodes = const <int>[

  final result = querySelector('#result');
  final keyUp = new Observable<KeyboardEvent>(document.onKeyUp);

    .map((event) => event.keyCode)
    .bufferWithCount(10, 1)
    .where((lastTenKeyCodes) => const IterableEquality<int>().equals(lastTenKeyCodes, konamiKeyCodes))
    .listen((_) => result.innerHtml = 'KONAMI!');

API Overview #

Objects #

Observable #

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

  • The Observable class is a simple wrapper for Stream and StreamTransformer classes. All underlying implementations can be used free of the Observable wrapper, and are exposed in their own libraries. They are linked to below.
  • The following sections link to DartDoc. While DartDoc is a bit scary looking at first, the documentation is up-to-date, readable, and contains examples. Furthermore, this documentation lives within the code, which means it can be easily read from within your favorite editor.

Instantiation #

Generally speaking, creating a new Observable is either done by wrapping a Dart Stream using the top-level constructor new 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.

var myObservable = new Observable(myStream);

Available Factory Methods

var myObservable = new Observable.merge([myFirstStream, mySecondStream]);
Available Static Methods
var myObservable = Observable.combineLatest3(
    (firstData, secondData, thirdData) => print("$firstData $secondData $thirdData"));

Transformations #

Available Methods

A full list of all methods and properties including those provided by the Dart Stream API (such as first, asyncMap, etc), can be seen by examining the DartDocs

var myObservable = new Observable(myStream)

Examples #

Web and command-line examples can be found in the example folder.

Web Examples #

In order to run the web examples, please follow these steps:

  1. Clone this repo and enter the directory
  2. Run pub get
  3. Run pub serve example/web
  4. Navigate to http://localhost:8080 in your browser

Command Line Examples #

In order to run the command line example, please follow these steps:

  1. Clone this repo and enter the directory
  2. Run pub get
  3. Run dart example/bin/fibonacci.dart 10

Flutter Example #

Install Flutter

In order to run the flutter example, you must have Flutter installed. For installation instructions, view the online documentation.

Run the app

  1. Open up an Android Emulator, the iOS Simulator, or connect an appropriate mobile device for debugging.
  2. Open up a terminal
  3. cd into the example/flutter/github_search directory
  4. Run flutter doctor to ensure you have all Flutter dependencies working.
  5. Run flutter packages get
  6. Run flutter run

Notable References #

Changelog #

Refer to the Changelog to get all release notes.