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 clone
this project;- open any step of a certain workshop part;
- run
npm install
oryarn
inside your terminal client; - run
npm start
oryarn 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.js
to<App/>
component. Replace game title with game logo (./resources/logo.png
) - Step 2: Create initial state with
question
andtext
, 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 useguesses
Array
inside state. - Step 5: Display 6
lives
and decrement them after unsuccessful guess. Extract code to<Hangman/>
component. In addition implement hangman images (./resources/**/*.png
).
- Step 1: Install
redux
andreact-redux
. Create store, simple reducer and initial state insidestore.js
. Wrap<App/>
inside redux<Provider/>
. - Step 2: Connect
<App/>
to Redux usingconnect()
function. Mapquestion
andtext
from state to props and use them instead state. Cleanup redundant code. - Step 3: Map
lives
from state to props. CreateDECREMENT_LIVES
action insideactions/index.js
and handle it inside reducer. Finishlives
with Redux implementation. - Step 4: Do the same for
guesses
property, just useGUESS_LETTER
action. - Step 5: Install
axios
andredux-thunk
. Addthunk
middleware to the store. Then useaxios
to fetch data from/data.json
insidefetchData
action. Pick randomquestion
andtext
from data inside reducer.
- Step 1: Install
enzyme
andreact-test-renderer
. InsideHiddenText.spec.js
write 2 tests usingshallow()
: initialtext
is hidden and another with some revealed letters. - Step 2: Install
axios-mock-adapter
and mock data fetch. Then Usingmount()
insideApp.spec.js
write 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