{"size": 470, "ext": "js", "max_stars_repo_path": "public/asset/js/common/api.js", "max_stars_repo_name": "mohamed0group/justcooking", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "public/asset/js/common/api.js", "max_issues_repo_name": "mohamed0group/justcooking", "max_issues_repo_issues_event_min_datetime": "2021-03-01T21:08:28.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-26T01:54:45.000Z", "max_forks_repo_path": "public/asset/js/common/api.js", "max_forks_repo_name": "mohamed0group/justcooking", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 3, "max_forks_count": null, "avg_line_length": 18.8, "max_line_length": 45, "alphanum_fraction": 0.5404255319}
import ajax from "./ajax.js";

const store = {};

/**
 * Get data from api
 * 
 * @param {String} apiPath 
 * @param {Function} callback 
 */
export default (apiPath, callback) => {
  if (store[apiPath]) {
    callback && callback(store[apiPath]);
  } else {
    ajax({
      url: `/api/${apiPath}.json`,
      method: 'get',
      dataType: 'json',
      success(data) {
        store[apiPath] = data;
        callback && callback(store[apiPath]);
      }
    });
  }
}