SlideShare a Scribd company logo
1 of 54
Download to read offline
Using Context, Higher-Order Components
and Observables with React
Slide 1Sources:ReactJS [https://github.com/facebook/react/ ]
Licensed under the Creative Commons Attribution 4.0 International Public License
Sofia
May 15, 2017
Context, HOCs & Observables with React
Trayan Iliev
IPT โ€“ Intellectual Products & Technologies
e-mail: tiliev@iproduct.org
web: http://www.iproduct.org
Using Context, Higher-Order Components
and Observables with React
Sofia
May 15, 2017
Slide 2Sources:ReactJS [https://github.com/facebook/react/ ]
Licensed under the Creative Commons Attribution 4.0 International Public License
About Us: IPT - Intellectual Products & Technologies
Since 2003 we provide trainings and share knowledge
in JS/ TypeScript/ Node/ Express/ Socket.IO/ NoSQL/
Angular/ React / Java SE/ EE/ Web/ REST SOA:
Node.js + Express/ hapi + React.js + Redux + GraphQL
Angular + TypeScript + Redux (ngrx)
Java EE6/7, Spring, JSF, Portals/Portlets: Liferay, GateIn
Reactive IoT with Reactor / RxJava / RxJS
SOA & Distributed Hypermedia APIs (REST)
Domain Driven Design & Reactive Microservices
Using Context, Higher-Order Components
and Observables with React
Sofia
May 15, 2017
Slide 3Sources:ReactJS [https://github.com/facebook/react/ ]
Licensed under the Creative Commons Attribution 4.0 International Public License
Where is The Code?
React.js demo code is available @GitHub:
https://github.com/iproduct/demos-and-presentations
Demos:
react-router-redux-demo โ€“ React + Redux + Router +
Thunk (async actions) integration
react-hocs-observables โ€“ React + Redux + Router + RxJS
Observables (async action stream transforms) + Reselect +
Recompose + Material-UI
Using Context, Higher-Order Components
and Observables with React
Sofia
May 15, 2017
Slide 4Sources:ReactJS [https://github.com/facebook/react/ ]
Licensed under the Creative Commons Attribution 4.0 International Public License
Contemporary Web Applications
Provide better User Experience (UX) by:
more interactive
loading and reacting faster in response (or even
anticipation) of user's moves
able to work offline
supporting multiple devices and screen resolutions
(responsive design)
are following design metaphors consistently (e.g. Google
Material Design - MD)
looking more like desktop application than static web page
Using Context, Higher-Order Components
and Observables with React
Sofia
May 15, 2017
Slide 5Sources:ReactJS [https://github.com/facebook/react/ ]
Licensed under the Creative Commons Attribution 4.0 International Public License
MVC Comes in Different Flavors
MVC
MVVM
MVP
Sources:https://en.wikipedia.org/wiki/Model_View_ViewModel#/media/File:MVVMPattern.png, https://en.wikipedia.org/wiki/Model
%E2%80%93view%E2%80%93presenter#/media/File:Model_View_Presenter_GUI_Design_Pattern.png
License: CC BY-SA 3.0, Authors:Ugaya40, Daniel.Cardenas
Using Context, Higher-Order Components
and Observables with React
Sofia
May 15, 2017
Slide 6Sources:ReactJS [https://github.com/facebook/react/ ]
Licensed under the Creative Commons Attribution 4.0 International Public License
Single Page Applications (SPA)
Source: http://stackoverflow.com/questions/12863663/complex-nesting-of-partials-and-templates
Author: PhillipKregg
Using Context, Higher-Order Components
and Observables with React
Sofia
May 15, 2017
Slide 7Sources:ReactJS [https://github.com/facebook/react/ ]
Licensed under the Creative Commons Attribution 4.0 International Public License
SPA with Multiple Router Outlets
Using Context, Higher-Order Components
and Observables with React
Sofia
May 15, 2017
Slide 8Sources:ReactJS [https://github.com/facebook/react/ ]
Licensed under the Creative Commons Attribution 4.0 International Public License
Why SPA?
Page does not flicker โ€“ seamless (or even animated)
transitions
Less data transferred โ€“ responses are cached
Only raw data, not markup
Features can be loaded on demand (lazy) or in background
Most page processing happens on the client offloading the
server: REST data services + snapshops for crawlers (SEO)
Code reuse โ€“ REST endopints are general purpose
Supporting multiple platforms (Web, iOS, Android) โ†’
React Native
Using Context, Higher-Order Components
and Observables with React
Slide 9Sources:ReactJS [https://github.com/facebook/react/ ]
Licensed under the Creative Commons Attribution 4.0 International Public License
Sofia
May 15, 2017
Developing Sinagle Page Apps (SPA) in 3 steps
1) Setting up a build system โ€“ npm, webpack, gulp are common
choices, babel, typescript, JSX, CSS preprocessors (SASS,
SCSS, LESS, PostCSS), servers ...
2) Designing front-end architecture components โ€“ views & layouts
+ view models (presentation data models) + presentation logic
(event handling, messaging) + routing paths (essential for SPA)
Better to use component model to boost productivity and
maintainability.
3) End-to-end application design โ€“ front-end: wireframes โ†’ views,
data entities & data streams โ†’ service API and models design,
sitemap โ†’ router config
Using Context, Higher-Order Components
and Observables with React
Sofia
May 15, 2017
Slide 10Sources:ReactJS [https://github.com/facebook/react/ ]
Licensed under the Creative Commons Attribution 4.0 International Public License
Components Resuability - Two Approaches
Inheritance - we create new component Types (or Classes)
by extending exiting ones โ€“ Class Hierachy:
Composition:
Object composition
Functional composition
Using Context, Higher-Order Components
and Observables with React
Sofia
May 15, 2017
Slide 11Sources:ReactJS [https://github.com/facebook/react/ ]
Licensed under the Creative Commons Attribution 4.0 International Public License
Object Composition Hierachy
Using Context, Higher-Order Components
and Observables with React
Sofia
May 15, 2017
Slide 12Sources:ReactJS [https://github.com/facebook/react/ ]
Licensed under the Creative Commons Attribution 4.0 International Public License
Functional Composition
Functional programming (FP) - the mathematical notion of
function composition
Composing functions f and g, g(f(x)) means fโ€™s out โ†’ gโ€™s input
In FP, the inputs and outputs are values without life cycles
Simpler to understand compared to object compositions
If input-output types match, functions can always compose!
More sophisticated forms of composition can be implemented
using higher-order functions: functions can be passed as
inputs and received as outputs to/from other functions
Functions are just immutable values โ€“ no special treatment!
Using Context, Higher-Order Components
and Observables with React
Sofia
May 15, 2017
Slide 13Sources:ReactJS [https://github.com/facebook/react/ ]
Licensed under the Creative Commons Attribution 4.0 International Public License
Higher-Order Components
Higher-order component (HOC) is a function that takes a
component and returns a new component:
const EnhancedComponent =
higherOrderComponent( WrappedComponent );
Example:
const VisibleTodoList =
connect(mapStateToProps, mapDispatchToProps) (TodoList);
Using Context, Higher-Order Components
and Observables with React
Sofia
May 15, 2017
Slide 14Sources:ReactJS [https://github.com/facebook/react/ ]
Licensed under the Creative Commons Attribution 4.0 International Public License
Use HOCs For Cross-Cutting Concerns
class BlogPost extends React.Component {
constructor(props) {
super(props);
this.handleChange = this.handleChange.bind(this);
this.state = {
blogPost: DataSource.getBlogPost(props.id)
};
}
componentDidMount(){DataSource.addChangeListener(this.handleChange);}
componentWillUnmount() {
DataSource.removeChangeListener(this.handleChange);}
handleChange() {
this.setState({blogPost: DataSource.getBlogPost(this.props.id)}); }
render() {
return <TextBlock text={this.state.blogPost} />; }
}
Using Context, Higher-Order Components
and Observables with React
Sofia
May 15, 2017
Slide 15Sources:ReactJS [https://github.com/facebook/react/ ]
Licensed under the Creative Commons Attribution 4.0 International Public License
Use HOCs For Cross-Cutting Concerns (2)
function withSubscription(WrappedComponent, selectData) {
return class extends React.Component {
constructor(props) {
super(props);
this.handleChange = this.handleChange.bind(this);
this.state = {data: selectData(DataSource, props) }; }
componentDidMount() {
DataSource.addChangeListener(this.handleChange); }
componentWillUnmount({
DataSource.removeChangeListener(this.handleChange);}
handleChange() {
this.setState({data: selectData(DataSource, this.props)});}
render() {
return <WrappedComponent data={this.state.data} {...this.props}/>;}
};
}
Anonimous class.
Name should be added using
dispalyName static property
Using Context, Higher-Order Components
and Observables with React
Sofia
May 15, 2017
Slide 16Sources:ReactJS [https://github.com/facebook/react/ ]
Licensed under the Creative Commons Attribution 4.0 International Public License
Usage:
const CommentListWithSubscription = withSubscription(
CommentList,
(DataSource) => DataSource.getComments()
);
const BlogPostWithSubscription = withSubscription(
BlogPost,
(DataSource, props) => DataSource.getBlogPost(props.id)
});
Using Context, Higher-Order Components
and Observables with React
Sofia
May 15, 2017
Slide 17Sources:ReactJS [https://github.com/facebook/react/ ]
Licensed under the Creative Commons Attribution 4.0 International Public License
Using HOCs โ€“ Things To Remember:
Don't Mutate the Original Component. Use Composition.
Convention: Pass Unrelated Props Through to the
Wrapped Component
Convention: Maximizing Composability
const ConnectedComment =
connect(commentSelector, commentActions)(Comment);
// compose(f, g, h) is the same as (...args) => f(g(h(...args)))
const enhance = compose(withRouter,
connect(commentSelector, commentActions) );
enhance(Comment);
Convention: Wrap the Display Name for Easy Debugging
The order matters!
Using Context, Higher-Order Components
and Observables with React
Sofia
May 15, 2017
Slide 18Sources:ReactJS [https://github.com/facebook/react/ ]
Licensed under the Creative Commons Attribution 4.0 International Public License
How to Boost Performance with React
Use the production build
Avoiding reconciling the DOM โ€“ React provides a component
lifecycle function, shouldComponentUpdate, which is
triggered before the re-rendering process starts (virtual DOM
comparison and possible eventual DOM reconciliation), giving
the developer the ability to short circuit this process. Default:
shouldComponentUpdate: function(nextProps, nextState) {
return true;
}
React invokes shouldComponentUpdate often -should be fast
Use immutability for comparisons to be efficient
Using Context, Higher-Order Components
and Observables with React
Sofia
May 15, 2017
Slide 19Sources:ReactJS [https://github.com/facebook/react/ ]
Licensed under the Creative Commons Attribution 4.0 International Public License
Performance with shouldComponentUpdate
class MyStatelessComp extends React.Component {
static propTypes = {
value: PropTypes.string.isRequired
};
shouldComponentUpdate: function(nextProps, nextState) {
return this.props.value !== nextProps.value;
},
render: function() {
return <div>{this.props.value}</div>;
}
});
Using Context, Higher-Order Components
and Observables with React
Sofia
May 15, 2017
Slide 20Sources:ReactJS [https://github.com/facebook/react/ ]
Licensed under the Creative Commons Attribution 4.0 International Public License
Boosting Performance: PureRenderMixin
Before โ€“ using mixins(Mixins Considered Harmful by Dan Abramov):
var PureRenderMixin = require('react-addons-pure-render-mixin');
React.createClass({
mixins: [PureRenderMixin],
render: function() {
return <div className={this.props.className}>foo</div>;
}
});
Now you should prefer:
class MyComponent extends React.PureComponent { โ€ฆ }
Using Context, Higher-Order Components
and Observables with React
Sofia
May 15, 2017
Slide 21Sources:ReactJS [https://github.com/facebook/react/ ]
Licensed under the Creative Commons Attribution 4.0 International Public License
Using HOCs โ€“ Caveats:
Don't Use HOCs Inside the render Method:
render() {
const EnhancedComponent = enhance(MyComponent);
return <EnhancedComponent />;
}
Static Methods Must Be Copied Over
Maximizing Composability
Refs Aren't Passed Through
Don't
Using Context, Higher-Order Components
and Observables with React
Sofia
May 15, 2017
Slide 22Sources:ReactJS [https://github.com/facebook/react/ ]
Licensed under the Creative Commons Attribution 4.0 International Public License
Refs to Components
Refs (references) โ€“ allow to find the DOM markup rendered
by a component, and invoke methods on component
instances returned from render()
Example uses: absolute positioning, using React components in
larger non-React applications, transition existing code to React.
var myComponentInstanceRef =
ReactDOM.render(<MyComp />, myContainer);
myComponentInstanceRef.doSomething();
ReactDOM.findDOMNode(componentInstance) โ€“ this
function will return the DOM node belonging to the outermost
HTML element returned by render.
Using Context, Higher-Order Components
and Observables with React
Sofia
May 15, 2017
Slide 23Sources:ReactJS [https://github.com/facebook/react/ ]
Licensed under the Creative Commons Attribution 4.0 International Public License
The ref Callback Attribute
render: function() {
return (
<TextInput ref={ function(input) {
if (input != null) {
input.focus();
}
}} />
);
},
OR better using ES6 => :
render: function() {
return <TextInput ref={(c) => this._input = c} />;
},
componentDidMount: function() {
this._input.focus();
},
Will be called twice โ€“ on mount with ref,
and on unmount with null. That is why
we check if ref not null.
Using Context, Higher-Order Components
and Observables with React
Sofia
May 15, 2017
Slide 24Sources:ReactJS [https://github.com/facebook/react/ ]
Licensed under the Creative Commons Attribution 4.0 International Public License
Using React Component Context
React props allow to track data-flow easy between componets
React Context is alternative if you want to pass data through
the component tree without having to pass the props down
manually at every level.
Inversion of Control (IoC) principle and Dependency Injection
(DI) pattern
React's "context" feature lets you do this โ€“ Example how to
inject testService and router in TestsList component:
TestsList.contextTypes = {
testService: React.PropTypes.object,
router: React.PropTypes.object
};
Using Context, Higher-Order Components
and Observables with React
Sofia
May 15, 2017
Slide 25Sources:ReactJS [https://github.com/facebook/react/ ]
Licensed under the Creative Commons Attribution 4.0 International Public License
Passing Refs from Wrapped Comp to HOC
function Field({ inputRef, ...rest }) {
return <input ref={inputRef} {...rest} />;
}
// Wrap Field in a higher-order component
const EnhancedField = enhance(Field);
// Inside a class component's render method...
<EnhancedField
inputRef={(inputEl) => {
// This callback gets passed through as a regular prop
this.inputEl = inputEl
}}
/>
// Now you can call imperative methods
this.inputEl.focus();
Using Context, Higher-Order Components
and Observables with React
Sofia
May 15, 2017
Slide 26Sources:ReactJS [https://github.com/facebook/react/ ]
Licensed under the Creative Commons Attribution 4.0 International Public License
Providing Services with React Context
class IPTKnowledgeTester extends React.Component {
constructor(props) { super(props);
this.testServiceSingleton = new TestService(TEST_SERVICE_URL);
this.localeServiceSingleton = new LocaleService(DEFAULT_LOCALE,
this.onLocaleChange);
}
getChildContext() {
return {
testService: this.testServiceSingleton,
localeService: this.localeServiceSingleton
}; } โ€ฆ
}
IPTKnowledgeTester.childContextTypes = {
testService: React.PropTypes.object,
localeService: React.PropTypes.object
};
Using Context, Higher-Order Components
and Observables with React
Sofia
May 15, 2017
Slide 27Sources:ReactJS [https://github.com/facebook/react/ ]
Licensed under the Creative Commons Attribution 4.0 International Public License
React Context Usage Example
handleAddTest() {
const path = { pathname: '/test',
query: { controls: true, edit: true } };
this.context.router.push(path);
}
componentDidMount() {
this.context.testService.getTests().then((tests) => {
this.setState({ tests: tests });
});
}
Using Context, Higher-Order Components
and Observables with React
Sofia
May 15, 2017
Slide 28Sources:ReactJS [https://github.com/facebook/react/ ]
Licensed under the Creative Commons Attribution 4.0 International Public License
Referencing Context in Lifecycle Methods
void componentWillReceiveProps(
object nextProps, object nextContext
)
boolean shouldComponentUpdate(
object nextProps, object nextState, object nextContext
)
void componentWillUpdate(
object nextProps, object nextState, object nextContext
)
void componentDidUpdate(
object prevProps, object prevState, object prevContext
)
Using Context, Higher-Order Components
and Observables with React
Sofia
May 15, 2017
Slide 29Sources:ReactJS [https://github.com/facebook/react/ ]
Licensed under the Creative Commons Attribution 4.0 International Public License
Using Context with Functional Components
const Button = ({children}, context) =>
<button style={{background: context.color}}>
{children}
</button>;
Button.contextTypes = {color: React.PropTypes.string};
Using Context, Higher-Order Components
and Observables with React
Sofia
May 15, 2017
Slide 30Sources:ReactJS [https://github.com/facebook/react/ ]
Licensed under the Creative Commons Attribution 4.0 International Public License
React Router v4 Configuration
<Route path="/" component={Base} />
<Route path="/home" component={Home} />
<Route path="/intro"
render={() => <div>How to start using this app</div>} />
<Route path="/repos" component={Repos} />
<Route path="/topics" component={Topics} />
<Route path="/about" component={About} />
<Route path="/show-location" component={ShowTheLocation} />
const Repos = (props) => {
return (
<div>
<h2>Repos</h2>
<Route path="/repos/:userName/:repoName" component={Repo} />
</div>
);
};
Hierarchical navigation,
no need to use props.children
Using Context, Higher-Order Components
and Observables with React
Sofia
May 15, 2017
Slide 31Sources:ReactJS [https://github.com/facebook/react/ ]
Licensed under the Creative Commons Attribution 4.0 International Public License
Site Navigation using Router v4
<ul className="main-menu">
<li><Link to="/home">Home</Link></li>
<li><Link to="/intro">Intro</Link></li>
<li><Link to="/repos">Repos</Link></li>
<li><Link to="/topics">Topics</Link></li>
<li><Link to="/show-location">Show the Location</Link></li>
<li><Link to="/about">About</Link></li>
<form className="navbar-form navbar-right" role="search"
onSubmit={this.handleSerch}>
<input type="text" placeholder="userName" /> / {' '}
<input type="text" placeholder="repo" /> {' '}
<button type="submit" className="btn btn-default">Go</button>
</form>
</ul>
Using Context, Higher-Order Components
and Observables with React
Sofia
May 15, 2017
Slide 32Sources:ReactJS [https://github.com/facebook/react/ ]
Licensed under the Creative Commons Attribution 4.0 International Public License
Programmatic Navigation using Router v4
ReactDOM.render(
<Router >
<App />
</Router>,
document.getElementById('root')
);
handleSerch = (event) => {
event.preventDefault();
const userName = event.target.elements[0].value;
const repo = event.target.elements[1].value;
const path = `/repos/${userName}/${repo}`;
console.log(path);
console.log(this.context);
// this.context.router.history.push(path);
this.props.history.push(path);
}
Using Context, Higher-Order Components
and Observables with React
Sofia
May 15, 2017
Slide 33Sources:ReactJS [https://github.com/facebook/react/ ]
Licensed under the Creative Commons Attribution 4.0 International Public License
Using @withRouter Decorator (HOC) - Router v4
import React from 'react';
import PropTypes from 'prop-types';
import { withRouter } from 'react-router-dom';
@withRouter
export default class ShowTheLocation extends React.Component {
render() {
const { match, location, history } = this.props;
return (
<div>
<div>You are now at {location.pathname}</div>
<div>The match is: {JSON.stringify(match)}</div>
<div>The history contains: {JSON.stringify(history)}</div>
</div>
)
}
}
Using Context, Higher-Order Components
and Observables with React
Sofia
May 15, 2017
Slide 34Sources:ReactJS [https://github.com/facebook/react/ ]
Licensed under the Creative Commons Attribution 4.0 International Public License
Flux Design Pattern
Source: Flux in GitHub, https://github.com/facebook/flux, License: BSD 3-clause "New" License
Using Context, Higher-Order Components
and Observables with React
Sofia
May 15, 2017
Slide 35Sources:ReactJS [https://github.com/facebook/react/ ]
Licensed under the Creative Commons Attribution 4.0 International Public License
Redux Design Pattern
Source: @ngrx/store in GitHub, https://gist.github.com/btroncone/a6e4347326749f938510
Linear flow:
Using Context, Higher-Order Components
and Observables with React
Sofia
May 15, 2017
Slide 36Sources:ReactJS [https://github.com/facebook/react/ ]
Licensed under the Creative Commons Attribution 4.0 International Public License
Redux
Streamlined state management for React.js applications,
inspired by Redux
State is a single immutable data structure
Actions describe state changes
Pure functions called reducers take the previous state and the
next action to compute the new state
State is kept within single Store, and accessed through sub-
state selectors, or as Observable of state changes
Components are by default perfomance optimized using the
shouldComponentUpdate() โ†’ performant change detection
Using Context, Higher-Order Components
and Observables with React
Sofia
May 15, 2017
Slide 37Sources:ReactJS [https://github.com/facebook/react/ ]
Licensed under the Creative Commons Attribution 4.0 International Public License
Redux Recommended (Basic) Project Structure
actions โ€“ action creator factory functions (design pattern
Command)
assets โ€“ static assets (css images, fonts, etc.) folder
components โ€“ simple (dumb) react components โ€“ pure render
container โ€“ Redux Store aware (smart) component wrappers
reducers โ€“ the only way to advance state:
function(OldStoreState, Action) => NewStoreState // = Rx scan()
index.js โ€“ bootstraps app providing access to Store for all
containers (smart components) using React context
Using Context, Higher-Order Components
and Observables with React
Sofia
May 15, 2017
Slide 38Sources:ReactJS [https://github.com/facebook/react/ ]
Licensed under the Creative Commons Attribution 4.0 International Public License
Bootstrapping Redux App โ€“ index.js
import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import { createStore } from 'redux';
import rootReducer from './reducers';
import { FilteredTodoApp } from './containers/filtered-todo-app';
const store = createStore(
rootReducer, window.__REDUX_DEVTOOLS_EXTENSION__ &&
window.__REDUX_DEVTOOLS_EXTENSION__() );
const render = (Component) => {
ReactDOM.render(
<Provider store={store}>
<FilteredTodoApp />
</Provider>,
document.getElementById('root')
);
};
Top level container component
Redux store provider
Using Context, Higher-Order Components
and Observables with React
Sofia
May 15, 2017
Slide 39Sources:ReactJS [https://github.com/facebook/react/ ]
Licensed under the Creative Commons Attribution 4.0 International Public License
Redux Action Creators โ€“ /actions/index.js
let nextTodoId = 0;
export const addTodo = (text) => ({
type: 'ADD_TODO',
id: nextTodoId++,
text
});
export const setVisibilityFilter = (filter) => ({
type: 'SET_VISIBILITY_FILTER',
filter
});
export const changeStatus = (id, status) => ({
type: 'CHANGE_STATUS',
id,
status
});
...
Action Payload
Action Type
Using Context, Higher-Order Components
and Observables with React
Sofia
May 15, 2017
Slide 40Sources:ReactJS [https://github.com/facebook/react/ ]
Licensed under the Creative Commons Attribution 4.0 International Public License
Redux Reducers โ€“ /reducers/todo.js
const todoReducer = (state = {}, action) => {
switch (action.type) {
case 'ADD_TODO':
return {
id: action.id,
text: action.text,
status: 'active'
};
case 'CHANGE_STATUS':
if (state.id !== action.id) {
return state;
}
return Object.assign({}, state, { status: action.status });
default:
return state;
}
};
Using Context, Higher-Order Components
and Observables with React
Sofia
May 15, 2017
Slide 41Sources:ReactJS [https://github.com/facebook/react/ ]
Licensed under the Creative Commons Attribution 4.0 International Public License
Redux Reducers โ€“ /reducers/todos.js
const todosReducer = (state = [], action) => {
switch (action.type) {
case 'ADD_TODO':
return [
...state,
todoReducer(undefined, action)
];
case 'CHANGE_STATUS':
return state.map(todo =>
todoReducer(todo, action)
);
case 'DELETE_TODOS':
return state.filter(todo =>
todo.status !== action.status
);
default:
return state;
}
};
Using Context, Higher-Order Components
and Observables with React
Sofia
May 15, 2017
Slide 42Sources:ReactJS [https://github.com/facebook/react/ ]
Licensed under the Creative Commons Attribution 4.0 International Public License
Redux Root Reducer โ€“ /reducers/index.js
import { combineReducers } from 'redux';
import todos from './todos';
import visibilityFilter from './visibilityFilter';
const rootReducer = combineReducers({
todos,
visibilityFilter
});
export default rootReducer;
Using Context, Higher-Order Components
and Observables with React
Sofia
May 15, 2017
Slide 43Sources:ReactJS [https://github.com/facebook/react/ ]
Licensed under the Creative Commons Attribution 4.0 International Public License
Redux Containers โ€“ /conatiners/visible-todo-list.js
const getVisibleTodos = (todos, filter) => todos.filter(
todo => filter === 'all' ? true: todo.status === filter);
const mapStateToProps = (state) => ({
todos: getVisibleTodos(state.todos, state.visibilityFilter)
});
const mapDispatchToProps = (dispatch) => ({
onCompleted: (id) => {
dispatch(changeStatus(id, 'completed'));
},
onCanceled: (id) => {
dispatch(changeStatus(id, 'canceled'));
}
});
const VisibleTodoList = connect(mapStateToProps, mapDispatchToProps
) (TodoList);
export default VisibleTodoList;
Using Context, Higher-Order Components
and Observables with React
Sofia
May 15, 2017
Slide 44Sources:ReactJS [https://github.com/facebook/react/ ]
Licensed under the Creative Commons Attribution 4.0 International Public License
Redux App using ES7 @connect Decorator
const getVisibleTodos = (todos, filter) => todos.filter(
todo => filter === 'all' ? true: todo.status === filter);
const mapStateToProps = (state) => ({
todos: getVisibleTodos(state.todos, state.visibilityFilter)
});
const mapDispatchToProps = (dispatch) => ({
onCompleted: (id) => {
dispatch(changeStatus(id, 'completed'));
},
onCanceled: (id) => {
dispatch(changeStatus(id, 'canceled'));
}
});
@connect(mapStateToProps, mapDispatchToProps)
export default class TodoList extends React.Component {
constructor(props) { ...
Using Context, Higher-Order Components
and Observables with React
Sofia
May 15, 2017
Slide 45Sources:ReactJS [https://github.com/facebook/react/ ]
Licensed under the Creative Commons Attribution 4.0 International Public License
Using Redux Router Redux and Redux Thunk (1)
Idea: history + store (redux) โ†’ react-router-redux โ†’ enhanced history โ†’ react-
router
import { compose, createStore, combineReducers, applyMiddleware } from
'redux';
import { Provider } from 'react-redux';
import createHistory from 'history/createBrowserHistory';
import { ConnectedRouter, routerReducer, routerMiddleware, push } from
'react-router-redux'; // React Router to Redux integration
import thunk from 'redux-thunk'; // Allows using thunks = async actions
import reducers from './reducers'; // your reducers here
const history = createHistory(); // use browser History API
// middleware for intercepting & dispatching navigation & async actions
const middleware = [routerMiddleware(history), thunk];
// Enable Redux Devtools
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ ||
compose;
Using Context, Higher-Order Components
and Observables with React
Sofia
May 15, 2017
Slide 46Sources:ReactJS [https://github.com/facebook/react/ ]
Licensed under the Creative Commons Attribution 4.0 International Public License
Using Redux Router Redux and Redux Thunk (2)
const store = createStore(
CombineReducers({ ...reducers,
router: routerReducer // Add the reducer to store on `router` key
}),
/* preloadedState, */
ComposeEnhancers( applyMiddleware(...middleware) ));
store.dispatch(push('/repos/react/redux'));//dispatch navigation action
ReactDOM.render(
<Provider store={store}>//ConnectedRouter use store from the Provider
<ConnectedRouter history={history}>
<App />
</ConnectedRouter>
</Provider>,
document.getElementById('root')
)
Using Context, Higher-Order Components
and Observables with React
Sofia
May 15, 2017
Slide 47Sources:ReactJS [https://github.com/facebook/react/ ]
Licensed under the Creative Commons Attribution 4.0 International Public License
Redux Thunk Async Actions - /actions/counter.js
export function increment(x) {
return { type: INCREMENT, amount: x }
}
export function incrementAsync(x) {
return dispatch => //Can invoke sync or async actions with `dispatch`
setTimeout(() => { dispatch(increment(x)); }, 2000);
}
export function incrementIfOdd(x) {
return (dispatch, getState) => {
const { counter } = getState();
if (counter.number % 2 === 0) return;
dispatch(increment(x)); //Can invoke actions conditionally
};
}
Using Context, Higher-Order Components
and Observables with React
Sofia
May 15, 2017
Slide 48Sources:ReactJS [https://github.com/facebook/react/ ]
Licensed under the Creative Commons Attribution 4.0 International Public License
Advanced Redux using Middleware Libraries
Normalizr โ€“ normalizing and denormalizing data in state, helps
to transform nested JSON response structures into a relational
DB-like plain entities, referenced by Id in the Redux store.
redux-thunk โ€“ in addition to plain actions, Action Creators can
now return Thunks โ€“ callback functions of dispatch and
getState arguments, allowing to handle async operations like
data fetch from REST endpoint and Promise-like composition.
redux-promise/ redux-promise-middleware โ€“ thunk alternatives
redux-observable โ€“ really powerfull reactive transforms of
async action events as RxJS Observables, called Epics:
(action$:Observable<Action>, store:Store) => Observable<Action>
Using Context, Higher-Order Components
and Observables with React
Sofia
May 15, 2017
Slide 49Sources:ReactJS [https://github.com/facebook/react/ ]
Licensed under the Creative Commons Attribution 4.0 International Public License
Functional Reactive Programming
Functional Reactive Programming (FRP) [Wikipedia]: a
programming paradigm for reactive programming
(asynchronous dataflow programming) using the building
blocks of functional programming (e.g. map, reduce, filter).
FRP has been used for programming graphical user
interfaces (GUIs), robotics, and music, aiming to simplify
these problems by explicitly modeling time. Ex. (RxJS):
const Observable = require('rxjs').Observable;
Observable.from(['Reactive', 'Extensions', 'JavaScript'])
.take(2).map(s => `${s}: on ${new Date()}`)
.subscribe(s => console.log(s));
Result: Reactive: on Sat Apr 29 2017 20:00:39 GMT+0300
Extensions: on Sat Apr 29 2017 20:00:39 GMT+0300
Good intro tutorial in RP using RxJS by Andre Staltz see: https://gist.github.com/staltz/868e7e9bc2a7b8c1f754
JS Fiddle of the demo: http://jsfiddle.net/staltz/8jFJH/48/
Using Context, Higher-Order Components
and Observables with React
Sofia
May 15, 2017
Slide 50Sources:ReactJS [https://github.com/facebook/react/ ]
Licensed under the Creative Commons Attribution 4.0 International Public License
Definitions of Reactive Programming
Microsoftยฎ
opens source polyglot project ReactiveX
(Reactive Extensions) [http://reactivex.io]:
Rx = Observables + LINQ + Schedulers :)
Supported Languages โ€“ Java: RxJava, JavaScript: RxJS, C#: Rx.NET,
C#(Unity): UniRx, Scala: RxScala, Clojure: RxClojure, C++: RxCpp,
Ruby: Rx.rb, Python: RxPY, Groovy: RxGroovy, JRuby: RxJRuby,
Kotlin: RxKotlin, Swift: RxSwift
ReactiveX for platforms and frameworks: RxNetty, RxAndroid, RxCocoa
Reactive Streams Specification
[http://www.reactive-streams.org/]
Using Context, Higher-Order Components
and Observables with React
Sofia
May 15, 2017
Slide 51Sources:ReactJS [https://github.com/facebook/react/ ]
Licensed under the Creative Commons Attribution 4.0 International Public License
RxJS โ€“ JS ReactiveX (Reactive Extensions)
[http://reactivex.io, https://github.com/ReactiveX]
ReactiveX is a polyglot library for composing asynchronous
event streams (observable sequences).
It extends the observer pattern by declarative composition of
functional transformations on events streams (e.g. map-filter-
reduce, etc.)
Abstracs away low-level concerns like concurrency,
synchronization, and non-blocking I/O.
Follows the next - error - completed event flow
Allows natural implementation of Redux design pattern
Alternative (together with promises) for solving โ€œcallback hellโ€
problem
Using Context, Higher-Order Components
and Observables with React
Sofia
May 15, 2017
Slide 52Sources:ReactJS [https://github.com/facebook/react/ ]
Licensed under the Creative Commons Attribution 4.0 International Public License
Resources: RxMarbles and RxJS Coans
RxMarbles:
http://rxmarbles.com/
RxJS Coans:
https://github.com/Reactive-Extensions/RxJSKoans
Using Context, Higher-Order Components
and Observables with React
Sofia
May 15, 2017
Slide 53Sources:ReactJS [https://github.com/facebook/react/ ]
Licensed under the Creative Commons Attribution 4.0 International Public License
Demo Time :)
React.js demo code is available @GitHub:
https://github.com/iproduct/demos-and-presentations
Demos:
react-router-redux-demo โ€“ React + Redux + Router +
Thunk (async actions) integration
react-hocs-observables โ€“ React + Redux + Router + RxJS
Observables (async action stream transforms) + Reselect +
Recompose + Material-UI
Using Context, Higher-Order Components
and Observables with React
Sofia
May 15, 2017
Slide 54Sources:ReactJS [https://github.com/facebook/react/ ]
Licensed under the Creative Commons Attribution 4.0 International Public License
Thankโ€™s for Your Attention!
Trayan Iliev
CEO of IPT โ€“ Intellectual Products
& Technologies
http://iproduct.org/
http://robolearn.org/
https://github.com/iproduct
https://twitter.com/trayaniliev
https://www.facebook.com/IPT.EACAD
https://plus.google.com/+IproductOrg

More Related Content

Similar to React HOCs, Context and Observables

Front End Development for Back End Java Developers - West Midlands Java User ...
Front End Development for Back End Java Developers - West Midlands Java User ...Front End Development for Back End Java Developers - West Midlands Java User ...
Front End Development for Back End Java Developers - West Midlands Java User ...Matt Raible
ย 
Vue and Firebase Experiences
Vue and Firebase ExperiencesVue and Firebase Experiences
Vue and Firebase ExperiencesIsatu Conteh
ย 
Front End Development for Back End Java Developers - South West Java 2019
Front End Development for Back End Java Developers - South West Java 2019Front End Development for Back End Java Developers - South West Java 2019
Front End Development for Back End Java Developers - South West Java 2019Matt Raible
ย 
ReactJS Tutorial For Beginners | ReactJS Redux Training For Beginners | React...
ReactJS Tutorial For Beginners | ReactJS Redux Training For Beginners | React...ReactJS Tutorial For Beginners | ReactJS Redux Training For Beginners | React...
ReactJS Tutorial For Beginners | ReactJS Redux Training For Beginners | React...Edureka!
ย 
Front End Development for Back End Java Developers - Dublin JUG 2019
Front End Development for Back End Java Developers - Dublin JUG 2019Front End Development for Back End Java Developers - Dublin JUG 2019
Front End Development for Back End Java Developers - Dublin JUG 2019Matt Raible
ย 
Bermon Painter - Rapid Prototyping with Vue.js - Codemotion Rome 2019
Bermon Painter - Rapid Prototyping with Vue.js - Codemotion Rome 2019Bermon Painter - Rapid Prototyping with Vue.js - Codemotion Rome 2019
Bermon Painter - Rapid Prototyping with Vue.js - Codemotion Rome 2019Codemotion
ย 
Full Stack Reactive with React and Spring WebFlux - Switzerland JUG 2020
Full Stack Reactive with React and Spring WebFlux - Switzerland JUG 2020Full Stack Reactive with React and Spring WebFlux - Switzerland JUG 2020
Full Stack Reactive with React and Spring WebFlux - Switzerland JUG 2020Matt Raible
ย 
Advanced Web Development
Advanced Web DevelopmentAdvanced Web Development
Advanced Web DevelopmentRobert J. Stein
ย 
Introduction to react js
Introduction to react jsIntroduction to react js
Introduction to react jsAeshan Wijetunge
ย 
The Best Guide to Know What, Why, When to Use Is ReactJS
The Best Guide to Know What, Why, When to Use Is ReactJSThe Best Guide to Know What, Why, When to Use Is ReactJS
The Best Guide to Know What, Why, When to Use Is ReactJSWeblineIndia
ย 
Full Stack Reactive with React and Spring WebFlux - Dublin JUG 2019
Full Stack Reactive with React and Spring WebFlux - Dublin JUG 2019Full Stack Reactive with React and Spring WebFlux - Dublin JUG 2019
Full Stack Reactive with React and Spring WebFlux - Dublin JUG 2019Matt Raible
ย 
Get Hip with JHipster - GIDS 2019
Get Hip with JHipster - GIDS 2019Get Hip with JHipster - GIDS 2019
Get Hip with JHipster - GIDS 2019Matt Raible
ย 
Front End Development for Back End Developers - vJUG24 2017
Front End Development for Back End Developers - vJUG24 2017Front End Development for Back End Developers - vJUG24 2017
Front End Development for Back End Developers - vJUG24 2017Matt Raible
ย 
what is context API and How it works in React.pptx
what is context API and How it works in React.pptxwhat is context API and How it works in React.pptx
what is context API and How it works in React.pptxBOSC Tech Labs
ย 
SPS Bremen 2020 The happy developer - SharePoint Framework - React - Mindfulness
SPS Bremen 2020 The happy developer - SharePoint Framework - React - MindfulnessSPS Bremen 2020 The happy developer - SharePoint Framework - React - Mindfulness
SPS Bremen 2020 The happy developer - SharePoint Framework - React - MindfulnessOlli Jรครคskelรคinen
ย 
Building a developer friendly plugin - WordCamp Chicago 2017
Building a developer friendly plugin - WordCamp Chicago 2017Building a developer friendly plugin - WordCamp Chicago 2017
Building a developer friendly plugin - WordCamp Chicago 2017Mike Hale
ย 
OttawaJS - React
OttawaJS - ReactOttawaJS - React
OttawaJS - Reactrbl002
ย 
Front Ends for Back End Developers - Spring I/O 2017
Front Ends for Back End Developers - Spring I/O 2017Front Ends for Back End Developers - Spring I/O 2017
Front Ends for Back End Developers - Spring I/O 2017Matt Raible
ย 

Similar to React HOCs, Context and Observables (20)

Front End Development for Back End Java Developers - West Midlands Java User ...
Front End Development for Back End Java Developers - West Midlands Java User ...Front End Development for Back End Java Developers - West Midlands Java User ...
Front End Development for Back End Java Developers - West Midlands Java User ...
ย 
Vue and Firebase Experiences
Vue and Firebase ExperiencesVue and Firebase Experiences
Vue and Firebase Experiences
ย 
Front End Development for Back End Java Developers - South West Java 2019
Front End Development for Back End Java Developers - South West Java 2019Front End Development for Back End Java Developers - South West Java 2019
Front End Development for Back End Java Developers - South West Java 2019
ย 
ReactJS Tutorial For Beginners | ReactJS Redux Training For Beginners | React...
ReactJS Tutorial For Beginners | ReactJS Redux Training For Beginners | React...ReactJS Tutorial For Beginners | ReactJS Redux Training For Beginners | React...
ReactJS Tutorial For Beginners | ReactJS Redux Training For Beginners | React...
ย 
Front End Development for Back End Java Developers - Dublin JUG 2019
Front End Development for Back End Java Developers - Dublin JUG 2019Front End Development for Back End Java Developers - Dublin JUG 2019
Front End Development for Back End Java Developers - Dublin JUG 2019
ย 
Bermon Painter - Rapid Prototyping with Vue.js - Codemotion Rome 2019
Bermon Painter - Rapid Prototyping with Vue.js - Codemotion Rome 2019Bermon Painter - Rapid Prototyping with Vue.js - Codemotion Rome 2019
Bermon Painter - Rapid Prototyping with Vue.js - Codemotion Rome 2019
ย 
Full Stack Reactive with React and Spring WebFlux - Switzerland JUG 2020
Full Stack Reactive with React and Spring WebFlux - Switzerland JUG 2020Full Stack Reactive with React and Spring WebFlux - Switzerland JUG 2020
Full Stack Reactive with React and Spring WebFlux - Switzerland JUG 2020
ย 
Advanced Web Development
Advanced Web DevelopmentAdvanced Web Development
Advanced Web Development
ย 
Introduction to react js
Introduction to react jsIntroduction to react js
Introduction to react js
ย 
The Best Guide to Know What, Why, When to Use Is ReactJS
The Best Guide to Know What, Why, When to Use Is ReactJSThe Best Guide to Know What, Why, When to Use Is ReactJS
The Best Guide to Know What, Why, When to Use Is ReactJS
ย 
Full Stack Reactive with React and Spring WebFlux - Dublin JUG 2019
Full Stack Reactive with React and Spring WebFlux - Dublin JUG 2019Full Stack Reactive with React and Spring WebFlux - Dublin JUG 2019
Full Stack Reactive with React and Spring WebFlux - Dublin JUG 2019
ย 
Reactjs
ReactjsReactjs
Reactjs
ย 
Exploring My Career: an Exclusive Interview EN
Exploring My Career: an Exclusive Interview ENExploring My Career: an Exclusive Interview EN
Exploring My Career: an Exclusive Interview EN
ย 
Get Hip with JHipster - GIDS 2019
Get Hip with JHipster - GIDS 2019Get Hip with JHipster - GIDS 2019
Get Hip with JHipster - GIDS 2019
ย 
Front End Development for Back End Developers - vJUG24 2017
Front End Development for Back End Developers - vJUG24 2017Front End Development for Back End Developers - vJUG24 2017
Front End Development for Back End Developers - vJUG24 2017
ย 
what is context API and How it works in React.pptx
what is context API and How it works in React.pptxwhat is context API and How it works in React.pptx
what is context API and How it works in React.pptx
ย 
SPS Bremen 2020 The happy developer - SharePoint Framework - React - Mindfulness
SPS Bremen 2020 The happy developer - SharePoint Framework - React - MindfulnessSPS Bremen 2020 The happy developer - SharePoint Framework - React - Mindfulness
SPS Bremen 2020 The happy developer - SharePoint Framework - React - Mindfulness
ย 
Building a developer friendly plugin - WordCamp Chicago 2017
Building a developer friendly plugin - WordCamp Chicago 2017Building a developer friendly plugin - WordCamp Chicago 2017
Building a developer friendly plugin - WordCamp Chicago 2017
ย 
OttawaJS - React
OttawaJS - ReactOttawaJS - React
OttawaJS - React
ย 
Front Ends for Back End Developers - Spring I/O 2017
Front Ends for Back End Developers - Spring I/O 2017Front Ends for Back End Developers - Spring I/O 2017
Front Ends for Back End Developers - Spring I/O 2017
ย 

More from Trayan Iliev

Making Machine Learning Easy with H2O and WebFlux
Making Machine Learning Easy with H2O and WebFluxMaking Machine Learning Easy with H2O and WebFlux
Making Machine Learning Easy with H2O and WebFluxTrayan Iliev
ย 
Rapid Web API development with Kotlin and Ktor
Rapid Web API development with Kotlin and KtorRapid Web API development with Kotlin and Ktor
Rapid Web API development with Kotlin and KtorTrayan Iliev
ย 
IPT Reactive Java IoT Demo - BGOUG 2018
IPT Reactive Java IoT Demo - BGOUG 2018IPT Reactive Java IoT Demo - BGOUG 2018
IPT Reactive Java IoT Demo - BGOUG 2018Trayan Iliev
ย 
Learning Programming Using Robots - Sofia University Conference 2018
Learning Programming Using Robots - Sofia University Conference 2018 Learning Programming Using Robots - Sofia University Conference 2018
Learning Programming Using Robots - Sofia University Conference 2018 Trayan Iliev
ย 
Active Learning Using Connected Things - 2018 (in Bulgarian)
Active Learning Using Connected Things - 2018 (in Bulgarian)Active Learning Using Connected Things - 2018 (in Bulgarian)
Active Learning Using Connected Things - 2018 (in Bulgarian)Trayan Iliev
ย 
Spring 5 Webflux - Advances in Java 2018
Spring 5 Webflux - Advances in Java 2018Spring 5 Webflux - Advances in Java 2018
Spring 5 Webflux - Advances in Java 2018Trayan Iliev
ย 
Fog Computing - DEV.BG 2018
Fog Computing - DEV.BG 2018Fog Computing - DEV.BG 2018
Fog Computing - DEV.BG 2018Trayan Iliev
ย 
Microservices with Spring 5 Webflux - jProfessionals
Microservices  with Spring 5 Webflux - jProfessionalsMicroservices  with Spring 5 Webflux - jProfessionals
Microservices with Spring 5 Webflux - jProfessionalsTrayan Iliev
ย 
Reactive Microservices with Spring 5: WebFlux
Reactive Microservices with Spring 5: WebFlux Reactive Microservices with Spring 5: WebFlux
Reactive Microservices with Spring 5: WebFlux Trayan Iliev
ย 
What's new in java 9?
What's new in java 9?What's new in java 9?
What's new in java 9?Trayan Iliev
ย 
NGRX Apps in Depth
NGRX Apps in DepthNGRX Apps in Depth
NGRX Apps in DepthTrayan Iliev
ย 
Stream Processing with CompletableFuture and Flow in Java 9
Stream Processing with CompletableFuture and Flow in Java 9Stream Processing with CompletableFuture and Flow in Java 9
Stream Processing with CompletableFuture and Flow in Java 9Trayan Iliev
ย 
Reactive Java Robotics & IoT with Spring Reactor
Reactive Java Robotics & IoT with Spring ReactorReactive Java Robotics & IoT with Spring Reactor
Reactive Java Robotics & IoT with Spring ReactorTrayan Iliev
ย 
Hackathon: โ€œIPTPI and LeJaRo Meet The Real Worldโ€
Hackathon: โ€œIPTPI and LeJaRo Meet The Real Worldโ€Hackathon: โ€œIPTPI and LeJaRo Meet The Real Worldโ€
Hackathon: โ€œIPTPI and LeJaRo Meet The Real Worldโ€Trayan Iliev
ย 
Reactive robotics io_t_2017
Reactive robotics io_t_2017Reactive robotics io_t_2017
Reactive robotics io_t_2017Trayan Iliev
ย 
Java & JavaScipt Reactive Robotics and IoT 2016 @ jProfessionals
Java & JavaScipt Reactive Robotics and IoT 2016 @ jProfessionalsJava & JavaScipt Reactive Robotics and IoT 2016 @ jProfessionals
Java & JavaScipt Reactive Robotics and IoT 2016 @ jProfessionalsTrayan Iliev
ย 
IPT High Performance Reactive Java BGOUG 2016
IPT High Performance Reactive Java BGOUG 2016IPT High Performance Reactive Java BGOUG 2016
IPT High Performance Reactive Java BGOUG 2016Trayan Iliev
ย 
Reactive Java Robotics IoT - jPrime 2016
Reactive Java Robotics IoT - jPrime 2016Reactive Java Robotics IoT - jPrime 2016
Reactive Java Robotics IoT - jPrime 2016Trayan Iliev
ย 
IPT angular2 typescript SPA 2016
IPT angular2 typescript SPA 2016IPT angular2 typescript SPA 2016
IPT angular2 typescript SPA 2016Trayan Iliev
ย 
Reactive Java Robotics and IoT - IPT Presentation @ Voxxed Days 2016
Reactive Java Robotics and IoT - IPT Presentation @ Voxxed Days 2016Reactive Java Robotics and IoT - IPT Presentation @ Voxxed Days 2016
Reactive Java Robotics and IoT - IPT Presentation @ Voxxed Days 2016Trayan Iliev
ย 

More from Trayan Iliev (20)

Making Machine Learning Easy with H2O and WebFlux
Making Machine Learning Easy with H2O and WebFluxMaking Machine Learning Easy with H2O and WebFlux
Making Machine Learning Easy with H2O and WebFlux
ย 
Rapid Web API development with Kotlin and Ktor
Rapid Web API development with Kotlin and KtorRapid Web API development with Kotlin and Ktor
Rapid Web API development with Kotlin and Ktor
ย 
IPT Reactive Java IoT Demo - BGOUG 2018
IPT Reactive Java IoT Demo - BGOUG 2018IPT Reactive Java IoT Demo - BGOUG 2018
IPT Reactive Java IoT Demo - BGOUG 2018
ย 
Learning Programming Using Robots - Sofia University Conference 2018
Learning Programming Using Robots - Sofia University Conference 2018 Learning Programming Using Robots - Sofia University Conference 2018
Learning Programming Using Robots - Sofia University Conference 2018
ย 
Active Learning Using Connected Things - 2018 (in Bulgarian)
Active Learning Using Connected Things - 2018 (in Bulgarian)Active Learning Using Connected Things - 2018 (in Bulgarian)
Active Learning Using Connected Things - 2018 (in Bulgarian)
ย 
Spring 5 Webflux - Advances in Java 2018
Spring 5 Webflux - Advances in Java 2018Spring 5 Webflux - Advances in Java 2018
Spring 5 Webflux - Advances in Java 2018
ย 
Fog Computing - DEV.BG 2018
Fog Computing - DEV.BG 2018Fog Computing - DEV.BG 2018
Fog Computing - DEV.BG 2018
ย 
Microservices with Spring 5 Webflux - jProfessionals
Microservices  with Spring 5 Webflux - jProfessionalsMicroservices  with Spring 5 Webflux - jProfessionals
Microservices with Spring 5 Webflux - jProfessionals
ย 
Reactive Microservices with Spring 5: WebFlux
Reactive Microservices with Spring 5: WebFlux Reactive Microservices with Spring 5: WebFlux
Reactive Microservices with Spring 5: WebFlux
ย 
What's new in java 9?
What's new in java 9?What's new in java 9?
What's new in java 9?
ย 
NGRX Apps in Depth
NGRX Apps in DepthNGRX Apps in Depth
NGRX Apps in Depth
ย 
Stream Processing with CompletableFuture and Flow in Java 9
Stream Processing with CompletableFuture and Flow in Java 9Stream Processing with CompletableFuture and Flow in Java 9
Stream Processing with CompletableFuture and Flow in Java 9
ย 
Reactive Java Robotics & IoT with Spring Reactor
Reactive Java Robotics & IoT with Spring ReactorReactive Java Robotics & IoT with Spring Reactor
Reactive Java Robotics & IoT with Spring Reactor
ย 
Hackathon: โ€œIPTPI and LeJaRo Meet The Real Worldโ€
Hackathon: โ€œIPTPI and LeJaRo Meet The Real Worldโ€Hackathon: โ€œIPTPI and LeJaRo Meet The Real Worldโ€
Hackathon: โ€œIPTPI and LeJaRo Meet The Real Worldโ€
ย 
Reactive robotics io_t_2017
Reactive robotics io_t_2017Reactive robotics io_t_2017
Reactive robotics io_t_2017
ย 
Java & JavaScipt Reactive Robotics and IoT 2016 @ jProfessionals
Java & JavaScipt Reactive Robotics and IoT 2016 @ jProfessionalsJava & JavaScipt Reactive Robotics and IoT 2016 @ jProfessionals
Java & JavaScipt Reactive Robotics and IoT 2016 @ jProfessionals
ย 
IPT High Performance Reactive Java BGOUG 2016
IPT High Performance Reactive Java BGOUG 2016IPT High Performance Reactive Java BGOUG 2016
IPT High Performance Reactive Java BGOUG 2016
ย 
Reactive Java Robotics IoT - jPrime 2016
Reactive Java Robotics IoT - jPrime 2016Reactive Java Robotics IoT - jPrime 2016
Reactive Java Robotics IoT - jPrime 2016
ย 
IPT angular2 typescript SPA 2016
IPT angular2 typescript SPA 2016IPT angular2 typescript SPA 2016
IPT angular2 typescript SPA 2016
ย 
Reactive Java Robotics and IoT - IPT Presentation @ Voxxed Days 2016
Reactive Java Robotics and IoT - IPT Presentation @ Voxxed Days 2016Reactive Java Robotics and IoT - IPT Presentation @ Voxxed Days 2016
Reactive Java Robotics and IoT - IPT Presentation @ Voxxed Days 2016
ย 

Recently uploaded

Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
ย 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
ย 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
ย 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto Gonzรกlez Trastoy
ย 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
ย 
Russian Call Girls in Karol Bagh Aasnvi โžก๏ธ 8264348440 ๐Ÿ’‹๐Ÿ“ž Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi โžก๏ธ 8264348440 ๐Ÿ’‹๐Ÿ“ž Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi โžก๏ธ 8264348440 ๐Ÿ’‹๐Ÿ“ž Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi โžก๏ธ 8264348440 ๐Ÿ’‹๐Ÿ“ž Independent Escort S...soniya singh
ย 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
ย 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
ย 
(Genuine) Escort Service Lucknow | Starting โ‚น,5K To @25k with A/C ๐Ÿง‘๐Ÿฝโ€โค๏ธโ€๐Ÿง‘๐Ÿป 89...
(Genuine) Escort Service Lucknow | Starting โ‚น,5K To @25k with A/C ๐Ÿง‘๐Ÿฝโ€โค๏ธโ€๐Ÿง‘๐Ÿป 89...(Genuine) Escort Service Lucknow | Starting โ‚น,5K To @25k with A/C ๐Ÿง‘๐Ÿฝโ€โค๏ธโ€๐Ÿง‘๐Ÿป 89...
(Genuine) Escort Service Lucknow | Starting โ‚น,5K To @25k with A/C ๐Ÿง‘๐Ÿฝโ€โค๏ธโ€๐Ÿง‘๐Ÿป 89...gurkirankumar98700
ย 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
ย 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
ย 
Call Girls In Mukherjee Nagar ๐Ÿ“ฑ 9999965857 ๐Ÿคฉ Delhi ๐Ÿซฆ HOT AND SEXY VVIP ๐ŸŽ SE...
Call Girls In Mukherjee Nagar ๐Ÿ“ฑ  9999965857  ๐Ÿคฉ Delhi ๐Ÿซฆ HOT AND SEXY VVIP ๐ŸŽ SE...Call Girls In Mukherjee Nagar ๐Ÿ“ฑ  9999965857  ๐Ÿคฉ Delhi ๐Ÿซฆ HOT AND SEXY VVIP ๐ŸŽ SE...
Call Girls In Mukherjee Nagar ๐Ÿ“ฑ 9999965857 ๐Ÿคฉ Delhi ๐Ÿซฆ HOT AND SEXY VVIP ๐ŸŽ SE...Call Girls In Delhi Whatsup 9873940964 Enjoy Unlimited Pleasure
ย 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyFrank van der Linden
ย 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...aditisharan08
ย 
XpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsXpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsMehedi Hasan Shohan
ย 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
ย 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
ย 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
ย 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
ย 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
ย 

Recently uploaded (20)

Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
ย 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
ย 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
ย 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
ย 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
ย 
Russian Call Girls in Karol Bagh Aasnvi โžก๏ธ 8264348440 ๐Ÿ’‹๐Ÿ“ž Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi โžก๏ธ 8264348440 ๐Ÿ’‹๐Ÿ“ž Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi โžก๏ธ 8264348440 ๐Ÿ’‹๐Ÿ“ž Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi โžก๏ธ 8264348440 ๐Ÿ’‹๐Ÿ“ž Independent Escort S...
ย 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
ย 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
ย 
(Genuine) Escort Service Lucknow | Starting โ‚น,5K To @25k with A/C ๐Ÿง‘๐Ÿฝโ€โค๏ธโ€๐Ÿง‘๐Ÿป 89...
(Genuine) Escort Service Lucknow | Starting โ‚น,5K To @25k with A/C ๐Ÿง‘๐Ÿฝโ€โค๏ธโ€๐Ÿง‘๐Ÿป 89...(Genuine) Escort Service Lucknow | Starting โ‚น,5K To @25k with A/C ๐Ÿง‘๐Ÿฝโ€โค๏ธโ€๐Ÿง‘๐Ÿป 89...
(Genuine) Escort Service Lucknow | Starting โ‚น,5K To @25k with A/C ๐Ÿง‘๐Ÿฝโ€โค๏ธโ€๐Ÿง‘๐Ÿป 89...
ย 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
ย 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
ย 
Call Girls In Mukherjee Nagar ๐Ÿ“ฑ 9999965857 ๐Ÿคฉ Delhi ๐Ÿซฆ HOT AND SEXY VVIP ๐ŸŽ SE...
Call Girls In Mukherjee Nagar ๐Ÿ“ฑ  9999965857  ๐Ÿคฉ Delhi ๐Ÿซฆ HOT AND SEXY VVIP ๐ŸŽ SE...Call Girls In Mukherjee Nagar ๐Ÿ“ฑ  9999965857  ๐Ÿคฉ Delhi ๐Ÿซฆ HOT AND SEXY VVIP ๐ŸŽ SE...
Call Girls In Mukherjee Nagar ๐Ÿ“ฑ 9999965857 ๐Ÿคฉ Delhi ๐Ÿซฆ HOT AND SEXY VVIP ๐ŸŽ SE...
ย 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The Ugly
ย 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...
ย 
XpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsXpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software Solutions
ย 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
ย 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
ย 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
ย 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
ย 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
ย 

React HOCs, Context and Observables

  • 1. Using Context, Higher-Order Components and Observables with React Slide 1Sources:ReactJS [https://github.com/facebook/react/ ] Licensed under the Creative Commons Attribution 4.0 International Public License Sofia May 15, 2017 Context, HOCs & Observables with React Trayan Iliev IPT โ€“ Intellectual Products & Technologies e-mail: tiliev@iproduct.org web: http://www.iproduct.org
  • 2. Using Context, Higher-Order Components and Observables with React Sofia May 15, 2017 Slide 2Sources:ReactJS [https://github.com/facebook/react/ ] Licensed under the Creative Commons Attribution 4.0 International Public License About Us: IPT - Intellectual Products & Technologies Since 2003 we provide trainings and share knowledge in JS/ TypeScript/ Node/ Express/ Socket.IO/ NoSQL/ Angular/ React / Java SE/ EE/ Web/ REST SOA: Node.js + Express/ hapi + React.js + Redux + GraphQL Angular + TypeScript + Redux (ngrx) Java EE6/7, Spring, JSF, Portals/Portlets: Liferay, GateIn Reactive IoT with Reactor / RxJava / RxJS SOA & Distributed Hypermedia APIs (REST) Domain Driven Design & Reactive Microservices
  • 3. Using Context, Higher-Order Components and Observables with React Sofia May 15, 2017 Slide 3Sources:ReactJS [https://github.com/facebook/react/ ] Licensed under the Creative Commons Attribution 4.0 International Public License Where is The Code? React.js demo code is available @GitHub: https://github.com/iproduct/demos-and-presentations Demos: react-router-redux-demo โ€“ React + Redux + Router + Thunk (async actions) integration react-hocs-observables โ€“ React + Redux + Router + RxJS Observables (async action stream transforms) + Reselect + Recompose + Material-UI
  • 4. Using Context, Higher-Order Components and Observables with React Sofia May 15, 2017 Slide 4Sources:ReactJS [https://github.com/facebook/react/ ] Licensed under the Creative Commons Attribution 4.0 International Public License Contemporary Web Applications Provide better User Experience (UX) by: more interactive loading and reacting faster in response (or even anticipation) of user's moves able to work offline supporting multiple devices and screen resolutions (responsive design) are following design metaphors consistently (e.g. Google Material Design - MD) looking more like desktop application than static web page
  • 5. Using Context, Higher-Order Components and Observables with React Sofia May 15, 2017 Slide 5Sources:ReactJS [https://github.com/facebook/react/ ] Licensed under the Creative Commons Attribution 4.0 International Public License MVC Comes in Different Flavors MVC MVVM MVP Sources:https://en.wikipedia.org/wiki/Model_View_ViewModel#/media/File:MVVMPattern.png, https://en.wikipedia.org/wiki/Model %E2%80%93view%E2%80%93presenter#/media/File:Model_View_Presenter_GUI_Design_Pattern.png License: CC BY-SA 3.0, Authors:Ugaya40, Daniel.Cardenas
  • 6. Using Context, Higher-Order Components and Observables with React Sofia May 15, 2017 Slide 6Sources:ReactJS [https://github.com/facebook/react/ ] Licensed under the Creative Commons Attribution 4.0 International Public License Single Page Applications (SPA) Source: http://stackoverflow.com/questions/12863663/complex-nesting-of-partials-and-templates Author: PhillipKregg
  • 7. Using Context, Higher-Order Components and Observables with React Sofia May 15, 2017 Slide 7Sources:ReactJS [https://github.com/facebook/react/ ] Licensed under the Creative Commons Attribution 4.0 International Public License SPA with Multiple Router Outlets
  • 8. Using Context, Higher-Order Components and Observables with React Sofia May 15, 2017 Slide 8Sources:ReactJS [https://github.com/facebook/react/ ] Licensed under the Creative Commons Attribution 4.0 International Public License Why SPA? Page does not flicker โ€“ seamless (or even animated) transitions Less data transferred โ€“ responses are cached Only raw data, not markup Features can be loaded on demand (lazy) or in background Most page processing happens on the client offloading the server: REST data services + snapshops for crawlers (SEO) Code reuse โ€“ REST endopints are general purpose Supporting multiple platforms (Web, iOS, Android) โ†’ React Native
  • 9. Using Context, Higher-Order Components and Observables with React Slide 9Sources:ReactJS [https://github.com/facebook/react/ ] Licensed under the Creative Commons Attribution 4.0 International Public License Sofia May 15, 2017 Developing Sinagle Page Apps (SPA) in 3 steps 1) Setting up a build system โ€“ npm, webpack, gulp are common choices, babel, typescript, JSX, CSS preprocessors (SASS, SCSS, LESS, PostCSS), servers ... 2) Designing front-end architecture components โ€“ views & layouts + view models (presentation data models) + presentation logic (event handling, messaging) + routing paths (essential for SPA) Better to use component model to boost productivity and maintainability. 3) End-to-end application design โ€“ front-end: wireframes โ†’ views, data entities & data streams โ†’ service API and models design, sitemap โ†’ router config
  • 10. Using Context, Higher-Order Components and Observables with React Sofia May 15, 2017 Slide 10Sources:ReactJS [https://github.com/facebook/react/ ] Licensed under the Creative Commons Attribution 4.0 International Public License Components Resuability - Two Approaches Inheritance - we create new component Types (or Classes) by extending exiting ones โ€“ Class Hierachy: Composition: Object composition Functional composition
  • 11. Using Context, Higher-Order Components and Observables with React Sofia May 15, 2017 Slide 11Sources:ReactJS [https://github.com/facebook/react/ ] Licensed under the Creative Commons Attribution 4.0 International Public License Object Composition Hierachy
  • 12. Using Context, Higher-Order Components and Observables with React Sofia May 15, 2017 Slide 12Sources:ReactJS [https://github.com/facebook/react/ ] Licensed under the Creative Commons Attribution 4.0 International Public License Functional Composition Functional programming (FP) - the mathematical notion of function composition Composing functions f and g, g(f(x)) means fโ€™s out โ†’ gโ€™s input In FP, the inputs and outputs are values without life cycles Simpler to understand compared to object compositions If input-output types match, functions can always compose! More sophisticated forms of composition can be implemented using higher-order functions: functions can be passed as inputs and received as outputs to/from other functions Functions are just immutable values โ€“ no special treatment!
  • 13. Using Context, Higher-Order Components and Observables with React Sofia May 15, 2017 Slide 13Sources:ReactJS [https://github.com/facebook/react/ ] Licensed under the Creative Commons Attribution 4.0 International Public License Higher-Order Components Higher-order component (HOC) is a function that takes a component and returns a new component: const EnhancedComponent = higherOrderComponent( WrappedComponent ); Example: const VisibleTodoList = connect(mapStateToProps, mapDispatchToProps) (TodoList);
  • 14. Using Context, Higher-Order Components and Observables with React Sofia May 15, 2017 Slide 14Sources:ReactJS [https://github.com/facebook/react/ ] Licensed under the Creative Commons Attribution 4.0 International Public License Use HOCs For Cross-Cutting Concerns class BlogPost extends React.Component { constructor(props) { super(props); this.handleChange = this.handleChange.bind(this); this.state = { blogPost: DataSource.getBlogPost(props.id) }; } componentDidMount(){DataSource.addChangeListener(this.handleChange);} componentWillUnmount() { DataSource.removeChangeListener(this.handleChange);} handleChange() { this.setState({blogPost: DataSource.getBlogPost(this.props.id)}); } render() { return <TextBlock text={this.state.blogPost} />; } }
  • 15. Using Context, Higher-Order Components and Observables with React Sofia May 15, 2017 Slide 15Sources:ReactJS [https://github.com/facebook/react/ ] Licensed under the Creative Commons Attribution 4.0 International Public License Use HOCs For Cross-Cutting Concerns (2) function withSubscription(WrappedComponent, selectData) { return class extends React.Component { constructor(props) { super(props); this.handleChange = this.handleChange.bind(this); this.state = {data: selectData(DataSource, props) }; } componentDidMount() { DataSource.addChangeListener(this.handleChange); } componentWillUnmount({ DataSource.removeChangeListener(this.handleChange);} handleChange() { this.setState({data: selectData(DataSource, this.props)});} render() { return <WrappedComponent data={this.state.data} {...this.props}/>;} }; } Anonimous class. Name should be added using dispalyName static property
  • 16. Using Context, Higher-Order Components and Observables with React Sofia May 15, 2017 Slide 16Sources:ReactJS [https://github.com/facebook/react/ ] Licensed under the Creative Commons Attribution 4.0 International Public License Usage: const CommentListWithSubscription = withSubscription( CommentList, (DataSource) => DataSource.getComments() ); const BlogPostWithSubscription = withSubscription( BlogPost, (DataSource, props) => DataSource.getBlogPost(props.id) });
  • 17. Using Context, Higher-Order Components and Observables with React Sofia May 15, 2017 Slide 17Sources:ReactJS [https://github.com/facebook/react/ ] Licensed under the Creative Commons Attribution 4.0 International Public License Using HOCs โ€“ Things To Remember: Don't Mutate the Original Component. Use Composition. Convention: Pass Unrelated Props Through to the Wrapped Component Convention: Maximizing Composability const ConnectedComment = connect(commentSelector, commentActions)(Comment); // compose(f, g, h) is the same as (...args) => f(g(h(...args))) const enhance = compose(withRouter, connect(commentSelector, commentActions) ); enhance(Comment); Convention: Wrap the Display Name for Easy Debugging The order matters!
  • 18. Using Context, Higher-Order Components and Observables with React Sofia May 15, 2017 Slide 18Sources:ReactJS [https://github.com/facebook/react/ ] Licensed under the Creative Commons Attribution 4.0 International Public License How to Boost Performance with React Use the production build Avoiding reconciling the DOM โ€“ React provides a component lifecycle function, shouldComponentUpdate, which is triggered before the re-rendering process starts (virtual DOM comparison and possible eventual DOM reconciliation), giving the developer the ability to short circuit this process. Default: shouldComponentUpdate: function(nextProps, nextState) { return true; } React invokes shouldComponentUpdate often -should be fast Use immutability for comparisons to be efficient
  • 19. Using Context, Higher-Order Components and Observables with React Sofia May 15, 2017 Slide 19Sources:ReactJS [https://github.com/facebook/react/ ] Licensed under the Creative Commons Attribution 4.0 International Public License Performance with shouldComponentUpdate class MyStatelessComp extends React.Component { static propTypes = { value: PropTypes.string.isRequired }; shouldComponentUpdate: function(nextProps, nextState) { return this.props.value !== nextProps.value; }, render: function() { return <div>{this.props.value}</div>; } });
  • 20. Using Context, Higher-Order Components and Observables with React Sofia May 15, 2017 Slide 20Sources:ReactJS [https://github.com/facebook/react/ ] Licensed under the Creative Commons Attribution 4.0 International Public License Boosting Performance: PureRenderMixin Before โ€“ using mixins(Mixins Considered Harmful by Dan Abramov): var PureRenderMixin = require('react-addons-pure-render-mixin'); React.createClass({ mixins: [PureRenderMixin], render: function() { return <div className={this.props.className}>foo</div>; } }); Now you should prefer: class MyComponent extends React.PureComponent { โ€ฆ }
  • 21. Using Context, Higher-Order Components and Observables with React Sofia May 15, 2017 Slide 21Sources:ReactJS [https://github.com/facebook/react/ ] Licensed under the Creative Commons Attribution 4.0 International Public License Using HOCs โ€“ Caveats: Don't Use HOCs Inside the render Method: render() { const EnhancedComponent = enhance(MyComponent); return <EnhancedComponent />; } Static Methods Must Be Copied Over Maximizing Composability Refs Aren't Passed Through Don't
  • 22. Using Context, Higher-Order Components and Observables with React Sofia May 15, 2017 Slide 22Sources:ReactJS [https://github.com/facebook/react/ ] Licensed under the Creative Commons Attribution 4.0 International Public License Refs to Components Refs (references) โ€“ allow to find the DOM markup rendered by a component, and invoke methods on component instances returned from render() Example uses: absolute positioning, using React components in larger non-React applications, transition existing code to React. var myComponentInstanceRef = ReactDOM.render(<MyComp />, myContainer); myComponentInstanceRef.doSomething(); ReactDOM.findDOMNode(componentInstance) โ€“ this function will return the DOM node belonging to the outermost HTML element returned by render.
  • 23. Using Context, Higher-Order Components and Observables with React Sofia May 15, 2017 Slide 23Sources:ReactJS [https://github.com/facebook/react/ ] Licensed under the Creative Commons Attribution 4.0 International Public License The ref Callback Attribute render: function() { return ( <TextInput ref={ function(input) { if (input != null) { input.focus(); } }} /> ); }, OR better using ES6 => : render: function() { return <TextInput ref={(c) => this._input = c} />; }, componentDidMount: function() { this._input.focus(); }, Will be called twice โ€“ on mount with ref, and on unmount with null. That is why we check if ref not null.
  • 24. Using Context, Higher-Order Components and Observables with React Sofia May 15, 2017 Slide 24Sources:ReactJS [https://github.com/facebook/react/ ] Licensed under the Creative Commons Attribution 4.0 International Public License Using React Component Context React props allow to track data-flow easy between componets React Context is alternative if you want to pass data through the component tree without having to pass the props down manually at every level. Inversion of Control (IoC) principle and Dependency Injection (DI) pattern React's "context" feature lets you do this โ€“ Example how to inject testService and router in TestsList component: TestsList.contextTypes = { testService: React.PropTypes.object, router: React.PropTypes.object };
  • 25. Using Context, Higher-Order Components and Observables with React Sofia May 15, 2017 Slide 25Sources:ReactJS [https://github.com/facebook/react/ ] Licensed under the Creative Commons Attribution 4.0 International Public License Passing Refs from Wrapped Comp to HOC function Field({ inputRef, ...rest }) { return <input ref={inputRef} {...rest} />; } // Wrap Field in a higher-order component const EnhancedField = enhance(Field); // Inside a class component's render method... <EnhancedField inputRef={(inputEl) => { // This callback gets passed through as a regular prop this.inputEl = inputEl }} /> // Now you can call imperative methods this.inputEl.focus();
  • 26. Using Context, Higher-Order Components and Observables with React Sofia May 15, 2017 Slide 26Sources:ReactJS [https://github.com/facebook/react/ ] Licensed under the Creative Commons Attribution 4.0 International Public License Providing Services with React Context class IPTKnowledgeTester extends React.Component { constructor(props) { super(props); this.testServiceSingleton = new TestService(TEST_SERVICE_URL); this.localeServiceSingleton = new LocaleService(DEFAULT_LOCALE, this.onLocaleChange); } getChildContext() { return { testService: this.testServiceSingleton, localeService: this.localeServiceSingleton }; } โ€ฆ } IPTKnowledgeTester.childContextTypes = { testService: React.PropTypes.object, localeService: React.PropTypes.object };
  • 27. Using Context, Higher-Order Components and Observables with React Sofia May 15, 2017 Slide 27Sources:ReactJS [https://github.com/facebook/react/ ] Licensed under the Creative Commons Attribution 4.0 International Public License React Context Usage Example handleAddTest() { const path = { pathname: '/test', query: { controls: true, edit: true } }; this.context.router.push(path); } componentDidMount() { this.context.testService.getTests().then((tests) => { this.setState({ tests: tests }); }); }
  • 28. Using Context, Higher-Order Components and Observables with React Sofia May 15, 2017 Slide 28Sources:ReactJS [https://github.com/facebook/react/ ] Licensed under the Creative Commons Attribution 4.0 International Public License Referencing Context in Lifecycle Methods void componentWillReceiveProps( object nextProps, object nextContext ) boolean shouldComponentUpdate( object nextProps, object nextState, object nextContext ) void componentWillUpdate( object nextProps, object nextState, object nextContext ) void componentDidUpdate( object prevProps, object prevState, object prevContext )
  • 29. Using Context, Higher-Order Components and Observables with React Sofia May 15, 2017 Slide 29Sources:ReactJS [https://github.com/facebook/react/ ] Licensed under the Creative Commons Attribution 4.0 International Public License Using Context with Functional Components const Button = ({children}, context) => <button style={{background: context.color}}> {children} </button>; Button.contextTypes = {color: React.PropTypes.string};
  • 30. Using Context, Higher-Order Components and Observables with React Sofia May 15, 2017 Slide 30Sources:ReactJS [https://github.com/facebook/react/ ] Licensed under the Creative Commons Attribution 4.0 International Public License React Router v4 Configuration <Route path="/" component={Base} /> <Route path="/home" component={Home} /> <Route path="/intro" render={() => <div>How to start using this app</div>} /> <Route path="/repos" component={Repos} /> <Route path="/topics" component={Topics} /> <Route path="/about" component={About} /> <Route path="/show-location" component={ShowTheLocation} /> const Repos = (props) => { return ( <div> <h2>Repos</h2> <Route path="/repos/:userName/:repoName" component={Repo} /> </div> ); }; Hierarchical navigation, no need to use props.children
  • 31. Using Context, Higher-Order Components and Observables with React Sofia May 15, 2017 Slide 31Sources:ReactJS [https://github.com/facebook/react/ ] Licensed under the Creative Commons Attribution 4.0 International Public License Site Navigation using Router v4 <ul className="main-menu"> <li><Link to="/home">Home</Link></li> <li><Link to="/intro">Intro</Link></li> <li><Link to="/repos">Repos</Link></li> <li><Link to="/topics">Topics</Link></li> <li><Link to="/show-location">Show the Location</Link></li> <li><Link to="/about">About</Link></li> <form className="navbar-form navbar-right" role="search" onSubmit={this.handleSerch}> <input type="text" placeholder="userName" /> / {' '} <input type="text" placeholder="repo" /> {' '} <button type="submit" className="btn btn-default">Go</button> </form> </ul>
  • 32. Using Context, Higher-Order Components and Observables with React Sofia May 15, 2017 Slide 32Sources:ReactJS [https://github.com/facebook/react/ ] Licensed under the Creative Commons Attribution 4.0 International Public License Programmatic Navigation using Router v4 ReactDOM.render( <Router > <App /> </Router>, document.getElementById('root') ); handleSerch = (event) => { event.preventDefault(); const userName = event.target.elements[0].value; const repo = event.target.elements[1].value; const path = `/repos/${userName}/${repo}`; console.log(path); console.log(this.context); // this.context.router.history.push(path); this.props.history.push(path); }
  • 33. Using Context, Higher-Order Components and Observables with React Sofia May 15, 2017 Slide 33Sources:ReactJS [https://github.com/facebook/react/ ] Licensed under the Creative Commons Attribution 4.0 International Public License Using @withRouter Decorator (HOC) - Router v4 import React from 'react'; import PropTypes from 'prop-types'; import { withRouter } from 'react-router-dom'; @withRouter export default class ShowTheLocation extends React.Component { render() { const { match, location, history } = this.props; return ( <div> <div>You are now at {location.pathname}</div> <div>The match is: {JSON.stringify(match)}</div> <div>The history contains: {JSON.stringify(history)}</div> </div> ) } }
  • 34. Using Context, Higher-Order Components and Observables with React Sofia May 15, 2017 Slide 34Sources:ReactJS [https://github.com/facebook/react/ ] Licensed under the Creative Commons Attribution 4.0 International Public License Flux Design Pattern Source: Flux in GitHub, https://github.com/facebook/flux, License: BSD 3-clause "New" License
  • 35. Using Context, Higher-Order Components and Observables with React Sofia May 15, 2017 Slide 35Sources:ReactJS [https://github.com/facebook/react/ ] Licensed under the Creative Commons Attribution 4.0 International Public License Redux Design Pattern Source: @ngrx/store in GitHub, https://gist.github.com/btroncone/a6e4347326749f938510 Linear flow:
  • 36. Using Context, Higher-Order Components and Observables with React Sofia May 15, 2017 Slide 36Sources:ReactJS [https://github.com/facebook/react/ ] Licensed under the Creative Commons Attribution 4.0 International Public License Redux Streamlined state management for React.js applications, inspired by Redux State is a single immutable data structure Actions describe state changes Pure functions called reducers take the previous state and the next action to compute the new state State is kept within single Store, and accessed through sub- state selectors, or as Observable of state changes Components are by default perfomance optimized using the shouldComponentUpdate() โ†’ performant change detection
  • 37. Using Context, Higher-Order Components and Observables with React Sofia May 15, 2017 Slide 37Sources:ReactJS [https://github.com/facebook/react/ ] Licensed under the Creative Commons Attribution 4.0 International Public License Redux Recommended (Basic) Project Structure actions โ€“ action creator factory functions (design pattern Command) assets โ€“ static assets (css images, fonts, etc.) folder components โ€“ simple (dumb) react components โ€“ pure render container โ€“ Redux Store aware (smart) component wrappers reducers โ€“ the only way to advance state: function(OldStoreState, Action) => NewStoreState // = Rx scan() index.js โ€“ bootstraps app providing access to Store for all containers (smart components) using React context
  • 38. Using Context, Higher-Order Components and Observables with React Sofia May 15, 2017 Slide 38Sources:ReactJS [https://github.com/facebook/react/ ] Licensed under the Creative Commons Attribution 4.0 International Public License Bootstrapping Redux App โ€“ index.js import React from 'react'; import ReactDOM from 'react-dom'; import { Provider } from 'react-redux'; import { createStore } from 'redux'; import rootReducer from './reducers'; import { FilteredTodoApp } from './containers/filtered-todo-app'; const store = createStore( rootReducer, window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__() ); const render = (Component) => { ReactDOM.render( <Provider store={store}> <FilteredTodoApp /> </Provider>, document.getElementById('root') ); }; Top level container component Redux store provider
  • 39. Using Context, Higher-Order Components and Observables with React Sofia May 15, 2017 Slide 39Sources:ReactJS [https://github.com/facebook/react/ ] Licensed under the Creative Commons Attribution 4.0 International Public License Redux Action Creators โ€“ /actions/index.js let nextTodoId = 0; export const addTodo = (text) => ({ type: 'ADD_TODO', id: nextTodoId++, text }); export const setVisibilityFilter = (filter) => ({ type: 'SET_VISIBILITY_FILTER', filter }); export const changeStatus = (id, status) => ({ type: 'CHANGE_STATUS', id, status }); ... Action Payload Action Type
  • 40. Using Context, Higher-Order Components and Observables with React Sofia May 15, 2017 Slide 40Sources:ReactJS [https://github.com/facebook/react/ ] Licensed under the Creative Commons Attribution 4.0 International Public License Redux Reducers โ€“ /reducers/todo.js const todoReducer = (state = {}, action) => { switch (action.type) { case 'ADD_TODO': return { id: action.id, text: action.text, status: 'active' }; case 'CHANGE_STATUS': if (state.id !== action.id) { return state; } return Object.assign({}, state, { status: action.status }); default: return state; } };
  • 41. Using Context, Higher-Order Components and Observables with React Sofia May 15, 2017 Slide 41Sources:ReactJS [https://github.com/facebook/react/ ] Licensed under the Creative Commons Attribution 4.0 International Public License Redux Reducers โ€“ /reducers/todos.js const todosReducer = (state = [], action) => { switch (action.type) { case 'ADD_TODO': return [ ...state, todoReducer(undefined, action) ]; case 'CHANGE_STATUS': return state.map(todo => todoReducer(todo, action) ); case 'DELETE_TODOS': return state.filter(todo => todo.status !== action.status ); default: return state; } };
  • 42. Using Context, Higher-Order Components and Observables with React Sofia May 15, 2017 Slide 42Sources:ReactJS [https://github.com/facebook/react/ ] Licensed under the Creative Commons Attribution 4.0 International Public License Redux Root Reducer โ€“ /reducers/index.js import { combineReducers } from 'redux'; import todos from './todos'; import visibilityFilter from './visibilityFilter'; const rootReducer = combineReducers({ todos, visibilityFilter }); export default rootReducer;
  • 43. Using Context, Higher-Order Components and Observables with React Sofia May 15, 2017 Slide 43Sources:ReactJS [https://github.com/facebook/react/ ] Licensed under the Creative Commons Attribution 4.0 International Public License Redux Containers โ€“ /conatiners/visible-todo-list.js const getVisibleTodos = (todos, filter) => todos.filter( todo => filter === 'all' ? true: todo.status === filter); const mapStateToProps = (state) => ({ todos: getVisibleTodos(state.todos, state.visibilityFilter) }); const mapDispatchToProps = (dispatch) => ({ onCompleted: (id) => { dispatch(changeStatus(id, 'completed')); }, onCanceled: (id) => { dispatch(changeStatus(id, 'canceled')); } }); const VisibleTodoList = connect(mapStateToProps, mapDispatchToProps ) (TodoList); export default VisibleTodoList;
  • 44. Using Context, Higher-Order Components and Observables with React Sofia May 15, 2017 Slide 44Sources:ReactJS [https://github.com/facebook/react/ ] Licensed under the Creative Commons Attribution 4.0 International Public License Redux App using ES7 @connect Decorator const getVisibleTodos = (todos, filter) => todos.filter( todo => filter === 'all' ? true: todo.status === filter); const mapStateToProps = (state) => ({ todos: getVisibleTodos(state.todos, state.visibilityFilter) }); const mapDispatchToProps = (dispatch) => ({ onCompleted: (id) => { dispatch(changeStatus(id, 'completed')); }, onCanceled: (id) => { dispatch(changeStatus(id, 'canceled')); } }); @connect(mapStateToProps, mapDispatchToProps) export default class TodoList extends React.Component { constructor(props) { ...
  • 45. Using Context, Higher-Order Components and Observables with React Sofia May 15, 2017 Slide 45Sources:ReactJS [https://github.com/facebook/react/ ] Licensed under the Creative Commons Attribution 4.0 International Public License Using Redux Router Redux and Redux Thunk (1) Idea: history + store (redux) โ†’ react-router-redux โ†’ enhanced history โ†’ react- router import { compose, createStore, combineReducers, applyMiddleware } from 'redux'; import { Provider } from 'react-redux'; import createHistory from 'history/createBrowserHistory'; import { ConnectedRouter, routerReducer, routerMiddleware, push } from 'react-router-redux'; // React Router to Redux integration import thunk from 'redux-thunk'; // Allows using thunks = async actions import reducers from './reducers'; // your reducers here const history = createHistory(); // use browser History API // middleware for intercepting & dispatching navigation & async actions const middleware = [routerMiddleware(history), thunk]; // Enable Redux Devtools const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
  • 46. Using Context, Higher-Order Components and Observables with React Sofia May 15, 2017 Slide 46Sources:ReactJS [https://github.com/facebook/react/ ] Licensed under the Creative Commons Attribution 4.0 International Public License Using Redux Router Redux and Redux Thunk (2) const store = createStore( CombineReducers({ ...reducers, router: routerReducer // Add the reducer to store on `router` key }), /* preloadedState, */ ComposeEnhancers( applyMiddleware(...middleware) )); store.dispatch(push('/repos/react/redux'));//dispatch navigation action ReactDOM.render( <Provider store={store}>//ConnectedRouter use store from the Provider <ConnectedRouter history={history}> <App /> </ConnectedRouter> </Provider>, document.getElementById('root') )
  • 47. Using Context, Higher-Order Components and Observables with React Sofia May 15, 2017 Slide 47Sources:ReactJS [https://github.com/facebook/react/ ] Licensed under the Creative Commons Attribution 4.0 International Public License Redux Thunk Async Actions - /actions/counter.js export function increment(x) { return { type: INCREMENT, amount: x } } export function incrementAsync(x) { return dispatch => //Can invoke sync or async actions with `dispatch` setTimeout(() => { dispatch(increment(x)); }, 2000); } export function incrementIfOdd(x) { return (dispatch, getState) => { const { counter } = getState(); if (counter.number % 2 === 0) return; dispatch(increment(x)); //Can invoke actions conditionally }; }
  • 48. Using Context, Higher-Order Components and Observables with React Sofia May 15, 2017 Slide 48Sources:ReactJS [https://github.com/facebook/react/ ] Licensed under the Creative Commons Attribution 4.0 International Public License Advanced Redux using Middleware Libraries Normalizr โ€“ normalizing and denormalizing data in state, helps to transform nested JSON response structures into a relational DB-like plain entities, referenced by Id in the Redux store. redux-thunk โ€“ in addition to plain actions, Action Creators can now return Thunks โ€“ callback functions of dispatch and getState arguments, allowing to handle async operations like data fetch from REST endpoint and Promise-like composition. redux-promise/ redux-promise-middleware โ€“ thunk alternatives redux-observable โ€“ really powerfull reactive transforms of async action events as RxJS Observables, called Epics: (action$:Observable<Action>, store:Store) => Observable<Action>
  • 49. Using Context, Higher-Order Components and Observables with React Sofia May 15, 2017 Slide 49Sources:ReactJS [https://github.com/facebook/react/ ] Licensed under the Creative Commons Attribution 4.0 International Public License Functional Reactive Programming Functional Reactive Programming (FRP) [Wikipedia]: a programming paradigm for reactive programming (asynchronous dataflow programming) using the building blocks of functional programming (e.g. map, reduce, filter). FRP has been used for programming graphical user interfaces (GUIs), robotics, and music, aiming to simplify these problems by explicitly modeling time. Ex. (RxJS): const Observable = require('rxjs').Observable; Observable.from(['Reactive', 'Extensions', 'JavaScript']) .take(2).map(s => `${s}: on ${new Date()}`) .subscribe(s => console.log(s)); Result: Reactive: on Sat Apr 29 2017 20:00:39 GMT+0300 Extensions: on Sat Apr 29 2017 20:00:39 GMT+0300 Good intro tutorial in RP using RxJS by Andre Staltz see: https://gist.github.com/staltz/868e7e9bc2a7b8c1f754 JS Fiddle of the demo: http://jsfiddle.net/staltz/8jFJH/48/
  • 50. Using Context, Higher-Order Components and Observables with React Sofia May 15, 2017 Slide 50Sources:ReactJS [https://github.com/facebook/react/ ] Licensed under the Creative Commons Attribution 4.0 International Public License Definitions of Reactive Programming Microsoftยฎ opens source polyglot project ReactiveX (Reactive Extensions) [http://reactivex.io]: Rx = Observables + LINQ + Schedulers :) Supported Languages โ€“ Java: RxJava, JavaScript: RxJS, C#: Rx.NET, C#(Unity): UniRx, Scala: RxScala, Clojure: RxClojure, C++: RxCpp, Ruby: Rx.rb, Python: RxPY, Groovy: RxGroovy, JRuby: RxJRuby, Kotlin: RxKotlin, Swift: RxSwift ReactiveX for platforms and frameworks: RxNetty, RxAndroid, RxCocoa Reactive Streams Specification [http://www.reactive-streams.org/]
  • 51. Using Context, Higher-Order Components and Observables with React Sofia May 15, 2017 Slide 51Sources:ReactJS [https://github.com/facebook/react/ ] Licensed under the Creative Commons Attribution 4.0 International Public License RxJS โ€“ JS ReactiveX (Reactive Extensions) [http://reactivex.io, https://github.com/ReactiveX] ReactiveX is a polyglot library for composing asynchronous event streams (observable sequences). It extends the observer pattern by declarative composition of functional transformations on events streams (e.g. map-filter- reduce, etc.) Abstracs away low-level concerns like concurrency, synchronization, and non-blocking I/O. Follows the next - error - completed event flow Allows natural implementation of Redux design pattern Alternative (together with promises) for solving โ€œcallback hellโ€ problem
  • 52. Using Context, Higher-Order Components and Observables with React Sofia May 15, 2017 Slide 52Sources:ReactJS [https://github.com/facebook/react/ ] Licensed under the Creative Commons Attribution 4.0 International Public License Resources: RxMarbles and RxJS Coans RxMarbles: http://rxmarbles.com/ RxJS Coans: https://github.com/Reactive-Extensions/RxJSKoans
  • 53. Using Context, Higher-Order Components and Observables with React Sofia May 15, 2017 Slide 53Sources:ReactJS [https://github.com/facebook/react/ ] Licensed under the Creative Commons Attribution 4.0 International Public License Demo Time :) React.js demo code is available @GitHub: https://github.com/iproduct/demos-and-presentations Demos: react-router-redux-demo โ€“ React + Redux + Router + Thunk (async actions) integration react-hocs-observables โ€“ React + Redux + Router + RxJS Observables (async action stream transforms) + Reselect + Recompose + Material-UI
  • 54. Using Context, Higher-Order Components and Observables with React Sofia May 15, 2017 Slide 54Sources:ReactJS [https://github.com/facebook/react/ ] Licensed under the Creative Commons Attribution 4.0 International Public License Thankโ€™s for Your Attention! Trayan Iliev CEO of IPT โ€“ Intellectual Products & Technologies http://iproduct.org/ http://robolearn.org/ https://github.com/iproduct https://twitter.com/trayaniliev https://www.facebook.com/IPT.EACAD https://plus.google.com/+IproductOrg