React is a JavaScript library for creating user interfaces developed by Facebook. It uses concept so-called Virtual DOM where all the components actually live. This Virtual DOM approach gives lots of flexibility and boosts the performance because React does smart calculations to minimize the amount of costly operations in the actual DOM.
This hands-on workshop will help you to deeply understand and learn core concepts of React, how to structure your application with Redux and test it in a proper way.
http://slides.com/tomasmiliauskas/modern-web-development-with-react-and-redux
Hardware:
- A personal computer with internet connection.
Software:
- A terminal client.
- Favorite code editor or IDE like Visual Studio Code, Sublime Text, TextMate, WebStorm, etc.
- Node (LTS) + NPM (https://nodejs.org/en/download/) installed.
- Yarn (https://yarnpkg.com/en/docs/install) installed to speed up
npm install. - Chrome browser ( https://www.google.com/chrome/browser/desktop/index.html ).
git clonethis project;- open any step of a certain workshop part;
- run
npm installoryarninside your terminal client; - run
npm startoryarn start; - open http://localhost:3000/ inside your Chrome browser (might happen automatically);
- browser will reload automatically after changes in source code;
Follow the instructions to complete the Hangman game.
IMPORTANT NOTE: The actual implementation of each and every step is stored in this repository.
- Step 1: Clone the project, install modules, render game title (Hangman Game) and some text.
- Step 1: Move existing code from
index.jsto<App/>component. Replace game title with game logo (./resources/logo.png) - Step 2: Create initial state with
questionandtext, render it and then extract it to<HiddenText/>component. Text should be hidden. - Step 3: Render alphabet letters as buttons inside
<Alphabet/>(use alphabet from./resources/alphabet.js) component and fire an event if any is clicked. - Step 4: Connect
<HiddenText/>and<Alphabet/>components. Letters should be revealed after successful guess. Create and useguessesArrayinside state. - Step 5: Display 6
livesand decrement them after unsuccessful guess. Extract code to<Hangman/>component. In addition implement hangman images (./resources/**/*.png).
- Step 1: Install
reduxandreact-redux. Create store, simple reducer and initial state insidestore.js. Wrap<App/>inside redux<Provider/>. - Step 2: Connect
<App/>to Redux usingconnect()function. Mapquestionandtextfrom state to props and use them instead state. Cleanup redundant code. - Step 3: Map
livesfrom state to props. CreateDECREMENT_LIVESaction insideactions/index.jsand handle it inside reducer. Finishliveswith Redux implementation. - Step 4: Do the same for
guessesproperty, just useGUESS_LETTERaction. - Step 5: Install
axiosandredux-thunk. Addthunkmiddleware to the store. Then useaxiosto fetch data from/data.jsoninsidefetchDataaction. Pick randomquestionandtextfrom data inside reducer.
- Step 1: Install
enzymeandreact-test-renderer. InsideHiddenText.spec.jswrite 2 tests usingshallow(): initialtextis hidden and another with some revealed letters. - Step 2: Install
axios-mock-adapterand mock data fetch. Then Usingmount()insideApp.spec.jswrite 3 tests: log src was defined, 26 letters rendered and 6 lives visible. - Step 3: Write 2 integration tests: successful letter guess and unsuccessful letter guess. After creating a wrapper use
setImmediate()for the rest of the code so the data is accessible.
MIT