redux_thunk 0.2.0

  • README.md
  • CHANGELOG.md
  • Installing
  • Versions
  • 93

redux_thunk

Build Status codecov

Redux provides a simple way to update a your application's State in response to synchronous Actions. However, it lacks tools to handle asynchronous code. This is where Thunks come in.

The thunkMiddleware intercepts and calls ThunkActions, which is simply a fancy name for any function that takes 1 argument: a Redux Store. This allows you to dispatch functions (aka ThunkActions) to your Store that can perform asynchronous work, then dispatch actions using the Store after the work is complete.

The dispatched ThunkActions will be swallowed, meaning they will not go through the rest of your middleware to the Store's Reducer.

Example

// First, create a quick reducer
final reducer = (String state, action) =>
    action is String ? action : state;

// Next, apply the `thunkMiddleware` to the Store
final store = new Store<String>(
  reducer,
  middleware: [thunkMiddleware],
);

// Create a `ThunkAction`, which is any function that accepts the 
// Store as it's only argument. Our function (aka ThunkAction) will
// simply send an action after 1 second.  This is just an example, 
// but  in real life, you could make a call to an HTTP service or 
// database instead!
final action = (Store<String> store) async {
  final searchResults = await new Future.delayed(
    new Duration(seconds: 1),
    () => "Search Results",
  );

  store.dispatch(searchResults);
};

Credits

All the ideas in this lib are shamelessly stolen from the original redux-thunk library and simply adapted to Dart.

Changelog

0.2.0

  • Update to work with Redux 3.0.0 & Dart 2

0.1.1

  • Move to github

0.1.0

  • Initial version, includes a thunkMiddleware, which intercepts and calls functions that are dispatched to the Store.

1. Depend on it

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


dependencies:
  redux_thunk: "^0.2.0"

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 packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:redux_thunk/redux_thunk.dart';
        
Version Uploaded Documentation Archive
0.2.0 Mar 31, 2018 Go to the documentation of redux_thunk 0.2.0 Download redux_thunk 0.2.0 archive
0.1.1 Nov 25, 2017 Go to the documentation of redux_thunk 0.1.1 Download redux_thunk 0.1.1 archive
0.1.0 Aug 27, 2017 Go to the documentation of redux_thunk 0.1.0 Download redux_thunk 0.1.0 archive

Analysis

We analyzed this package on Apr 23, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0-dev.49.0
  • pana: 0.10.6

Scores

Popularity:
Describes how popular the package is relative to other packages. [more]
86 / 100
Health:
Code health derived from static analysis. [more]
100 / 100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100 / 100
Overall score:
Weighted score of the above. [more]
93
Learn more about scoring.

Platforms

Detected platforms: Flutter, web, other

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

Suggestions

  • The description is too short.

    Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

  • Package is pre-v1 release.

    While there is nothing inherently wrong with versions of 0.*.*, it usually means that the author is still experimenting with the general direction API.

  • Maintain an example.

    Create a short demo in the example/ directory to show how to use this package. Common file name patterns include: main.dart, example.dart or you could also use redux_thunk.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.28.0 <3.0.0
redux >=3.0.0 <4.0.0 3.0.0
Dev dependencies
test >=0.12.33 <0.13.0