HISTORY
BootcampMisc2021-02-16
Update History
This is the walking steps of Dan Abramovâs Redux vedio tutorials.
Part 2: Building React Applications with Idiomatic Redux (27 free videos)
https://egghead.io/courses/building-react-applications-with-idiomatic-redux
There are total 10 branches (step-1âŠstep-9, main) to go through the video episodes.
Branches
1. step-1
grab the source code from: https://github.com/reactjs/redux/tree/master/examples/todos
config package.json, add webpack.config.js, do some updating, use webpack-dev-server to make the source working properly.
2. step-2
initial state in HTML 5 Local-storage.
store.subscribe(() => {
saveState({'todos': store.getState()})
})add node-uuid.v4, lodash/Throttle for subscribe(saveState)
3. step-3
- seperate js to Root, configureStore
- use react-router
Linkfor hashHistory URL. - add removeState to reset localStorageâs state to prove it work.
4. step-4
- debug: devtool: âinline-source-mapâ,
- FilterLink not work correct. (step-3 either)
6. step-6
- favicon
- mongod && mongoose
- routes: /api/todos, models
- server: âwebpack-dev-middlewareâ, âwebpack-hot-middlewareâ
try to integrate williamDemo (Redux Universal) and react-redux-universal-hot-example into.
mongod &
npm run start1
open http://localhost:8081
open http://localhost:/8081/api/routes/re-cast getVisibleTodos to reducers as a selector, so mapStateToProps use state instead of state.todos.
work at course-15.
7. step-7
users tab works. It uses mongo + redux global state + react component.
- redux-thunk
- componentDidMount to call store.dispatch(âFETCH_USERâ)
- in userAction.js, superagent.get(â/api/usersâ) to get the user-list
- in userReducer.js, state is updated with the user-list
- in userApp.js,
mapStateToPropsupdate state.userList - in userApp.js, render is trigger coz state.userList is changed.
http://localhost:8081/users
- userList clicks and userDetail work.
- karma-test works.
- re-config the structure, bring (mv) stuff from previous
williamDemorepository. I prefer to make this repository as a template forreact-redux-fullstack, so step by step to integrate some good stuff. - Redux-form
- adjust the structure: replace db (todo -> redux), add new schemas. mv all todos name-convenention to redux-âŠ
- make counter <-> mongo <-> state works. localhost:8081/counter localhost:8081/users work.
- counter CRUD works. superagent + findOneAndUpdate localhost:8081/counter works as a full-stack behavior. mongodb keeps sync with counter-clicking.
8. step-8
checkout -b from step-6, at course-16.
- install redux-thunk, in configureStore.js use it. The inner function receives the store methods dispatch and getState as parameters.
- merge step-8 and step-7. currently the tabs: (1) counter, users, contact works. (2) app, todos not work. (3) about, phone not implement yet.
9. step-9
- https://jsonplaceholder.typicode.com/ Fake Online REST API for Testing and Prototyping
- request
- Cross Domain issues: Error: Request has been terminated Possible causes: the network is offline, Origin is not allowed by Access-Control-Allow-Origin, the page is being unloaded, etc.
- to make promise testable: add
chai-as-promised, and in karma.conf.js: files: [ ânode_modules/babel-polyfill/dist/polyfill.jsâ, ⊠] - use
react-route-dominstead ofreact-route - use react v15.4.0 instead of v15.5.3 to avoid warning
- change form
onSubmit={this.props.handleSubmit}toonSubmit={(e)=>this.props.handleSubmit(e)}to fix fetching github repository no-return issue. - use â/api/delegate/âŠâ in server-side (
request.js) to delegate accessing security website work.
10. Main
- component must be first-letter capitalize:
editModalnot work,EditModalwork. - usersList: CRUD works (redux-form + react-bootstrap-modal)
-
redux-form: â use
initialValuesto fill up the edit-form. âFieldshould haveonChange, otherwise the input canât edit, even nothing to do:onChange={}â rewrite add/edit userReucer, use map, concat. â pass user.id as hidden: <input name=âidâ type=âhiddenâ />
- the tabs
todoApp,users,counterall interact with MongoDB data. rxjs@5.3.0,redux-observablewill be used in input-searchisomorphic-fetchto use fetch alongside with superagent, for caching and performance reason.
connect = Object.assign({}, ownProps, stateProps, dispatchProps);- in
Userstab, addsearch userinput box, to search user âfistNameâ or âlastNameâ - add
redux-observableforsearchcriteria so this works: react + redux + rxjs (redux-observable) - add
debounceTimefor fetchUserEpic - add more search logic: put onChange event in search component instead of its parent; update onChange when search-criteria is empty
-
update server/routes/users.js for
/api/users/search?search_criteria:'$or': [ {firstName: regexp}, {lastName: regexp} ] - move
import orderBy from 'lodash/orderBy'to reducer file which it is called. - add optional parameter for URL
react-router-dom-v4: - add sub-menu (sub-navigator) in
Topics - add options to input counter from URL-params, like: http://localhost:8081/counter/18
- add .scss, .gif
style-loader - add loginApp logic
- add
Redirect - add actionCreator and reducers for
loginandlogout - add server-side routes
authfor login fetch. - user
tokenproperty for future extension. - add
react-bootstrap,react-router-bootstrapfor responsive menu. -
add toggle login/logout works: add
state.tokenin Root.js, just like in LoginApp.js, so these 2 parts are sync when login/logout. react-redux-universal-hot-example:export function logout() { return { types: [LOGOUT, LOGOUT_SUCCESS, LOGOUT_FAIL], promise: (client) => client.get('/logout') }; }
Unit Test
- use karma + mocha + chai + sinon + webpack to make test (folder) works, need a lot of npm-modules.
- in package.json
scripts: âimmutableâ: âmocha âcompilers js:babel-core/register ârequire ./test/helper.js ârecursiveâ does the same thing as karma.conf.js
ncu
ncu -u
npm update
karma start karma.conf.jschai-as-promisedto test promise: eitherreturn promiseordone()will work: test/promise.spec.js.immutableand `chai-immutable installed and test.react-bootstrapthrow warning (propTypes) with React ^15.4, ^15.5.
Issues:
- react-router version: V4 not work. Video use V2.4, I use ^3.0, then
npm update - use react-router-dom instead. remove react-router, and react-router-bootstrap.
- Warning: Accessing PropTypes via the main React package is deprecated. Use the prop-types package from npm instead.
after
npm i -S prop-types, the warning is disappear. so fix. - RESTFul API call Error: Request has been terminated Possible causes: the network is offline, Origin is not allowed by Access-Control-Allow-Origin, the page is being unloaded, etc.
o: /api/users x: /api/delegate/github/williamjxj x: http://localhost:8081/api/delegate/jsonplaceholder
- ERROR in ./~/css-loader!./~/sass-loader/lib/loader.js!./src/style.scss: Module build failed: Error: Cannot find module ânode-sassâ
npm i -D node-sass (npm rebuild node-sass)
It works. Whatâs the relationship btw
sassandscss?
Reference
- react-router version: V4 not work. Video use V2.4, I use ^3.0, then
npm updatereact-router ^3.0.0 â ^4.0.0
Use react-router-dom instead:
https://reacttraining.com/react-router
- use
Link, NavLinkfromreact-router-dom. - https://github.com/WilliamJiang/node-xml-xslt
- docs/flow.md
- react-boilerplate:
$ npm install -g create-react-app
$ create-react-app demo-app
$ cd demo-appThings to TODO
- http-proxy
- socket
- node-debug, node-inspector
- normalizr (reference/steps/schema.js)
