{"size": 680, "ext": "js", "max_stars_repo_path": "src/actions/index.js", "max_stars_repo_name": "maxgfr/react-async-context", "max_stars_repo_stars_event_min_datetime": "2020-12-21T02:50:51.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-25T10:59:53.000Z", "max_issues_repo_path": "src/actions/index.js", "max_issues_repo_name": "maxgfr/react-async-context", "max_issues_repo_issues_event_min_datetime": "2022-02-13T22:22:35.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-27T11:04:13.000Z", "max_forks_repo_path": "src/actions/index.js", "max_forks_repo_name": "maxgfr/react-async-context", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 2, "max_issues_count": 2, "max_forks_count": null, "avg_line_length": 25.1851851852, "max_line_length": 59, "alphanum_fraction": 0.5720588235}
import {
  DOWN, UP, RESET, IS_LOADING,
} from '../constants';

function sleep(ms) {
  return new Promise((resolve) => setTimeout(resolve, ms));
}

export default function actions(dispatch) {
  return {
    asyncIncrement: (time) => {
      dispatch({ type: IS_LOADING, payload: true });
      sleep(time).then(() => {
        dispatch({ type: UP });
        dispatch({ type: IS_LOADING, payload: false });
      });
    },
    asyncDecrement: async () => {
      dispatch({ type: IS_LOADING, payload: true });
      await sleep(3000);
      dispatch({ type: DOWN });
      dispatch({ type: IS_LOADING, payload: false });
    },
    reset: () => dispatch({ type: RESET }),
  };
}
