I've decided to attempt making the game of life in react/redux! I've decided to use react and redux mainly as a way to create a potential learning example for others, putting this stack to practical use. This stack includes:
- React
- Redux
- Duck Pattern
- Webpack
- Path resolution
- Immuatble JS
- BlueprintJS (UI Component Library)
- SASS Modules
This app contains a yarn.lock
file, if you wish you clone this repo and add dependencies, I recommend using yarn over npm
. However, if you just wish to checkout the examples in the code, npm
will do fine.
- First clone the repository
- Change directories:
cd game-of-life-react
- Install Dependencies:
yarn
ornpm install
- Start the dev server:
yarn start
ornpm run start
- go to http://localhost:8080/ in your browser
The large bulk of the base logic for solving "the game of life" is container in src/redux/modules/game.js. It should be noted that this repo uses Immutable.js for keeping state immutable (which is the redux way of life). The logic for solving this puzzle was the standard "2d array" solution.
React/Redux are, honestly, a bit overkill for this puzzle. However as previously stated, I wanted to solve it using this stack (or rather import the logic into this stack) as a potential teaching tool for future use.
The display is using the <canvas>
element, and thus there isn't much need for react to re-render the grid. However react re-renders the statistics used in the display as well as passes down state to the grid to provide new coordinates for re-drawing the <canvas>
. Using <canvas>
for this game was great, as it prevents us from rendering a large amount of DOM elements.
I plan on adding onto this app in the future, and will mark issues in the Issues section of this repo.