Giter VIP home page Giter VIP logo

rxdart's Introduction

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 run build_runner serve example
  4. Navigate to http://localhost:8080/web/ 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/example.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.

rxdart's People

Contributors

bcko avatar brianegan avatar charafau avatar darshangowda0 avatar dotdotcommadot avatar dustin-graham avatar edulpn avatar escamoteur avatar filiph avatar frankpepermans avatar ichenlei avatar kevmoo avatar long1eu avatar lwasyl avatar mishkun avatar simpler1 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.