{"size": 1516, "ext": "js", "max_stars_repo_path": "storefront/src/store/actions.js", "max_stars_repo_name": "401-advanced-javascript-raghad/storefront-new", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "storefront/src/store/actions.js", "max_issues_repo_name": "401-advanced-javascript-raghad/storefront-new", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "storefront/src/store/actions.js", "max_forks_repo_name": "401-advanced-javascript-raghad/storefront-new", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 19.9473684211, "max_line_length": 76, "alphanum_fraction": 0.5382585752}
import superagent from 'superagent';


let api = 'http://api-testtt.herokuapp.com/api/v1/products'; 

// this dispatch is not the "dispatch" from redux
export const getRemoteData =() => dispatch => {

    // call my data 
    return superagent.get(api)
        .then(data => {
            // dispatch the action getAction
            dispatch(getAction(data.body))
        });
}

export const putRemoteData = (id, data) => async dispatch => {
    let response = await (await superagent.put(`${api}/${id}`)).send(data);
    // dispatch action for the update
    // dispatch(putAction(response))
    // console.log(response)
}


// we are dispatching the function of the action
// dispatch(getAction())

export const getAction = payload => {
    return {
        type: 'GET',
        payload: payload
    }
}

export const putAction = payload => {
    return {
        type: 'PUT',
        payload: payload
    }
}

export const postAction = payload => {
    return {
        type: 'POST',
        payload: payload
    }
}

export const deleteAction = payload => {
    return {
        type: 'DELETE',
        payload: payload
    }
}


export const activate = (name) => {
    return {
      type: 'ACTIVATE',
      payload: name
    }
  }

  export const add = (name) => {
    return {
        type: 'ADD-TO-CART',
        payload: name
    }
}

export const remove = (id) => {
    return {
        type: 'REMOVE',
        payload: id
    }
}