+ All Categories
Home > Technology > Sexy React Stack

Sexy React Stack

Date post: 23-Jan-2018
Category:
Upload: kms-technology
View: 268 times
Download: 2 times
Share this document with a friend
32
HIGH TECH HIGH CODE QUALITY HIGH PERFORMANCE HIGH SCALABILITY HIGH MAINTAINABILITY Single Page App
Transcript
Page 1: Sexy React Stack

HIGH TECHHIGH CODE QUALITYHIGH PERFORMANCEHIGH SCALABILITYHIGH MAINTAINABILITY

Single Page

App

Page 2: Sexy React Stack

S E X Y R E A C T S T A C KC U R I O U S C A S E S

b y @ c u o n g t r u o n g

Page 3: Sexy React Stack

SSE at #KMS Technology

Hello!I am Cuong Truong

I am here because I love to share knowledge

You can contact me at [email protected]

Page 4: Sexy React Stack
Page 5: Sexy React Stack

React Redux ES6+ Flow

Linter

UI kit Unit Test Webpack VS Code Take away + Demo

Agenda

Page 6: Sexy React Stack

#library for building UI Uni-directional data flow Server-side rendering

**VIRTUAL DOM** #Cheat Sheet

REACT.JS

Page 7: Sexy React Stack

Do events

Repaint the DOMDo layout

Recalculate the CSS

Every time DOM changes, browser needs to

REAL DOMTAKES TIME

Page 8: Sexy React Stack

Modifies DOM when something changed

VIRTUAL DOM

1CREATEa lightweight description of component UI

BATCHexecute all changes

COMPUTEminimal set of changes

to apply to the DOM

DIFFwith the old version

2

34

BETTER PERFORMANCE

Page 9: Sexy React Stack

PROPS STATE

{/* data */}

Changes trigger a render()

state

Stateful

Stateless

Page 10: Sexy React Stack

#Thinking in React

No controllers No models No directives No global event listeners

Everything is <Component/>

Page 11: Sexy React Stack

THINKING IN REACT

- App - HomePage - Header - SearchBar - EmployeeList - EmployeeListItem

- EmployeePage - Header - EmployeeDetails

Page 12: Sexy React Stack

A solution for concurrent data modification by multiple actors

A client container for temporary UI state. e.g. wizard, shopping cart, …

A client cache for avoiding excessive HTTP requests

If you need

HOW TO MANAGE FRONTEND LOGIC

or

APPLICATION STATE EFFECTIVELY?

Page 13: Sexy React Stack

#Redux application state manager for javascript applications

UNIDIRECTIONAL DATA FLOW IMMUTABLE

Page 14: Sexy React Stack

MIDDLEWARESAsync API, Logging, Dev Tools, …

ReduxThunk, ReduxApiMiddleware, ReduxObservable, ReduxSaga, …

Page 15: Sexy React Stack

Let + Const const myObject = {propA, propB}

Arrow function, Default const myFunction = (arg = ‘value’) => {}

Class export class MyClass {constructor(){}}

Module import {MyClass} from ‘my/path’

Template String const tps = `Template string with ${…}`

#ES6 #Mozilla #ES-Next

ECMAScript 6+Destructuring const {propA, propB} = myObject

Rest, Spread …Promise myPromise.then().then().catch()

Async/Await const myFunction = async () => {await…}

Decorator @myDecoratorclass MyClass {…}

Page 16: Sexy React Stack

Static type checker for Javascript strong/statically typed advantages

Strong tool for LARGE app covers 100% of code catches incorrect assumptions

e.g. numbers represented as strings

Provides advanced autocompletion / intellisense navigation safe refactoring

FLOW

#WhyFlow

Page 17: Sexy React Stack

My Recommendation

project does not live for long

people enter or leave your team frequently

project is really simple

there is a chance you will need to refactor the thing

system is very important or even crucial for the success of company

Page 18: Sexy React Stack

discovers problems with js/jsx code

without executing itCoding conventions

Readability Maintainability

Functionality errors

ESLint

#eslint-plugin-flowtype#ESLint

Page 19: Sexy React Stack

KARMASpectacular #test runner

for JavaScript

CHAIBBD/TDD

#assertion library

MOCHAFeature-rich JavaScript

#test framework

ENZYMEJavaScript #testing utility for React

SINONTest #spies, stubs & mocks for JavaScript

ISTABULJS #code coverage tool

Front-end Unit Test

Page 20: Sexy React Stack

React Bootstrap Material UI

Build yourself ?!

#BEM #SMACSS #MVCSS

Page 21: Sexy React Stack

Bundles your Scripts Styles Assets Images

WEBPACKConfiguration object Resolves dependencies Hot reloading Tree-shaking Cache busting/hashing system

Page 22: Sexy React Stack

WEBPACK

ENTRY POINTS

single entry

multiple page app

separate app & vendor

MORE INFORMATION

WEBPACK

LOADERS

style | css | sass | scss | …

babel | typescript | flow | …

html | template | pug | …

url | file | raw | …

module | bundle-loader

MORE INFORMATION

WEBPACK

PLUGINS

minimize

deduplication

HtmlWebpackPlugin

CircularDependencyPlugin

CommonsChunk

MORE INFORMATION

Page 23: Sexy React Stack

// bar.jsexport default const bar () => { /* Your code here */}

<!--index.html--><html> <head>

<!--Your head—></head>

<body> <!--Your body--> <script src="bundle.js"></script> </body></html>// webpack.config.js

module.exports = { entry: './app.js', output: { filename: 'bundle.js' }}

// app.jsimport bar from './bar';bar();

Page 24: Sexy React Stack

folder structure?

Page 25: Sexy React Stack

FOLDER STRUCTURE

Page 26: Sexy React Stack

take away

Page 27: Sexy React Stack

ProsFull control/easy to manage coding flow Building reusable code/components Testable Readable Maintainable Performance Developer experience/community Redux ecosystem

Extension points such as #middleware Server-side rendering => SEO React + Redux is small

Page 28: Sexy React Stack

ConsLearning curve Need to keep conventions/boilerplate Need to care about performance Not easy to create large app without using bunch of libraries

React does not provide An events system (other than vanilla DOM events) AJAX Promise

Page 29: Sexy React Stack

My Recommendation

People are a part of solution Keep conventions / commitments Strategies for managing dependencies Take care about architecture and configurations Write small & pure functions as much as possible Write meaningful unit test as much as possible Don’t USE if you don’t NEED or UNDERSTAND it

Page 31: Sexy React Stack

Q&A

Page 32: Sexy React Stack

@CuongTruong

facebook/cuongtruong.official

[email protected]

THANK YOU@CuongTruong


Recommended