rx 0.0.4

  • Readme
  • Changelog
  • Example
  • Installing
  • 74

Reactive Dart #

Pub Package Build Status Coverage Status GitHub Issues GitHub Forks GitHub Stars GitHub License

Reactive Extensions Library for Dart providing an API for asynchronous programming with observable streams.

Reactive is created in the style of ReactiveX, and does not depend on Dart Streams. At this point this code is quite experimental, and might miss features or have serious bugs.

The package depends on the latest development version of Dart 2.6.0-dev.8.0. It does not work with earlier version due to extensive use of static extension methods.

This library is open source and well tested. Development happens on GitHub. Feel free to report issues or create a pull-request there. General questions are best asked on StackOverflow.

The package is hosted on dart packages. Up-to-date class documentation is created with every release.

License #

The MIT License, see LICENSE.

Changelog #

0.0.4 #

  • Operators as static extension methods.
  • More operators, converters, and constructors.

0.0.3 #

  • Subject and multicast basics.

0.0.2 #

  • Operator and composition basics.

0.0.1 #

  • Initial version.

example/example.dart

library rx.example.example;

import 'package:more/collection.dart';
import 'package:rx/constructors.dart' as rx;
import 'package:rx/converters.dart';
import 'package:rx/core.dart';
import 'package:rx/operators.dart';

Observer<T> printObserver<T>(String name) => Observer(
      next: (value) => print('$name.next($value)'),
      error: (error, [stackTrace]) => print('$name.error($error)'),
      complete: () => print('$name.complete()'),
    );

void main() {
  // concat
  final concat = rx.concat([
    [1, 2].toObservable(),
    rx.just(3)
  ]);
  concat.subscribe(printObserver('concat'));

  // create
  final create = rx.create((subscriber) {
    for (var i = 0; i < 3; i++) {
      subscriber.next(i);
    }
    subscriber.complete();
  });
  create.subscribe(printObserver('create'));

  // defer
  final defer = rx.defer(() => rx.just(42));
  defer.subscribe(printObserver('defer'));

  // empty
  final empty = rx.empty();
  empty.subscribe(printObserver('empty'));

  // future
  final fromFuture = Future.value(42).toObservable();
  fromFuture.subscribe(printObserver('fromFuture'));

  final toFuture = [1, 2, 3].toObservable().toFuture();
  toFuture.then((value) => print('toFuture.then($value)'));

  // iff
  final iff = rx.iff(() => true, rx.just(true), rx.just(false));
  iff.subscribe(printObserver('iff'));

  // just
  final just = rx.just(42);
  just.subscribe(printObserver('just'));

  // merge
  final merge = rx.merge([
    rx.just(1),
    [2, 3].toObservable()
  ]);
  merge.subscribe(printObserver('merge'));

  // never
  final never = rx.never();
  never.subscribe(printObserver('never'));

  // stream
  final fromStream = Stream.fromIterable([1, 2, 3]).toObservable();
  fromStream.subscribe(printObserver('fromStream'));

  final toStream = [1, 2, 3].toObservable().toStream();
  toStream.listen((value) => print('toStream.value($value)'));

  // throwError
  final throwError = rx.throwError(Exception('Hello World'));
  throwError.subscribe(printObserver('throw'));

  // double subscription
  final transformed = IntegerRange(0, 100)
      .toObservable()
      .where((value) => value.isEven)
      .map((value) => '${value * value}')
      .where((value) => value.length < 2);
  transformed.subscribe(printObserver('one'));
  transformed.subscribe(printObserver('two'));

  // subject subscription
  final subject =
      IntegerRange(0, 100, 25).toObservable().publishReplay().refCount();
  subject.subscribe(printObserver('subject1'));
  subject.subscribe(printObserver('subject2'));

  // timer
  final obs = rx.timer(
      delay: const Duration(seconds: 2),
      period: const Duration(milliseconds: 500));
  final subs1 = obs.subscribe(printObserver('first'));
  final subs2 = obs.subscribe(printObserver('second'));
  rx
      .timer(delay: const Duration(seconds: 3))
      .subscribe(Observer(complete: () => subs1.unsubscribe()));
  rx
      .timer(delay: const Duration(seconds: 5))
      .subscribe(Observer(complete: () => subs2.unsubscribe()));

  // zip
  final zip = rx.zip<Object>([
    <Object>[1, 2, 3].toObservable(),
    <Object>['a', 'b'].toObservable(),
  ]);
  zip.subscribe(printObserver('zip'));
}

Use this package as a library

1. Depend on it

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


dependencies:
  rx: ^0.0.4

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

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

3. Import it

Now in your Dart code, you can use:


import 'package:rx/constructors.dart';
import 'package:rx/converters.dart';
import 'package:rx/core.dart';
import 'package:rx/observables.dart';
import 'package:rx/operators.dart';
import 'package:rx/schedulers.dart';
import 'package:rx/shared.dart';
import 'package:rx/subjects.dart';
import 'package:rx/subscriptions.dart';
import 'package:rx/testing.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
53
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
74
Learn more about scoring.

We analyzed this package on Nov 7, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.6.0
  • pana: 0.12.21

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in libraries.

Maintenance suggestions

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.6.0-dev <3.0.0
collection ^1.14.0 1.14.12
meta ^1.1.0 1.1.8
more ^1.18.0 1.18.2
Dev dependencies
test ^1.6.0