Top Banner
React.js @emadb This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
50

React.js in real world apps.

Apr 16, 2017

Download

Software

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: React.js in real world apps.

React.js@emadb

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.

Page 2: React.js in real world apps.
Page 3: React.js in real world apps.

History of web development…

Page 4: React.js in real world apps.
Page 5: React.js in real world apps.

MV(something) in the browser

Page 6: React.js in real world apps.
Page 7: React.js in real world apps.
Page 8: React.js in real world apps.

Enterprise Javascript

Page 9: React.js in real world apps.
Page 10: React.js in real world apps.
Page 11: React.js in real world apps.

Quiz time!

Page 12: React.js in real world apps.

What’s the difference between Service, Factory, Provider?

Page 13: React.js in real world apps.
Page 14: React.js in real world apps.

UNLEARN EVERYTHING @michelebertoli

Page 15: React.js in real world apps.

var HelloWorld = React.createClass({ render: function() { return ( <h1> Hello world </h1> ); } });

React.render(<HelloWorld />, document.body);

Page 16: React.js in real world apps.
Page 17: React.js in real world apps.

Whooot?

• Markup and behaviour

• Separation of concerns

• Template language?

• Components

• JSX syntax

Page 18: React.js in real world apps.

var HelloWorld = React.createClass({ displayName: "HelloWorld", render: function() { return React.createElement("h1", null, "Hello World"); } });

React.render( React.createElement(HelloWorld, null), document.body);

Page 19: React.js in real world apps.

COMPONENTS

Page 20: React.js in real world apps.
Page 21: React.js in real world apps.
Page 22: React.js in real world apps.
Page 23: React.js in real world apps.

render

Every time the state change the component render itself

Page 24: React.js in real world apps.

DOM is slow

Javascript that access to the DOM is slow

console.dir(document.createElement('div'));

A DIV contains about 135 first level properties/function (700 on second level).

Page 25: React.js in real world apps.

Virtual DOM

• Our code act on a fake DOM (virtual dom)

• React.js take care of keep virtual DOM and real DOM synchronised

• Every ReactElement is a light, stateless, immutable, virtual representation of a DOM Element

• A virtual DOM div element contains only 6 properties.

Page 26: React.js in real world apps.
Page 27: React.js in real world apps.

Why I like react so much

• Easy to learn, easy to use

• True reusable components (1 single file per component)

• Functional approach

• Human error messages

• Active community

Page 28: React.js in real world apps.

I said “Easy to learn!”

Less than 1 hour to learn everything you need to be productive.

Challenge

Page 29: React.js in real world apps.

How I use it

Page 30: React.js in real world apps.

Server side

• Node.js Express api

• MongoDb/Mongoose

• Passport

• Mocha/Chai

Page 31: React.js in real world apps.
Page 32: React.js in real world apps.

Client side

Npm

Webpack

Hot-reload

Babel.js

Eslint

LibSass

Page 33: React.js in real world apps.

npm

var React = require(‘react’)

$ npm install react —save

import React from ‘react’

Page 34: React.js in real world apps.

Everything you need is in your package.json

Page 35: React.js in real world apps.

• A transpiler

• Converts ES6 javascript to “old” ES5.

• Compiles JSX files to plain js.

Page 36: React.js in real world apps.
Page 37: React.js in real world apps.

Webpack

Bundles javascript, css, sass, fonts and images with their dependencies into assets

Page 38: React.js in real world apps.
Page 39: React.js in real world apps.
Page 40: React.js in real world apps.

Superagent

Super Agent is light-weight progressive ajax API crafted for flexibility, readability, and a low learning curve after

being frustrated with many of the existing request APIs. It also works with Node.js!

Page 41: React.js in real world apps.
Page 42: React.js in real world apps.
Page 43: React.js in real world apps.

Flux

Page 44: React.js in real world apps.

Flux:Actions

ActionCreatorReact View

Dispatcher

Action API

Page 45: React.js in real world apps.

Flux: Dispatcher

Store

Action

Dispatcher

Store Store

Page 46: React.js in real world apps.

Flux: Store

Store

React View

Dispatcher

Change event

Request new state

Page 47: React.js in real world apps.
Page 48: React.js in real world apps.

Few more things…

• Server side rendering

• Redux

• Relay

Page 49: React.js in real world apps.
Page 50: React.js in real world apps.

Thank you!

Emanuele DelBono @emadb

https://github.com/emadb/spot-react