47
ReactJS binary-studio.c

Academy PRO: React JS. Redux & Tooling

Embed Size (px)

Citation preview

Page 1: Academy PRO: React JS. Redux & Tooling

ReactJS binary-studio.com

Page 2: Academy PRO: React JS. Redux & Tooling

React JSJS library focused on UI, not a framework

one-way data flow

VirtualDOM

Page 3: Academy PRO: React JS. Redux & Tooling

UI = f(x)ReactJS

F - Component

x - state

Page 4: Academy PRO: React JS. Redux & Tooling

MVC

Page 5: Academy PRO: React JS. Redux & Tooling

Problems

Page 6: Academy PRO: React JS. Redux & Tooling

Facebook problems

Page 7: Academy PRO: React JS. Redux & Tooling

201430th of April

F8 Facebook Developer Conference

Page 8: Academy PRO: React JS. Redux & Tooling

Flux

Page 9: Academy PRO: React JS. Redux & Tooling

Flux

Page 10: Academy PRO: React JS. Redux & Tooling

Flux

Action

Dispatcher

Store

View

● Instead of MVC for React● Unidirectional data flow● Created by Facebook● Many stores

Store

Store

...

Page 11: Academy PRO: React JS. Redux & Tooling

DispatcherCentral hub that messages all data flow

It is a registry of callbacks into the store

=> mechanism to deliver actions into the stores Action

Dispatcher

Store

ViewStore

Store

...

Page 12: Academy PRO: React JS. Redux & Tooling

Actionstriggered by the view

information about changes

Action

Dispatcher

Store

ViewStore

Store

...

Page 13: Academy PRO: React JS. Redux & Tooling

Storeapplication state

reacts to specific actions

issue events when data or state updated Action

Dispatcher

Store

ViewStore

Store

...

Page 14: Academy PRO: React JS. Redux & Tooling

ViewsTriggers actions

Reacts to specific events in the store

Action

Dispatcher

Store

ViewStore

Store

...

Page 15: Academy PRO: React JS. Redux & Tooling

Race of Flux implementationsrelay

flux

alt

reflux

flummox

fluxible

fluxxor

marty.js

fynx

McFly

……..

Page 16: Academy PRO: React JS. Redux & Tooling

Problems of FluxStore contains store change logic and state

The state is being rewritten with every action

Dispatcher cannot dispatch while dispatching

Page 17: Academy PRO: React JS. Redux & Tooling

2015End of the race

Redux wins!

Page 18: Academy PRO: React JS. Redux & Tooling

Why Redux?1. One global state

2. New state after each action (Time traveling)

3. State is read-only

4. Changes are made with pure functions (reducers)

5. Hot reload

Page 19: Academy PRO: React JS. Redux & Tooling

Redux

View layer

Action

Dispatcher Store View

Provider Connect

Page 20: Academy PRO: React JS. Redux & Tooling

( previousState, action ) => newState Basic principle

Page 21: Academy PRO: React JS. Redux & Tooling

Redux flow - ActionWhenever you want to change the state of the application, you shoot off an action.

Action function returns a formatted action object

Page 22: Academy PRO: React JS. Redux & Tooling

Redux flow - ReducerEvery reducer:

receive state

return new state

Not mutated old state! new one!

Page 23: Academy PRO: React JS. Redux & Tooling

Redux flow - Store

Page 24: Academy PRO: React JS. Redux & Tooling

Redux flow - Connect

Page 25: Academy PRO: React JS. Redux & Tooling

Smart elementsHow things works

no DOM markup, no styles

Provide data

call actions

Page 26: Academy PRO: React JS. Redux & Tooling

Dumb elementsHow things look

No app dependencies

Just props for data and callbacks

only UI state

Page 27: Academy PRO: React JS. Redux & Tooling

Solved issues1. Delegation is easier

a. top-down props is not required

2. Separation of concerns

a. Data fetching => actions

b. Data decorations => reducer

c. view logic

3. State management

a. App-specific

b. Immutable

c. Maintainable

Page 28: Academy PRO: React JS. Redux & Tooling

Redux SummaryOne store

Reducers === (previousState, action) => newState

State changes only in reducers

Structured code

We have access to state in every moment

Page 29: Academy PRO: React JS. Redux & Tooling

Server-side EnvironmentsNode.js

ReactJS .NET

Nashorn

Page 30: Academy PRO: React JS. Redux & Tooling

Tooling

Page 31: Academy PRO: React JS. Redux & Tooling

React DevTools

Page 32: Academy PRO: React JS. Redux & Tooling

Redux DevToolsdevtools

Page 33: Academy PRO: React JS. Redux & Tooling

Redux slider monitor

https://calesce.github.io/redux-slider-monitor/?debug_session=123

Page 34: Academy PRO: React JS. Redux & Tooling

Webpack

Page 35: Academy PRO: React JS. Redux & Tooling

WebpackLike Grunt or Gulp, but different

Bundles

Uses javascript modules

Reduce the amount of AJAX requests

Totally configurable

Page 36: Academy PRO: React JS. Redux & Tooling

Webpack

http://webpack.github.io/docs/configuration.html

Entry - entry files, which WP will use

Page 37: Academy PRO: React JS. Redux & Tooling

Webpack

http://webpack.github.io/docs/configuration.html

Output:● path - location where

webpack will build the files

● publicPath - location where wwbpack serves files from.

Page 38: Academy PRO: React JS. Redux & Tooling

Webpack

http://webpack.github.io/docs/configuration.html

Loaders:● Like tasks ● Transform files● Preprocess files as you

require or import them.

Preloaders - the same but before executing loaders and building bundles

Page 39: Academy PRO: React JS. Redux & Tooling

Webpack

http://webpack.github.io/docs/configuration.html

Plugins:● Like tasks ● Work with bundle

Page 40: Academy PRO: React JS. Redux & Tooling

Webpack

http://webpack.github.io/docs/configuration.html

Bundles:● Lazy loading● Resource per page

Page 41: Academy PRO: React JS. Redux & Tooling

WebpackPlugins

Loaders

Async build

Chunks

DevTools

Page 42: Academy PRO: React JS. Redux & Tooling

Webpack-dev-serverWhen you need HTTP

Serves files virtually

Hot reload (works on socket.io)

Page 43: Academy PRO: React JS. Redux & Tooling

Hot reload

Page 44: Academy PRO: React JS. Redux & Tooling

Complementary-Toolshttps://github.com/facebook/react/wiki/Complementary-Tools

Page 46: Academy PRO: React JS. Redux & Tooling

Demohttps://bitbucket.org/oleksandrkovalov/bsa-2016-react-demo-2

Page 47: Academy PRO: React JS. Redux & Tooling

Thank you! Let’s redux!