ReactJS binary-studio.com
React JS
JS library focused on UI, not a framework
one-way data flow
VirtualDOM
UI = f(x)
ReactJS
F - Component
x - state
MVC
Problems
Facebook problems
2014
30th of April
F8 Facebook Developer Conference
Flux
Flux
Flux
Action
Dispatcher
Store
View
● Instead of MVC for React
● Unidirectional data flow
● Created by Facebook
● Many stores
Store
Store
...
Dispatcher
Central 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
...
Actions
triggered by the view
information about changes
Action
Dispatcher
Store
ViewStore
Store
...
Store
application state
reacts to specific actions
issue events when data or state updated
Action
Dispatcher
Store
ViewStore
Store
...
Views
Triggers actions
Reacts to specific events in the store
Action
Dispatcher
Store
ViewStore
Store
...
Race of Flux implementations
relay
flux
alt
reflux
flummox
fluxible
fluxxor
marty.js
Problems of Flux
Store contains store change logic and state
The state is being rewritten with every action
Dispatcher cannot dispatch while dispatching
2015
End of the race
Redux wins!
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
Redux
View layer
Action
Dispatcher Store View
Provider Connect
( previousState, action )
=> newState
Basic principle
Redux flow - Action
Whenever you want to change the
state of the application, you shoot
off an action.
Action function returns a formatted
action object
Redux flow - Reducer
Every reducer:
receive state
return new state
Not mutated old state! new one!
Redux flow - Store
Redux flow - Connect
Smart elements
How things works
no DOM markup, no styles
Provide data
call actions
Dumb elements
How things look
No app dependencies
Just props for data and callbacks
only UI state
Solved issues
1. 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
Redux Summary
One store
Reducers === (previousState, action) => newState
State changes only in reducers
Structured code
We have access to state in every moment
Server-side Environments
Node.js
ReactJS .NET
Nashorn
Tooling
React DevTools
Redux DevTools
devtools
Redux slider monitor
https://calesce.github.io/redux-slider-monitor/?debug_session=123
Webpack
Webpack
Like Grunt or Gulp, but different
Bundles
Uses javascript modules
Reduce the amount of AJAX requests
Totally configurable
Webpack
http://webpack.github.io/docs/configuration.html
Entry - entry files, which WP
will use
Webpack
http://webpack.github.io/docs/configuration.html
Output:
● path - location where
webpack will build the
files
● publicPath - location
where wwbpack serves
files from.
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
Webpack
http://webpack.github.io/docs/configuration.html
Plugins:
● Like tasks
● Work with bundle
Webpack
http://webpack.github.io/docs/configuration.html
Bundles:
● Lazy loading
● Resource per page
Webpack
Plugins
Loaders
Async build
Chunks
DevTools
Webpack-dev-server
When you need HTTP
Serves files virtually
Hot reload (works on socket.io)
Hot reload
Complementary-Tools
https://github.com/facebook/react/wiki/Complementary-Tools
Links
Redux video: egghead
Flux: Rus/Eng
Redux: Rus/Eng
Demo
https://bitbucket.org/oleksandrkovalov/bsa-2016-react-demo-2
Thank you!Let’s redux!

Academy PRO: React JS. Redux & Tooling