lore-hook-bind-actions

Binds all actions to the dispatch method of the Redux store

Example Usage

In Lore, invoking action creators is as simple as something like this:

lore.actions.tweet.create({
  text: 'Message to tweet'
});

This call invokes the action creator, makes an AJAX calls, and dispatches the result to the Redux Store. But if you look at the signature for the create action, you may wonder where the dispatch argument comes from:

module.exports = function create(params) {
  return function(dispatch) {
    // ...code for the action creator...
  };
};

If you read the Redux docs for bindActionCreators you'll notice that action creators are not normally bound to the Redux store. They're "pure" in the sense that they're just a function with some arguments. The bindActionCreators method is what actually takes the dispatch method from the Redux store and binds it to the action creator, so it can dispatch messages to the Store.

This hook iterates through all actions and binds them to the Redux store. This means instead of having to write code like this all over your application:

import { bindActionCreators } from 'redux'

let createAction = bindActionCreators(
  lore.actions.tweet.create,
  lore.store.dispatch
);

createAction({
  text: 'Message to tweet'
})

You can simply write this:

lore.actions.tweet.create({
  text: 'Message to tweet'
});