{"size": 1295, "ext": "js", "max_stars_repo_path": "frontend/src/stateMap.js", "max_stars_repo_name": "SteBry/mycroft", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "frontend/src/stateMap.js", "max_issues_repo_name": "SteBry/mycroft", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "frontend/src/stateMap.js", "max_forks_repo_name": "SteBry/mycroft", "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.9230769231, "max_line_length": 61, "alphanum_fraction": 0.5606177606}
import store from './state';

/* -- ACTIONS -- */
export const ADD_CAMERA = "ADD_CAMERA";
export const REMOVE_CAMERA = "REMOVE_CAMERA";

/* -- INITIAL STATE -- */
export const initialState = {
    cameras: {}
};

/* -- ACTION CREATORS -- */
/**
 * 
 * Creates an action used for adding a camera.
 * 
 * @param {Camera} cam Camera to add.
 * @return {action} Action for adding a camera.
 */
export function addCamera(cam) {
    return {
		type: ADD_CAMERA,
		cam: cam
    };
}

/**
 * 
 * Creates an action used for removing a camera.
 * 
 * @param {int} id Unique idenfitifier of a camera to remove.
 * @return {action} Action for removing a camera.
 */
export function removeCamera(id) {
    return {
        type: REMOVE_CAMERA,
        id: id
    };
}

/* -- REDUX REDUCER -- */
const mapReducer = (state = initialState, action) => {
    switch(action.type) {
    case ADD_CAMERA:
        return {
            ...state,
            cameras: {
                ...state.cameras,
                [action.cam.id]: action.cam
            }
        };
    case REMOVE_CAMERA:
        var cameras = {...state.cameras};
        delete cameras[action.id];
        return {
            ...state,
            cameras: cameras
        };
    default:
		return state;
    }
};

export default mapReducer;
