<commit_before>var dispatcher = require('../dispatcher');
module.exports = function(config){
  config = config || {};
  config.type = config.type || 'update';
  if(!config.service){
    throw new Error('You need to provide a service');
  }
  if(!config.service){
    throw new Error('You need to provide a service to call');
  }

  if(!config.data){
    throw new Error('You need to provide an action data');
  }
  return config.service(config.data).then(function(jsonData){
    dispatcher.handleServerAction({
      data: {[config.property]: jsonData},
      type: config.type
    });
  }, function actionError(err){
    console.warn('Error in action', err);
    throw new Error('An errror occurs');
  });
};<commit_msg>[action-builder] Add an action builder.<commit_after>var dispatcher = require('../dispatcher');
function preServiceCall(config){
  dispatcher.handleViewAction({
    data: {[config.node]: undefined},
    type: config.type,
    status: {[config.type]: config.preStatus, isLoading: true}
  });
}
function postServiceCall(config, json){
  dispatcher.handleServerAction({
    data: {[config.node]: json},
    type: config.type,
    status: {[config.type]: config.status, isLoading: false}
  });
}

module.exports = function(config){
  config = config || {};
  config.type = config.type || 'update';
  config.preStatus = config.preStatus || 'loading';
  if(!config.service){
    throw new Error('You need to provide a service to call');
  }
  if(!config.status){
    throw new Error('You need to provide a status to your action');
  }
  /*if(!config.data){
    throw new Error('You need to provide an action data');
  }*/
  //Exposes a function consumes by the compoennt.
  return function(criteria){
    preServiceCall(config);
    return config.service(criteria).then(function(jsonData){
      postServiceCall(config, jsonData);
    }, function actionError(err){
      console.warn('Error in action', err);
      //Get code back from a project
      throw new Error('An errror occurs');
    });
  };
};
{'fraction_non_alphanumeric': 0.1490837048043586, 'fraction_numerical': 0.0, 'mean_word_length': 3.798099762470309, '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': '6061037', 'n_tokens_mistral': 595, 'n_tokens_neox': 593, 'n_words': 167}