dart_saga 0.3.0

[WIP][poc] Port of redux-saga to Dart

Redux-saga like process manager for Dart.

This library supports communication pattern between isolates through 'cannel'.

Note: This package is still under development, and many of functionality might not be available yet. Feedback and Pull Requests are most welcome!

Sample code #

import "dart:async";
import 'package:dart_saga/dart_saga.dart';

rootSaga([msg, greeting]) async* {
  print("rootSaga(${msg}) started greeting: ${greeting}");
  Completer<int> saga2handle = new Completer();
  yield fork(saga2, params: ["start saga2"], completer: saga2handle);

  for (int i = 0; i < 10; i++) {
    yield wait(1);
    if (i == 5) {
      yield cancel(await saga2handle.future);
    }
  }
}

saga2([msg]) async* {
  print("           saga2(${msg}) started");
  Completer<int> saga3handle;
  yield fork(saga3, params: ["start saga3"], completer: saga3handle);

  for (int i = 0; true; i++) {
    print("           saga2");
    yield wait(1);
    yield put(Action("HOGE", "From saga2"));
    if (i == 3) {
      yield cancel(await saga3handle.future);
    }
  }
}

saga3([msg]) async* {
  print("                      saga3(${msg}) started");
  while (true) {
    print("                      saga3");
    Completer takenAction = new Completer();
    yield take("HOGE", completer: takenAction);
    print("                      taken ${await takenAction.future}");
  }
}

main() {
  var effectManager = new EffectManager();
  effectManager.run(rootSaga, ["start rootSaga", "hello"]);
}

Demo #

% pub run example/simple_demo.dart
start _isolate context
Task.start 0
rootSaga(start rootSaga) started greeting: hello
Task.start 1
           saga2(start saga2) started
           saga2
Task.start 2
                      saga3(start saga3) started
                      saga3
           saga2
                      taken Action(HOGE, From saga2)
                      saga3
           saga2
                      taken Action(HOGE, From saga2)
                      saga3
           saga2
                      taken Action(HOGE, From saga2)
                      saga3
Task(taskId=2) terminated: null.
Task(taskId=1) terminated: null.
Task(taskId=0) terminated: null.

Use this package as a library

1. Depend on it

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


dependencies:
  dart_saga: ^0.3.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:dart_saga/dart_saga.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
10
Health:
Code health derived from static analysis. [more]
91
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
9
Overall:
Weighted score of the above. [more]
34
Learn more about scoring.

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

  • Dart: 2.6.1
  • pana: 0.12.21

Health issues and suggestions

Document public APIs. (-1 points)

66 out of 66 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Fix lib/src/task.dart. (-4.41 points)

Analysis of lib/src/task.dart reported 9 hints, including:

line 49 col 30: Unnecessary new keyword.

line 50 col 31: Unnecessary new keyword.

line 51 col 29: Unnecessary new keyword.

line 67 col 26: Unnecessary new keyword.

line 69 col 50: Unnecessary new keyword.

Fix lib/src/effect.dart. (-1.99 points)

Analysis of lib/src/effect.dart reported 4 hints:

line 36 col 29: Use ; instead of {} for empty constructor bodies.

line 67 col 24: Unnecessary new keyword.

line 68 col 9: Unnecessary new keyword.

line 68 col 28: Unnecessary new keyword.

Fix lib/src/dispatcher.dart. (-1 points)

Analysis of lib/src/dispatcher.dart reported 2 hints:

line 10 col 7: Unnecessary new keyword.

line 10 col 47: Future results in async function bodies must be awaited or marked unawaited using package:pedantic.

Fix lib/dart_saga.dart. (-0.50 points)

Analysis of lib/dart_saga.dart reported 1 hint:

line 41 col 39: Avoid types as parameter names.

Fix lib/src/manager.dart. (-0.50 points)

Analysis of lib/src/manager.dart reported 1 hint:

line 10 col 5: Unnecessary new keyword.

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.

Package is getting outdated. (-50.96 points)

The package was last published 78 weeks ago.

The package description is too short. (-20 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.

Maintain an example.

None of the files in the package's example/ directory matches known example patterns.

Common filename patterns include main.dart, example.dart, and dart_saga.dart. Packages with multiple examples should provide example/README.md.

For more information see the pub package layout conventions.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.32.0 <3.0.0