productive development with react js

46
Productive development with ReactJs How to boost developer’s productivity? Tim Zadorozhniy betterstack. org

Upload: tim-dev-tim-zadorozhniy

Post on 15-Apr-2017

1.424 views

Category:

Software


2 download

TRANSCRIPT

Page 1: Productive development with react js

Productive development with ReactJs

How to boost developer’s productivity?

Tim Zadorozhniy betterstack.org

Page 2: Productive development with react js
Page 3: Productive development with react js

Developers Productivity

Page 4: Productive development with react js

Soft skills:- planning- good communication

- right goals- motivation- discipline

Page 5: Productive development with react js

Technical part:- automation- language/framework- code quality- best practices- code review- Tests/TDD- ???

Page 6: Productive development with react js

Tech part

Page 7: Productive development with react js

Automate as much as you can

If you don’t automate, you do more work than needed

But, What could be automated?

Page 8: Productive development with react js

Builds, tests, code analyze/linting, code/styles hot swap, reporting, assets

compilation, deployments, etc ...

Page 9: Productive development with react js

To automate stuff we need some tools, libs and

methodologies

Page 10: Productive development with react js

Code

Page 11: Productive development with react js

Write code in text editor

Reload browser

Bring app to certain state

Iterate

Page 12: Productive development with react js

Write code in text editor

Reload browser

Bring app to certain state

Iterate

Page 13: Productive development with react js

Webpack- Simple configuration

- CommonJS, AMD modules out or the box

- Loaders for anything (ES6, (S)CSS, Fonts)

- Robust bundle management

- Webpack dev server

- Hot reload with webpack dev server

- 9000+ plugins

Page 14: Productive development with react js

Babel

- Transforms ES6(7) code to ES5

- Robust

- Highly configurable

- Works well with webpack

- https://babeljs.io/

Page 15: Productive development with react js

Webpack simple config

{ context: __dirname + "/app", entry: "./index", output: { path: __dirname + "/dist", filename: "bundle.js" }}

Starting point if the app

Output bundle

Page 16: Productive development with react js

Webpack HMR

module: { loaders: [ { test: /\.jsx?$/, loaders: ['react-hot', 'jsx?harmony'], include: path.join(__dirname, 'src') } ]},

plugins: [ new webpack.HotModuleReplacementPlugin()]

Enable Hot reloader here

Jsx transpiler hereWebpack module reloader here

Page 17: Productive development with react js

React Hot Loader

Code changes Hot ReloaderProxy

Component A code

Component A new code

Page 18: Productive development with react js

React Hot Loader + Webpack HMR

Code changes Hot ReloaderProxy

Component A code

Component A new code

Shipped by Webpack Hot Module replacement

Page 19: Productive development with react js

Redux

- Read-only state

- Mutations as a pure functions

- Declarative data flow

Page 20: Productive development with react js

React + Webpack (+ Redux)

“Time travel” with Redux https://github.com/gaearon/redux-devtools

https://github.com/gaearon/redux

Page 21: Productive development with react js

React + Webpack (+ Redux)

Page 22: Productive development with react js
Page 23: Productive development with react js

React Red BoxShows console error in red box

(can save your time evaluating errors)

Page 24: Productive development with react js

Write code in text editor

Look at screen/Evaluate results

Iterate

Page 25: Productive development with react js

Test

Page 26: Productive development with react js

Why?

- Confidence for changes

- Room for continuous delivery

- Tests === better documentation

Page 27: Productive development with react js

What to test?

- React components (Shallow Rendered dom)

- Stores (Reducers)

- Actions (check if action mutate as you expected)

- Custom logic (....)

Page 28: Productive development with react js

How ?- TDD

- Decouple code into modules

- Karma + Jasmine,

- Karma + Mocha, Sinon, chai

- Write test just for that module

- Iterate on it

Jest ?

Page 29: Productive development with react js
Page 30: Productive development with react js

Sometimes code we commit is not good.

So we need to check it before.

Page 31: Productive development with react js

Lint and hook

Page 32: Productive development with react js

ESLint + Husky

ESLint: code linter/style checker + Tests

+Husky: Git Hooks with NPM interface

=

Better code

Page 33: Productive development with react js

EsLint

- Catch syntax, style issues- Pluggable, configurable rules- ES6/React friendly- Supports configurable envs- Robust http://eslint.org/docs/rules/

Page 34: Productive development with react js

1. Helps to detect common “bad” things in code and points to them

2. Enforces real metric for Js code quality

Page 35: Productive development with react js

Things to catch

eval(), global variables, not used brackets, trailing commas, dead code, not used React

properties, …

Page 36: Productive development with react js

{ "ecmaFeatures": { // enable or disable some features of ES6 "blockBindings": true, "forOf": true, "jsx": true }, "rules": { // ESLint rules settings "semi": 2, // use semicolons "no-empty": 2, // disallows empty statements }, "plugins": { // ESLint rules settings "react" // adds React plugin }}

Configuration for EsLint:

Page 37: Productive development with react js

EsLint

Sample configurations:- https://github.com/airbnb/javascript

- https://github.com/feross/eslint-config-standard

Page 38: Productive development with react js

Git Hooks

Each push/commit triggers a command

Page 39: Productive development with react js

Husky- npm interface to githooks

- looks at precommit, prepush, npm scripts

npm install husky --save-dev

Page 40: Productive development with react js

Improved linting workflow

Add code git push npm test && npm run lint Actually push

FAIL!

Ran by Git Hooks && Husky

Page 41: Productive development with react js

So you push/commit less bad code!

Page 42: Productive development with react js

What else?

Page 43: Productive development with react js

- Emmet idea plugin- Use CSS preprocessors SCSS/PostCSS- Master your IDE- Hotkeys!!!- Develop Soft Skills

Page 44: Productive development with react js

Demo time!https://github.com/erikras/react-redux-universal-hot-example/

Page 45: Productive development with react js

Thanks!

Page 46: Productive development with react js

Q&A?