+ All Categories
Home > Documents > REACT - inovex€¦ · React Facts > Library (NOT a framework) > Is only the view-part of the...

REACT - inovex€¦ · React Facts > Library (NOT a framework) > Is only the view-part of the...

Date post: 22-May-2020
Category:
Upload: others
View: 4 times
Download: 0 times
Share this document with a friend
40
CONCEPTS OF REACT
Transcript
Page 1: REACT - inovex€¦ · React Facts > Library (NOT a framework) > Is only the view-part of the application > Open source > Developed (and used) by facebook

CONCEPTS OF REACT

Page 2: REACT - inovex€¦ · React Facts > Library (NOT a framework) > Is only the view-part of the application > Open source > Developed (and used) by facebook

Johannes Reuter

Master student HS Karlsruhe

&

Student employee @ inovex lab

[email protected]

evaluation of new (web-)technologies

Page 3: REACT - inovex€¦ · React Facts > Library (NOT a framework) > Is only the view-part of the application > Open source > Developed (and used) by facebook

React Facts

> Library (NOT a framework)

> Is only the view-part of the application

> Open source

> Developed (and used) by facebook

Page 4: REACT - inovex€¦ · React Facts > Library (NOT a framework) > Is only the view-part of the application > Open source > Developed (and used) by facebook

Coming from layers...

Structure (HTML)

Appearance (CSS)

Behavior (JS)

Page 5: REACT - inovex€¦ · React Facts > Library (NOT a framework) > Is only the view-part of the application > Open source > Developed (and used) by facebook

Component

...to components

JS + JSX

Component Component

...

separation of concerns

APIAPI API

JS + JSX JS + JSX

Page 6: REACT - inovex€¦ · React Facts > Library (NOT a framework) > Is only the view-part of the application > Open source > Developed (and used) by facebook
Page 7: REACT - inovex€¦ · React Facts > Library (NOT a framework) > Is only the view-part of the application > Open source > Developed (and used) by facebook

Hierarchical structuring DATA

Page 8: REACT - inovex€¦ · React Facts > Library (NOT a framework) > Is only the view-part of the application > Open source > Developed (and used) by facebook

App state vs. UI-state

DATA a.k.a. app state

UI-state

Page 9: REACT - inovex€¦ · React Facts > Library (NOT a framework) > Is only the view-part of the application > Open source > Developed (and used) by facebook

On new data

> Complete re-evaluation

> Comparison of result to displayed components

> Calculation of minimal set of changes

> Execution of changes

JS (fast)

DOM (slow)

Page 10: REACT - inovex€¦ · React Facts > Library (NOT a framework) > Is only the view-part of the application > Open source > Developed (and used) by facebook

How to define Components?

Page 11: REACT - inovex€¦ · React Facts > Library (NOT a framework) > Is only the view-part of the application > Open source > Developed (and used) by facebook

Example Todo-App

Page 12: REACT - inovex€¦ · React Facts > Library (NOT a framework) > Is only the view-part of the application > Open source > Developed (and used) by facebook

0. Data modelling{

“todos”: [{

“name”: “Eat”,“completed”: false

},{

“name”: “Pray”,“completed”: false

},{

“name”: “Love”,“completed”: false

},]

}

Page 13: REACT - inovex€¦ · React Facts > Library (NOT a framework) > Is only the view-part of the application > Open source > Developed (and used) by facebook

1. Separate

Page 14: REACT - inovex€¦ · React Facts > Library (NOT a framework) > Is only the view-part of the application > Open source > Developed (and used) by facebook

Header

List

Footer

Page 15: REACT - inovex€¦ · React Facts > Library (NOT a framework) > Is only the view-part of the application > Open source > Developed (and used) by facebook

2. Define and connect

Page 16: REACT - inovex€¦ · React Facts > Library (NOT a framework) > Is only the view-part of the application > Open source > Developed (and used) by facebook

TodoApp

Header List Footer

todos todos.length

data selectively passed down

onFilterChange

Page 17: REACT - inovex€¦ · React Facts > Library (NOT a framework) > Is only the view-part of the application > Open source > Developed (and used) by facebook

3. Zoom in

Page 18: REACT - inovex€¦ · React Facts > Library (NOT a framework) > Is only the view-part of the application > Open source > Developed (and used) by facebook

Count-label Visibility radio buttons

Page 19: REACT - inovex€¦ · React Facts > Library (NOT a framework) > Is only the view-part of the application > Open source > Developed (and used) by facebook

4. Repeat

Page 20: REACT - inovex€¦ · React Facts > Library (NOT a framework) > Is only the view-part of the application > Open source > Developed (and used) by facebook

TodoApp

Header List Footer

InputCheckbox ListItem CountLabel RadioButton

DATA

Checkbox Label

Page 21: REACT - inovex€¦ · React Facts > Library (NOT a framework) > Is only the view-part of the application > Open source > Developed (and used) by facebook

The bigger picture

DATA

how does this part work?

Page 22: REACT - inovex€¦ · React Facts > Library (NOT a framework) > Is only the view-part of the application > Open source > Developed (and used) by facebook

React leverages reactive programming

> Modelling of data-flow

> Data-changes are propagated automatically

+ No need to synchronize model <-> view (data-binding)

Page 23: REACT - inovex€¦ · React Facts > Library (NOT a framework) > Is only the view-part of the application > Open source > Developed (and used) by facebook

