rxdart 0.18.1

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 99

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.

Version

Dart 1.0 is supported until release 0.15.x, version 0.16.x is no longer backwards compatible and requires the Dart SDK 2.0

How To Use RxDart

For Example: Reading the Konami Code

void main() {
  const konamiKeyCodes = const <int>[
    KeyCode.UP,
    KeyCode.UP,
    KeyCode.DOWN,
    KeyCode.DOWN,
    KeyCode.LEFT,
    KeyCode.RIGHT,
    KeyCode.LEFT,
    KeyCode.RIGHT,
    KeyCode.B,
    KeyCode.A];

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

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

API Overview

Objects

Observable

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

Finally, the Observable class & operators are simple wrappers around Stream and StreamTransformer classes. All underlying implementations can be used free of the Observable class, and are exposed in their own libraries. They are linked to below.

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.

Usage
var myObservable = new Observable(myStream);

Available Factory Methods

Usage
var myObservable = new Observable.merge([myFirstStream, mySecondStream]);
Available Static Methods
Usage
var myObservable = Observable.combineLatest3(
    myFirstStream, 
    mySecondStream, 
    myThirdStream, 
    (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

Usage
var myObservable = new Observable(myStream)
    .bufferCount(5)
    .distinct();

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.

0.18.1

  • Add retryWhen operator. Thanks to Razvan Lung (@long1eu)! This can be used for custom retry logic.

0.18.0

  • Breaking Change: remove retype method, deprecated as part of Dart 2.
  • Add flatMapIterable

0.17.0

  • Breaking Change: stream property on Observable is now private.
    • Avoids API confusion
    • Simplifies Subject implementation
    • Require folks who are overriding the stream property to use a super constructor instead
  • Adds proper onPause and onResume handling for amb/race, combineLatest, concat, concat_eager, merge and zip
  • Add switchLatest operator
  • Add errors and stacktraces to RetryError class
  • Add onErrorResume and onErrorRetryWith operators. These allow folks to return a specific stream or value depending on the error that occurred.

0.16.7

  • Fix new buffer and window implementation for Flutter + Dart 2
  • Subject now implements the Observable interface

0.16.6

  • Rework for buffer and window, allow to schedule using a sampler
  • added buffer
  • added bufferFuture
  • added bufferTest
  • added bufferTime
  • added bufferWhen
  • added window
  • added windowFuture
  • added windowTest
  • added windowTime
  • added windowWhen
  • added onCount sampler for buffer and window
  • added onFuture sampler for buffer and window
  • added onTest sampler for buffer and window
  • added onTime sampler for buffer and window
  • added onStream sampler for buffer and window

0.16.5

  • Renames amb to race
  • Renames flatMapLatest to switchMap
  • Renames bufferWithCount to bufferCount
  • Renames windowWithCount to windowCount

0.16.4

  • Adds bufferTime transformer.
  • Adds windowTime transformer.

0.16.3

  • Adds delay transformer.

0.16.2

  • Fix added events to sink are not processed correctly by Subjects.

0.16.1

  • Fix dematerialize method for Dart 2.

0.16.0+2

  • Add value to BehaviorSubject. Allows you to get the latest value emitted by the subject if it exists.
  • Add values to ReplayrSubject. Allows you to get the values stored by the subject if any exists.

0.16.0+1

  • Update Changelog

0.16.0

  • breaks backwards compatibility, this release only works with Dart SDK >=2.0.0.
  • Removed old cast in favour of the now native Stream cast method.
  • Override retype to return an Observable.

0.15.1

  • Add exhaustMap map to inner observable, ignore other values until that observable completes.
  • Improved code to be dartdevc compatible.
  • Add upper SDK version limit in pubspec

0.15.0

  • Change debounce to emit the last item of the source stream as soon as the source stream completes.
  • Ensure debounce does not keep open any addition async timers after it has been cancelled.

0.14.0+1

  • Change DoStreamTransformer to return a Future on cancel for api compatibility.

0.14.0

  • Add PublishSubject (thanks to @pauldemarco)
  • Fix bug with doOnX operators where callbacks were fired too often

0.13.1

  • Fix error with FlatMapLatest where it was not properly cancelled in some scenarios
  • Remove additional async methods on Stream handlers unless they're shown to solve a problem

0.13.0

  • Remove call operator / StreamTransformer entirely
  • Important bug fix: Errors thrown within any Stream or Operator will now be properly sent to the StreamSubscription.
  • Improve overall handling of errors throughout the library to ensure they're handled correctly

0.12.0

  • Added doOn* operators in place of call.
  • Added DoStreamTransformer as a replacement for CallStreamTransformer
  • Deprecated call and CallStreamTransformer. Please use the appropriate doOnX operator / transformer.
  • Added distinctUnique. Emits items if they've never been emitted before. Same as to Rx#distinct.

0.11.0

  • !!!Breaking Api Change!!!
    • Observable.groupBy has been removed in order to be compatible with the next version of the Stream class in Dart 1.24.0, which includes this method

0.10.2

  • BugFix: The new Subject implementation no longer causes infinite loops when used with ng2 async pipes.

0.10.1

  • Documentation fixes

0.10.0

  • Api Changes
    • Observable
      • Remove all deprecated methods, including:
        • observable factory -- replaced by the constructor new Observable()
        • combineLatest -- replaced by Strong-Mode versions combineLatest2 - combineLatest9
        • zip -- replaced by Strong-Mode versions zip2 - zip9
      • Support asObservable conversion from Future-returning methods. e.g. new Observable.fromIterable([1, 2]).first.asObservable()
      • Max and Min now return a Future of the Max or Min value, rather than a stream of increasing or decreasing values.
      • Add cast operator
      • Remove ConcatMapStreamTransformer -- functionality is already supported by asyncExpand. Keep the concatMap method as an alias.
    • Subjects
      • BehaviourSubject has been renamed to BehaviorSubject
      • The subjects have been rewritten and include far more testing
      • In keeping with the Rx idea of Subjects, they are broadcast-only
  • Documentation -- extensive documentation has been added to the library with explanations and examples for each Future, Stream & Transformer.
    • Docs detailing the differences between RxDart and raw Observables.

0.9.0

  • Api Changes:
    • Convert all StreamTransformer factories to proper classes
      • Ensure these classes can be re-used multiple times
    • Retry has moved from an operator to a constructor. This is to ensure the stream can be properly re-constructed every time in the correct way.
    • Streams now properly enforce the single-subscription contract
  • Include example Flutter app. To run it, please follow the instructions in the README.

0.8.3+1

  • rename examples map to example

0.8.3

  • added concatWith, zipWith, mergeWith, skipUntil
  • cleanup of the examples folder
  • cleanup of examples code
  • added fibonacci example
  • added search GitHub example

0.8.2+1

  • moved repo into ReactiveX
  • update readme badges accordingly

0.8.2

  • added materialize/dematerialize
  • added range (factory)
  • added timer (factory)
  • added timestamp
  • added concatMap

0.8.1

  • added never constructor
  • added error constructor
  • moved code coverage to codecov.io

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

example/example.dart

import 'package:rxdart/rxdart.dart';

/// generate n-amount of fibonacci numbers
///
/// for example: dart fibonacci.dart 10
/// outputs:
/// 1: 1
/// 2: 1
/// 3: 2
/// 4: 3
/// 5: 5
/// 6: 8
/// 7: 13
/// 8: 21
/// 9: 34
/// 10: 55
/// done!
void main(List<String> arguments) {
  // read the command line argument, if none provided, default to 10
  var n = (arguments.length == 1) ? int.parse(arguments.first) : 10;

  // seed value: this value will be used as the
  // starting value for the [scan] method
  const seed = const IndexedPair(1, 1, 0);

  Observable
      // amount of numbers to compute
      .range(1, n)
      // accumulator: computes a new accumulated
      // value each time a [Stream] event occurs
      // in this case, the accumulated value is always
      // the latest Fibonacci number
      .scan((IndexedPair seq, _, __) => new IndexedPair.next(seq), seed)
      // finally, print the output
      .listen(print, onDone: () => print('done!'));
}

class IndexedPair {
  final int n1, n2, index;

  const IndexedPair(this.n1, this.n2, this.index);

  factory IndexedPair.next(IndexedPair prev) => new IndexedPair(
      prev.n2, prev.index <= 1 ? prev.n1 : prev.n1 + prev.n2, prev.index + 1);

  @override
  String toString() => '$index: $n2';
}

Use this package as a library

1. Depend on it

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


dependencies:
  rxdart: ^0.18.1

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or flutter packages 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';
  
Version Uploaded Documentation Archive
0.18.1 Jul 3, 2018 Go to the documentation of rxdart 0.18.1 Download rxdart 0.18.1 archive
0.18.0 Jun 19, 2018 Go to the documentation of rxdart 0.18.0 Download rxdart 0.18.0 archive
0.17.0 Jun 7, 2018 Go to the documentation of rxdart 0.17.0 Download rxdart 0.17.0 archive
0.16.7 May 2, 2018 Go to the documentation of rxdart 0.16.7 Download rxdart 0.16.7 archive
0.16.6 Apr 2, 2018 Go to the documentation of rxdart 0.16.6 Download rxdart 0.16.6 archive
0.16.5 Mar 30, 2018 Go to the documentation of rxdart 0.16.5 Download rxdart 0.16.5 archive
0.16.4 Mar 29, 2018 Go to the documentation of rxdart 0.16.4 Download rxdart 0.16.4 archive
0.16.3 Mar 28, 2018 Go to the documentation of rxdart 0.16.3 Download rxdart 0.16.3 archive
0.16.2 Mar 28, 2018 Go to the documentation of rxdart 0.16.2 Download rxdart 0.16.2 archive
0.16.1 Mar 27, 2018 Go to the documentation of rxdart 0.16.1 Download rxdart 0.16.1 archive

All 94 versions...

Popularity:
Describes how popular the package is relative to other packages. [more]
99
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
99
Learn more about scoring.

We analyzed this package on Aug 10, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0
  • pana: 0.11.8

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:rxdart/rxdart.dart.

Suggestions

Package is pre-v1 release.

While there is nothing inherently wrong with versions of 0.*.*, it usually means that the author is still experimenting with the general direction of the API.

Format lib/src/observable.dart.

Run dartfmt to format lib/src/observable.dart.

Format lib/src/streams/utils.dart.

Run dartfmt to format lib/src/streams/utils.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev <3.0.0
Dev dependencies
benchmark_harness >=1.0.0 <2.0.0
browser ^0.10.0+2
coverage 0.11.0
stack_trace ^1.9.2
test 1.0.0