import * as WelcomeActions from '../../actions/welcome/welcome.actions'; import * as ModeActions from '../../actions/mode.actions'; import SETTINGS from '../../AppSettings'; let dispatch; const emptyScores = JSON.stringify([ { initials: "AAA", score: "0" }, { initials: "AAA", score: "0" }, { initials: "AAA", score: "0" }, { initials: "AAA", score: "0" }, { initials: "AAA", score: "0" }, ]); const WelcomeCtrl = { setDispatch: (d) => dispatch = d, // Note: If storage has not been set, it will be populated here with empty scores. updateFromLocalStorage: () => { const scores = JSON.parse(localStorage.getItem(SETTINGS.LOCAL_STORAGE_KEY) || emptyScores); localStorage.setItem(SETTINGS.LOCAL_STORAGE_KEY, JSON.stringify(scores)); dispatch(WelcomeActions.updateScores(scores)); }, keydown: (e) => { if (e.keyCode === 32 || e.keyCode === 13) { dispatch(ModeActions.options()); } } }; export default WelcomeCtrl;