react_async 0.1.0

react_async #

pub package

Provides components for building asynchronous user interfaces out of dart-react.

This makes easy to adopt the BloC pattern and share a major part of your Flutter application logic with a website since the components are inspired by their Flutter equivalent.

Quickstart #

The example below shows you how to use StreamBuilder and FutureBuilder.

import 'dart:async';
import 'dart:html';
import 'package:react_async/async.dart';
import 'package:react/react.dart';
import 'package:react/react_client.dart' as react_client;
import 'package:react/react_dom.dart' as react_dom;

/// An example model object that exposes a `Future` and a
/// `Stream`. Our components will be able to observe them,
/// and update in accordingly.
class Model {
  Future<String> future() async {
    await Future.delayed(Duration(seconds: 4));
    return "Finished!";
  }

  Stream<String> stream() async* {
    await Future.delayed(Duration(seconds: 1));
    yield "3";
    await Future.delayed(Duration(seconds: 1));
    yield "2";
    await Future.delayed(Duration(seconds: 1));
    yield "1";
    await Future.delayed(Duration(seconds: 1));
    yield "Finished!";
  }
}

/// An example component that will be updated asynchronously 
/// from our model.
class HomeComponent extends Component {
  final Model model = Model();

  /// A component instance that will be refreshed at the end
  /// of the model's future execution.
  dynamic _fromFuture() => FutureBuilder<String>(
    initialData: "Ready...",
    future: this.model.future(),
    builder: (s) => b({}, s.data));

  /// A component instance that will be refreshed on each update
  /// from the model's stream.
  dynamic _fromStream() => StreamBuilder<String>(
    initialData: "Ready...",
    stream: this.model.stream(),
    builder: (s) => b({}, s.data));

  @override
  render() => div({}, [
    div({}, [ "Future:", _fromFuture()]),
    div({}, [ "Stream:", _fromStream()]),
  ]);
}

var Home = registerComponent(() => HomeComponent());

main() {
  react_client.setClientConfiguration();
  react_dom.render(Home({}), querySelector('#react_mount_point'));
}

Issues #

Please file any issues, bugs, or feature requests on GitHub.

Use this package as a library

1. Depend on it

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


dependencies:
  react_async: ^0.1.0

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:react_async/async.dart';
import 'package:react_async/base/hash_codes.dart';
import 'package:react_async/base/renderers.dart';
import 'package:react_async/base/snapshot.dart';
import 'package:react_async/builders/future_builder.dart';
import 'package:react_async/builders/stream_builder.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
95
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
58
Overall:
Weighted score of the above. [more]
40
Learn more about scoring.

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

  • Dart: 2.6.1
  • pana: 0.12.21

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in libraries.

Health suggestions

Fix lib/base/snapshot.dart. (-3.45 points)

Analysis of lib/base/snapshot.dart reported 7 hints, including:

line 25 col 23: The class 'Stream' wasn't exported from 'dart:core' until version 2.1, but this code is required to be able to run on earlier versions.

line 39 col 15: The class 'Stream' wasn't exported from 'dart:core' until version 2.1, but this code is required to be able to run on earlier versions.

line 41 col 15: The class 'Future' wasn't exported from 'dart:core' until version 2.1, but this code is required to be able to run on earlier versions.

line 79 col 7: DO use curly braces for all flow control structures.

line 81 col 7: DO use curly braces for all flow control structures.

Fix lib/base/hash_codes.dart. (-1 points)

Analysis of lib/base/hash_codes.dart reported 2 hints:

line 6 col 27: Avoid const keyword.

line 116 col 7: DO use curly braces for all flow control structures.

Fix lib/builders/future_builder.dart. (-0.50 points)

Analysis of lib/builders/future_builder.dart reported 1 hint:

line 63 col 30: Avoid using null in if null operators.

Fix additional 3 files with analysis or formatting issues. (-0.50 points)

Additional issues in the following files:

  • lib/builders/stream_builder.dart (1 hint)
  • lib/async.dart (Run dartfmt to format lib/async.dart.)
  • lib/base/renderers.dart (Run dartfmt to format lib/base/renderers.dart.)

Maintenance issues and suggestions

Provide a file named CHANGELOG.md. (-20 points)

Changelog entries help developers follow the progress of your package. See the example generated by stagehand.

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (react).

Package is getting outdated. (-12.33 points)

The package was last published 58 weeks ago.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
meta ^1.1.6 1.1.8
react ^4.5.0 4.9.2 5.1.1
Transitive dependencies
js 0.6.1+1
Dev dependencies
build_runner >=0.8.10 <2.0.0
build_web_compilers >=0.3.6 <0.5.0