<commit_before>/**
 * Actions are reponsible for performing the bulk of the "work" around a user
 * interaction. Any asynchronous logic (e.g. server calls) should live inside
 * of an Action, and the Action should result in one or more changes to state.
 * These changes are made through events broadcast on a Dispatcher.
 *
 * Materially-speaking, Actions are nothing more than functions. What is
 * provided by this module is a simple decorator to make integrating simple
 * Actions with a Dispatcher easier.
 */
var when = require('when');

/**
 * Decorates `fn(data)` with events most important for downstream Stores
 * listening through the `dispatcher`. For simple association between Actions
 * and Stores, `fn` must accept only one Object with all the data required
 * to perform the action. These Stores will listen on the `name`, with the
 * following three suffixes:
 *
 * If `fn` wishes to perform asynchronous work, it should return a Promise that
 * will be fulfilled with its result or rejected with an appropriate Error.
 *
 * - `name:pending`: The action has started, but has yet to complete. The
 *    original `data` is passed along to the Stores.
 * - `name:failed`: The action has failed. The reason String is passed along
 *    to the Stores.
 * - `name:succeeded`: The action has completed. The result of `fn` is passed
 *    along to the Stores.
 */
function action(dispatcher, name, fn) {
  return function (data) {
    dispatcher.dispatch(name + ':pending', data);

    return when(data, fn)
      .then(function (result) {
        dispatcher.dispatch(name + ':succeeded', result);
      }, function (err) {
        dispatcher.dispatch(name + ':failed', err.message || String(err));
      });
  };
}

/*!
 * Export `action`.
 */
module.exports = action;<commit_msg>Action: Name action functions.<commit_after>/**
 * Actions are reponsible for performing the bulk of the "work" around a user
 * interaction. Any asynchronous logic (e.g. server calls) should live inside
 * of an Action, and the Action should result in one or more changes to state.
 * These changes are made through events broadcast on a Dispatcher.
 *
 * Materially-speaking, Actions are nothing more than functions. What is
 * provided by this module is a simple decorator to make integrating simple
 * Actions with a Dispatcher easier.
 */
var when = require('when');

/**
 * Decorates `fn(data)` with events most important for downstream Stores
 * listening through the `dispatcher`. For simple association between Actions
 * and Stores, `fn` must accept only one Object with all the data required
 * to perform the action. These Stores will listen on the `name`, with the
 * following three suffixes:
 *
 * If `fn` wishes to perform asynchronous work, it should return a Promise that
 * will be fulfilled with its result or rejected with an appropriate Error.
 *
 * - `name:pending`: The action has started, but has yet to complete. The
 *    original `data` is passed along to the Stores.
 * - `name:failed`: The action has failed. The reason String is passed along
 *    to the Stores.
 * - `name:succeeded`: The action has completed. The result of `fn` is passed
 *    along to the Stores.
 */
function makeAction(dispatcher, name, fn) {
  return function act(data) {
    dispatcher.dispatch(name + ':pending', data);

    return when(data, fn)
      .then(function (result) {
        dispatcher.dispatch(name + ':succeeded', result);
      }, function (err) {
        dispatcher.dispatch(name + ':failed', err.message || String(err));
      });
  };
}

/*!
 * Export `makeAction`.
 */
module.exports = makeAction;
{'fraction_non_alphanumeric': 0.0957387935805202, 'fraction_numerical': 0.0, 'mean_word_length': 3.6168582375478926, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6907525', 'n_tokens_mistral': 995, 'n_tokens_neox': 929, 'n_words': 454}