distinct_value_connectable_observable 1.0.0+1

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

A library for Dart developers.

Created from templates made available by Stagehand under a BSD-style license.

Usage #

A simple usage example:

import 'package:distinct_value_connectable_observable/distinct_value_connectable_observable.dart';

main() {
  DistinctValueConnectableObservable(
      Stream.fromIterable([1, 2, 3]),
      seedValue: [1],
  );
}

Features and bugs #

Please file feature requests and bugs at the issue tracker.

1.0.0 #

  • Initial version, created by Stagehand

1.0.0+1 #

  • Some refactors, update readme.md

example/distinct_value_connectable_observable_example.dart

import 'package:distinct_value_connectable_observable/distinct_value_connectable_observable.dart';
import 'package:meta/meta.dart';
import 'package:rxdart/rxdart.dart';

class CounterBloc {
  ///
  /// Inputs
  ///
  final void Function(int) increment;
  final void Function(int) decrement;

  ///
  /// Outputs
  ///
  final ValueObservable<int> state;

  ///
  /// Clean up
  ///
  final void Function() dispose;

  CounterBloc._({
    @required this.increment,
    @required this.decrement,
    @required this.state,
    @required this.dispose,
  });

  factory CounterBloc() {
    final incrementController = PublishSubject<int>();
    final decrementController = PublishSubject<int>();

    final state = DistinctValueConnectableObservable(
      Observable.merge(<Stream<int>>[
        incrementController,
        decrementController.map((i) => -i),
      ]).scan<int>((acc, e, _) => acc + e, 0),
      seedValue: 0,
    );

    final subscription = state.connect();

    return CounterBloc._(
      increment: incrementController.add,
      decrement: decrementController.add,
      state: state,
      dispose: () async {
        await subscription.cancel();
        await Future.wait([incrementController, decrementController].map((c) => c.close()));
      },
    );
  }
}

main() async {
  var counterBloc = CounterBloc();
  print(counterBloc.state.value);

  var listen = counterBloc.state.listen((i) => print('[LOGGER] state=$i'));
  counterBloc.increment(0);
  counterBloc.increment(2);
  counterBloc.decrement(2);
  counterBloc.decrement(2);
  counterBloc.decrement(2);
  counterBloc.increment(2);
  counterBloc.increment(2);
  counterBloc.increment(0);
  counterBloc.increment(0);
  counterBloc.increment(0);
  counterBloc.increment(0);
  counterBloc.increment(0);

  await Future.delayed(Duration(seconds: 5));

  await listen.cancel();
  await counterBloc.dispose();
}

Use this package as a library

1. Depend on it

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


dependencies:
  distinct_value_connectable_observable: ^1.0.0+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:distinct_value_connectable_observable/distinct_value_connectable_observable.dart';
  
Version Uploaded Documentation Archive
1.0.0+1 Feb 1, 2019 Go to the documentation of distinct_value_connectable_observable 1.0.0+1 Download distinct_value_connectable_observable 1.0.0+1 archive
1.0.0 Feb 1, 2019 Go to the documentation of distinct_value_connectable_observable 1.0.0 Download distinct_value_connectable_observable 1.0.0 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
43
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
92
Overall:
Weighted score of the above. [more]
70
Learn more about scoring.

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

  • Dart: 2.1.0
  • pana: 0.12.13

Platforms

Detected platforms: Flutter, web, other

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

Maintenance suggestions

The package description is too short. (-8 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
rxdart ^0.20.0 0.20.0
Dev dependencies
meta ^1.1.7
mockito ^3.0.0
pedantic ^1.0.0
test ^1.0.0