bindActionCreators

Map<String, void Function()> bindActionCreators(

  1. Map<String, Action Function()> actionCreators,
  2. void dispatch(
    1. Action
    )
)

Binds multiple action creators to a dispatch function.

This turns a map of action creators into a map with the same keys, but with every action creator wrapped into a dispatch call.

Example:

final actionCreators = {
  'increment': () => Increment(),
  'decrement': () => Decrement(),
};

final bound = bindActionCreators(actionCreators, store.dispatch); bound['increment']!(); // dispatches Increment

Implementation

Map<String, void Function()> bindActionCreators(
  Map<String, Action Function()> actionCreators,
  void Function(Action) dispatch,
) => actionCreators.map(
  (key, creator) => MapEntry(key, () => dispatch(creator())),
);