On application level (Excel)

Page 24: REACT - inovex€¦ · React Facts > Library (NOT a framework) > Is only the view-part of the application > Open source > Developed (and used) by facebook

On code level (RxJS)

const subscription = todos

.filter(todo => !todo.completed)

.count()

.subscribe(

count => console.log(`There are ${count} uncompleted todos`),

err => console.log(`Something went wrong: ${err.message}`);

);

functional programming

Page 25: REACT - inovex€¦ · React Facts > Library (NOT a framework) > Is only the view-part of the application > Open source > Developed (and used) by facebook

On architecture level (Angular 1)

http://tutorials.jenkov.com/images/angularjs/angularjs-critique-3.png

Data Service

Scope

ViewValidator

Controller

Page 26: REACT - inovex€¦ · React Facts > Library (NOT a framework) > Is only the view-part of the application > Open source > Developed (and used) by facebook

Problem: Loops in the flow

Error: [$rootScope:infdig] 10 $digest() iterations reached.

Aborting!

Watchers fired in the last 5 iterations: []

http://errors.angularjs.org/1.4.3/$rootScope/infdig?p0=10&p1=%

at angular.js:68

...

450 Questions on Stackoverflow

Page 27: REACT - inovex€¦ · React Facts > Library (NOT a framework) > Is only the view-part of the application > Open source > Developed (and used) by facebook

Something changes something changes something...

Page 28: REACT - inovex€¦ · React Facts > Library (NOT a framework) > Is only the view-part of the application > Open source > Developed (and used) by facebook

Solution:Unidirectional dataflow

Page 29: REACT - inovex€¦ · React Facts > Library (NOT a framework) > Is only the view-part of the application > Open source > Developed (and used) by facebook

App-state is managed in centralized place

Page 30: REACT - inovex€¦ · React Facts > Library (NOT a framework) > Is only the view-part of the application > Open source > Developed (and used) by facebook

Action

https://facebook.github.io/flux/docs/overview.html

StoreDispatcher

Action

View

Flux

StoreStore

ViewView

on user input

on async event

app state

Page 31: REACT - inovex€¦ · React Facts > Library (NOT a framework) > Is only the view-part of the application > Open source > Developed (and used) by facebook

State

http://staltz.com/unidirectional-user-interface-architectures.html

Alternative (Redux)

Reducer I

Action

View

Reducer II

Reducer xView

View

...

on user input

Page 32: REACT - inovex€¦ · React Facts > Library (NOT a framework) > Is only the view-part of the application > Open source > Developed (and used) by facebook

https://medium.com/@AdamRNeary/unidirectional-data-flow-yes-flux-i-am-not-so-sure-b4acf988196c

Alternative

Event Stream (Server side)

View Aggregated Database-View

push

Action

on user input

Page 33: REACT - inovex€¦ · React Facts > Library (NOT a framework) > Is only the view-part of the application > Open source > Developed (and used) by facebook

And much, much more

> Cerebral www.cerebraljs.com/

> NuclearJS optimizely.github.io/nuclear-js/

> Alt alt.js.org/

> FluxThis www.fluxthis.io/

> Microcosm github.com/vigetlabs/microcosm

> ...

Page 34: REACT - inovex€¦ · React Facts > Library (NOT a framework) > Is only the view-part of the application > Open source > Developed (and used) by facebook

Integration in existing architectures

> Serverside rendering + glue code

> BackboneJS

> ...

Page 35: REACT - inovex€¦ · React Facts > Library (NOT a framework) > Is only the view-part of the application > Open source > Developed (and used) by facebook

http://winterbe.com/posts/2015/08/24/integrate-reactjs-into-jquery-webapps/

Serverside rendering + glue code

Server

jQuery

DOM

HTML

$(...).html(response);

Event

AJAX

Templating Engine

Page 36: REACT - inovex€¦ · React Facts > Library (NOT a framework) > Is only the view-part of the application > Open source > Developed (and used) by facebook

http://winterbe.com/posts/2015/08/24/integrate-reactjs-into-jquery-webapps/

Server

React

DOM

JSON

React.render(...);

Event

AJAX

json_encode

Serverside rendering + glue code

Page 37: REACT - inovex€¦ · React Facts > Library (NOT a framework) > Is only the view-part of the application > Open source > Developed (and used) by facebook

https://blog.engineyard.com/2015/integrating-react-with-backbone

BackboneJS

react.backbone

> Auto-rerenders on model/collection-change

> Place react components into backbone views

Backbone Model

Backbone View

React Component

on*-Event

Page 38: REACT - inovex€¦ · React Facts > Library (NOT a framework) > Is only the view-part of the application > Open source > Developed (and used) by facebook

Angular

DON’T> Already has a view-engine in place

> Big JS-files even for small apps

> Boilerplate-code

Page 39: REACT - inovex€¦ · React Facts > Library (NOT a framework) > Is only the view-part of the application > Open source > Developed (and used) by facebook

Upshot

> Hierarchical components defined by interfaces

> Data is passed selectively top to bottom

> Complete re-evaluation on each action

> Unidirectional data flow

> Centralized place for storage of app-state

Page 40: REACT - inovex€¦ · React Facts > Library (NOT a framework) > Is only the view-part of the application > Open source > Developed (and used) by facebook

Questions?

inovexperts.de

blog.inovex.de

@inovexGmbH

#inovexmeetup


Recommended