{"size": 510, "ext": "js", "max_stars_repo_path": "src/js/Sockets/updateTimer.js", "max_stars_repo_name": "imizaac/SharedCanvas", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/js/Sockets/updateTimer.js", "max_issues_repo_name": "imizaac/SharedCanvas", "max_issues_repo_issues_event_min_datetime": "2018-03-26T04:20:55.000Z", "max_issues_repo_issues_event_max_datetime": "2018-05-11T02:17:55.000Z", "max_forks_repo_path": "src/js/Sockets/updateTimer.js", "max_forks_repo_name": "imizaac/SharedCanvas", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 18, "max_forks_count": null, "avg_line_length": 28.3333333333, "max_line_length": 69, "alphanum_fraction": 0.6901960784}
// @flow
import { setTimerValue, setDrawingEnabled } from '../actionCreators';
import { subscribeToTimer } from './sockets';
import store from '../store';

// TODO: handle call with illegal time value (0 or less)
const startTimer = (duration: number) => {
  store.dispatch(setTimerValue(duration));
  subscribeToTimer(duration, (err, newValue) => {
    store.dispatch(setTimerValue(newValue));
    if (newValue === 0) {
      store.dispatch(setDrawingEnabled(true));
    }
  });
};

export default startTimer;
