redux_future 0.1.3

  • README.md
  • CHANGELOG.md
  • Installing
  • Versions
  • 31

redux_future

Build Status codecov

A Redux Middleware for handling Dart Futures as actions, with support for loading & optimistic payloads.

The futureMiddleware can be attached to the Redux Store upon construction.

Once attached, you can store.dispatch a Future or FutureAction, and the futureMiddleware will intercept it.

  • If the Future / FutureAction completes successfully, a FutureFulfilledAction will be dispatched with the result of the future.
  • If the Future / FutureAction fails, a FutureRejectedAction will be dispatched containing the error that was returned.

Examples


main() {
  // First, create a reducer that knows how to handle the Future Actions:
  // `FutureFulfilledAction` and `FutureRejectedAction`.
  String exampleReducer(String state, action) {
    if (action is String) {
      return action;
    } else if (action is FutureFulfilledAction<String>) {
      return action.result;
    } else if (action is FutureRejectedAction<Exception>) {
      return action.error.toString();
    }
  
    return state;
  }
  
  // Next, create a Store that includes `futureMiddleware`. It will
  // intercept all `FutureAction`s that are dispatched.
  final store = new Store(
    exampleReducer,
    middleware: [futureMiddleware],
  );
  
  // Next, dispatch some actions!
  
  // In this example, once the Future completes, a `FutureFulfilledAction`
  // will be dispatched with "Hi" as the result. The `exampleReducer` will
  // take the result of this action and update the state of the Store!
  store.dispatch(new Future.value("Hi"));
  
  // In this example, the initialAction String "Fetching" will be
  // immediately dispatched. After the future completes, the
  // "Search Results" will be dispatched.
  store.dispatch(new FutureAction(
    new Future.value("Search Results"),
    initialAction: "Fetching"));
  
  // In this example, the future will complete with an error. When that
  // happens, a `FutureRejectedAction` will be dispatched to your store,
  // and the state will be updated by the `exampleReducer`.
  store.dispatch(new Future.error("Oh no!"));
}

Contributors

Changelog

0.1.3

  • Dispatch initialAction through the entire Middelware chain. Fix contributed by Kezhu Wang!

0.1.2

  • Fix FutureAction incorrect type parameter. Fix contributed by Kezhu Wang!

0.1.1

  • Move to Github
  • Add the ability to await the resulting action (Fulfilled or Rejected) after it has been dispatched to the store.
  • Added FutureResultAction as base class for Fulfilled / Rejected actions.

0.1.0

  • Initial version, includes a futureMiddleware that intercepts Futures and FutureActions, captures their results, and dispatches their results as Redux actions.
  • Included classes
    • FutureAction
    • FutureFulfilledAction
    • FutureRejectedAction

Use this package as a library

1. Depend on it

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


dependencies:
  redux_future: ^0.1.3

2. Install it

You can install packages from the command line:

with pub:


$ pub get

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

3. Import it

Now in your Dart code, you can use:


import 'package:redux_future/redux_future.dart';
  
Version Uploaded Documentation Archive
0.1.3 Dec 4, 2017 Go to the documentation of redux_future 0.1.3 Download redux_future 0.1.3 archive
0.1.2 Dec 4, 2017 Go to the documentation of redux_future 0.1.2 Download redux_future 0.1.2 archive
0.1.1 Nov 26, 2017 Go to the documentation of redux_future 0.1.1 Download redux_future 0.1.1 archive
0.1.0 Aug 27, 2017 Go to the documentation of redux_future 0.1.0 Download redux_future 0.1.0 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
62
Health:
Code health derived from static analysis. [more]
0
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
0
Overall:
Weighted score of the above. [more]
31
Learn more about scoring.

The package version is not analyzed, because it does not support Dart 2. Until this is resolved, the package will receive a health and maintenance score of 0.

Issues and suggestions

Support Dart 2 in pubspec.yaml.

The SDK constraint in pubspec.yaml doesn't allow the Dart 2.0.0 release. For information about upgrading it to be Dart 2 compatible, please see https://www.dartlang.org/dart-2#migration.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.23.0 <2.0.0