rxdart 0.6.0


Native Dart rx implementation

rxdart #

Build Status Coverage Status Pub

Update This library no longer depends on RxJs and JS interop, instead it now aims to provide a native Dart implementation of Rx, allowing usage of this library in server side (or Flutter) projects as well.

Currently supported

 /// Use the observable method to wrap a Dart stream and add Rx operators to it
 Observable oStream = observable(myStream);
 /// Below operators are now available, next to the original Stream ones (map, where, ...)
 /// the following are contructors
 new Observable
    .combineLatest (deprecated - see below)
    .zip (deprecated - see below)
 /// To better support strong mode, combineLatest and zip
 /// have now been pulled apart into fixed-length constructors.
 /// These methods are available as static methods, since class
 /// factory methods don't support generic method types.
 /// BehaviourSubject and ReplaySubject are available
 /// The default StreamController functions as a PublishSubject
 /// On listen, receive the last added event
 StreamController controllerA = new BehaviourSubject();
 /// On listen, receive all past events
 StreamController controllerB = new ReplaySubject();


void main() {
  var codes = <int>[
      38, // up
      38, // up
      40, // down
      40, // down
      37, // left
      39, // right
      37, // left
      39, // right
      66, // b
      65  // a
  var result = querySelector('#result');
  var controller = new StreamController<KeyboardEvent>();
  var stream = rx.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))
    .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;