{"size": 1010, "ext": "js", "max_stars_repo_path": "src/stores/grid.store/grid.store.js", "max_stars_repo_name": "ivitivan/minesweeper", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/stores/grid.store/grid.store.js", "max_issues_repo_name": "ivitivan/minesweeper", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/stores/grid.store/grid.store.js", "max_forks_repo_name": "ivitivan/minesweeper", "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": 28.8571428571, "max_line_length": 72, "alphanum_fraction": 0.6811881188}
import {ReduceStore} from 'flux/utils';
import Dispatcher from '../../dispatcher';
import ActionConstants from '../../action-constants';
import Grid from '../../lib/grid';

class GridStore extends ReduceStore {

  getInitialState() {
    return new Grid(9, 9, 10);
  }

  reduce(state, action) {
    console.log('action', action);
    const {type, payload} = action;
    switch (type) {
      case ActionConstants.CELL_OPEN:
        return state.open(payload.cell.x, payload.cell.y);
      case ActionConstants.CELL_FLAG:
        return state.flag(payload.cell.x, payload.cell.y);
      case ActionConstants.CELL_UNFLAG:
        return state.unflag(payload.cell.x, payload.cell.y);
      case ActionConstants.GRID_CHANGE:
        return state.changeGrid(payload.m, payload.n, payload.occupied);
      case ActionConstants.GAME_NEW:
        return state.new(state.m, state.n, state.countOccupied);
      default: return state;
    }
  }

}

const instance = new GridStore(Dispatcher);
export default instance;

