soggybag / tetris-redux-app

Tetris built with React and Redux
https://soggybag.github.io/tetris-redux-app/
4 stars 6 forks source link

Save High Score to Local Storage #6

Closed soggybag closed 5 years ago

soggybag commented 5 years ago

It would be great of the game saved high scores and other data to local storage.

Follow the guide here: https://github.com/MakeSchool-Tutorials/web-7-react-redux-timers-app/blob/master/P10-Persisting-Timers/content.md

There are a couple approaches to take.

  1. Save all of the game info to local storage. In this case high score could be added the game state object in the gameReducer. Using this method you'd be able to save the entire game and return to a game in progress. The downside might be performance since local storage is synchronous. Performance issues might be handled by throttling.
  2. Save only high scores. Follow the guide to set up local storage. Add a new property on state to hold the high score. You need only update and save the score when the score changes.

In either case the high score can be saved to on the game state object in the reducer along with all of the other game data. An alternative would be to create a new reducer just for high scores and save the data there. This would require a new reducer and that reducer would need to be added to the root reducer. The advantage to this might be simplified state management.

ryanlsmith4 commented 5 years ago

Taking this one on!

ryanlsmith4 commented 5 years ago

Done and submitted pull request!

soggybag commented 5 years ago

Thanks, closed.