This is the tutorial from the book "React.js Essentials", by Artemij Fedosejev. Changes to the tutorial's source code are identified in this file. This code is designed to prevent the need for a connection during dev. Check todo lists before deploying. Several pieces of code need to be removed before it is production ready.
- gulp
- Automated build process
- browserify
- Bundles dependency files together so that node modules can be used by the application
- babelify
- Needed for JSX
- Ensure you have the
.babelrcfile created and configured (see below under Deviations, .babelrc section) - Ensure you install
babel-preset-es2015andbabel-preset-reactas listed below
- vinyl-source-stream
- Needed to use browserify and gulp together? Not really clear yet how it does that.
- react
- Contains base functionality for React
- react-dom
- Contains functionality for rendering to the DOM
- bootstrap-css-only
- Using this instead of the cdn minify in index.html from the book so that I can work offline
- babel-preset-es2015
- Preset required to use JSX with babel 6.0.0 (which newer babelify versions use). See deviation notes for gulpfile.js below for implementation.
- babel-preset-react
- Preset required to use JSX with babel 6.0.0 (which newer babelify versions use). See deviation notes for gulpfile.js below for implementation.
- snapkite-stream-client
- Connects to the live stream from the snapkite engine
- jest-cli
- Unit testing for React.
- Have to edit the
package.jsonfile as well. Change:
"scripts": { "test": "echo \"Error: no test specified\" && exit 1" },- to:
"scripts": { "test": "jest" }, - react-addons-test-utils
- Needed to help test, but requires additional packages (see below)
- babel-jest
- Ok, so this isn't a deviation, but it isn't mentioned until WAY later after you need it.
- Required to get jest working with react-addons-test-utils
- Ensure you have the
.babelrcfile created and configured (see below under Deviations, .babelrc section) - Ensure you have modified the
package.jsonfile by adding the Jest configuration block (see below under Deviations, package.json section)
- flux
- Application arcitecture for React that is based on unidirectional data flow
- object-assign
- Module that copies the properties from multiple source objects to a single target object.
app.js: This receives the new tweets and calls the receiveTweet function intweet_action_creators.jsfor each tweet.tweet_action_creators.js: Creates and dispatches a new action with every new tweet.app_dispatcher.js: Dispatches all actions to all stores.tweet_store.js: Registers withapp_dispatcherand emits the change event on every new action received from that dispatcher.stream.jsx: Listens to changes intweet_store.js, gets a new tweet fromtweet_store.js, updates the state with a new tweet, and re-renders.
- TBP
- Did not use terminating semicolons
- File name conventions
- Did not use
Component.react.jsnaming for react component files. Instead, usedcomponent.jsx - Did not capitalize any file names, but did capitalize component names. Similar to Elixir convention.
- Used
snake_casefor filename spaces
- Did not use
- Used local references to bootstrap-css-only instead of cdn calls
- Added some formatting changes to improve readability
- After installing
babel-jest, add this Jest configuration block:
"jest": {
"scriptPreprocessor": "<rootDir>/node_modules/babel-jest",
"testFileExtensions": [
"jsx",
"js"
],
"unmockedModulePathPatterns": [
"<rootDir>/node_modules/react",
"<rootDir>/node_modules/react-dom",
"<rootDir>/node_modules/react-addons-test-utils",
"<rootDir>/node_modules/fbjs"
]
}
- In order to use the babel presets for JSX, you must create a file in the root directory named
.babelrc. Within the file, add this code:
{
"presets": ["es2015", "react"]
}
- This is required for both
gulpandbabel-jest
- babel-preset-es2015
- babel-preset-react
- bootstrap-css-only
- Added notes throughout for future reference. Most are not verbatim from the book.
- Why no "else"? I hate hanging returns after if clauses
- Check TODOs