<commit_before>/* global ghost */
import axios from 'axios';

export const FETCH_HOME_CONTENTS = 'FETCH_HOME_CONTENTS';
export const FETCH_POSTS = 'FETCH_POSTS';
export const FETCH_POST = 'FETCH_POST';
export const LOADING = 'LOADING';
export const API_ERROR = 'API_ERROR';

export function fetchHomeContents() {
  const userDetails = axios.get(ghost.url.api('users', {
    fields: 'bio,image,name',
    limit: 1
  }));
  const initialPosts = axios.get(ghost.url.api('posts', {
    include: 'tags',
    fields: 'id,title,slug,image,tags,html',
    limit: 5
  }));
  return (dispatch) => {
    dispatch({
      type: LOADING,
      payload: { kind: FETCH_HOME_CONTENTS }
    });
    Promise.all([userDetails, initialPosts]).then(responses => dispatch({
      type: FETCH_HOME_CONTENTS,
      payload: {
        user: responses[0].data.users[0],
        posts: responses[1].data.posts
      }
    })).catch(error => dispatch({
      type: API_ERROR,
      payload: { kind: FETCH_HOME_CONTENTS, error }
    }));
  };
}

export function fetchPosts(limit = '5') {
  const request = axios.get(ghost.url.api('posts', { limit }));
  return (dispatch) => {
    dispatch({
      type: LOADING,
      payload: { kind: FETCH_POSTS }
    });
    request.then(({ data }) => {
      dispatch({ type: FETCH_POSTS, payload: data });
    }).catch((error) => {
      dispatch({
        type: API_ERROR,
        payload: { kind: FETCH_POSTS, error }
      });
    });
  };
}

export function fetchPost(slug) {
  const request = axios.get(ghost.url.api('posts', { slug }));
  return (dispatch) => {
    dispatch({
      type: LOADING,
      payload: { kind: FETCH_POST }
    });
    request.then(({ data }) => {
      dispatch({ type: FETCH_POST, payload: data });
    }).catch((error) => {
      dispatch({
        type: API_ERROR,
        payload: { kind: FETCH_POST, error }
      });
    });
  };
}
<commit_msg>Redux Actions, more controls through parameters<commit_after>/* global ghost */
import axios from 'axios';

export const FETCH_HOME_CONTENTS = 'FETCH_HOME_CONTENTS';
export const FETCH_POSTS = 'FETCH_POSTS';
export const FETCH_POST = 'FETCH_POST';
export const LOADING = 'LOADING';
export const API_ERROR = 'API_ERROR';

export function fetchHomeContents() {
  const userDetails = axios.get(ghost.url.api('users', {
    fields: 'bio,image,name',
    limit: 1
  }));
  const initialPosts = axios.get(ghost.url.api('posts', {
    include: 'tags',
    fields: 'id,title,slug,image,tags,html',
    limit: 5
  }));
  return (dispatch) => {
    dispatch({
      type: LOADING,
      payload: { kind: FETCH_HOME_CONTENTS }
    });
    Promise.all([userDetails, initialPosts]).then(responses => dispatch({
      type: FETCH_HOME_CONTENTS,
      payload: {
        user: responses[0].data.users[0],
        posts: responses[1].data.posts
      }
    })).catch(error => dispatch({
      type: API_ERROR,
      payload: { kind: FETCH_HOME_CONTENTS, error }
    }));
  };
}

export function fetchPosts(limit = '5', extras = null) {
  const request = axios.get(ghost.url.api('posts', { limit, ...(extras !== null ? extras : {}) }));
  return (dispatch) => {
    dispatch({
      type: LOADING,
      payload: { kind: FETCH_POSTS }
    });
    request.then(({ data }) => {
      dispatch({ type: FETCH_POSTS, payload: data });
    }).catch((error) => {
      dispatch({
        type: API_ERROR,
        payload: { kind: FETCH_POSTS, error }
      });
    });
  };
}

export function fetchPost(slug) {
  const request = axios.get(ghost.url.api('posts', { slug }));
  return (dispatch) => {
    dispatch({
      type: LOADING,
      payload: { kind: FETCH_POST }
    });
    request.then(({ data }) => {
      dispatch({ type: FETCH_POST, payload: data });
    }).catch((error) => {
      dispatch({
        type: API_ERROR,
        payload: { kind: FETCH_POST, error }
      });
    });
  };
}

{'fraction_non_alphanumeric': 0.16318099664342886, 'fraction_numerical': 0.003098373353989156, 'mean_word_length': 2.9091826437941473, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, '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': '5181655', 'n_tokens_mistral': 1332, 'n_tokens_neox': 1315, 'n_words': 276}