redux_thunk 0.4.0 copy "redux_thunk: ^0.4.0" to clipboard
redux_thunk: ^0.4.0 copied to clipboard

A Redux.dart Middleware that allows you to dispatch functions that perform async work as actions.

example/example.dart

import 'dart:async';

import 'package:redux/redux.dart';
import 'package:redux_thunk/redux_thunk.dart';

void main() {
  // First, create a quick reducer
  String reducer(String state, dynamic action) =>
      action is String ? action : state;

  // Next, apply the `thunkMiddleware` to the Store
  final store = Store<String>(
    reducer,
    initialState: '',
    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!
  void action(Store<String> store) async {
    var searchResults = await Future.delayed(
      Duration(seconds: 1),
      () => 'Search Results',
    );

    store.dispatch(searchResults);
  }

  // Dispatch the action! The `thunkMiddleware` will intercept and invoke
  // the action function.
  store.dispatch(action);
}
63
likes
140
pub points
95%
popularity

Publisher

unverified uploader

A Redux.dart Middleware that allows you to dispatch functions that perform async work as actions.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

redux

More

Packages that depend on redux_thunk