robust web apps with react.js

38
@maxmaxmaxmax MAKSYM KLYMYSHYN CTO GVMachines Inc. Robust apps with React.js

Upload: max-klymyshyn

Post on 12-Jul-2015

2.194 views

Category:

Software


1 download

TRANSCRIPT

Page 1: Robust web apps with React.js

@maxmaxmaxmaxMAKSYM KLYMYSHYNCTO GVMachines Inc.

Robust apps with React.js

Page 2: Robust web apps with React.js

TOC

TOC

‣ Typical mistakes

‣ Data flow

‣ React.js basics

‣ Flux

Page 3: Robust web apps with React.js

Typical mistakes

Page 4: Robust web apps with React.js

It’s not about stackTypical mistakes

‣ Most of application have sporadic data flow and tightly coupled components

‣ It’s quite hard to avoid it and meet deadlines simultaneously

‣ Only when you have really well formed team and strong architect

‣ So it’s not about Backbone, Angular or any other frameworks

Page 5: Robust web apps with React.js

It’s all about tightly coupled application components

Page 6: Robust web apps with React.js

Coupled code

Typical mistakes

‣ Easy to write – you do not need to think a lot about design

‣ Good for quick bootstrap because you care only about domain

‣ Not require any deep knowledge about programming science and apps design

Page 7: Robust web apps with React.js

Coupling disadvantages

Typical mistakes

‣ A change in one module usually forces a ripple effect of changes in other modules.

‣ Assembly of modules might require more effort and/or time due to the increased inter-module dependency.

‣ A particular module might be harder to reuse and/or test because dependent modules must be included.

Page 8: Robust web apps with React.js

But…

Typical mistakes

‣ some frameworks designed to provide more ways to communicate between components

‣ So it’s easier to make coupled things

‣ And increase coupling between components

‣ Which increase probability to introduce new bugs during change one of them

Page 9: Robust web apps with React.js

Cohesion

Typical mistakes

‣ Reduce module complexity

‣ Increase system maintainability

‣ Increase module reusability

Page 10: Robust web apps with React.js

I believe, that if framework allow to make coupled things,

they will be coupled.

Page 11: Robust web apps with React.js

Coupling correlates with cohesion and

vice versa

Page 12: Robust web apps with React.js

Data flow

Page 13: Robust web apps with React.js

What’s the deal?

Data flow

‣ Read and write from/to database

‣ Call external API

‣ React on external events

‣ Messages exchange/queues

Page 14: Robust web apps with React.js

It’s all about data flow

Data flow

Page 15: Robust web apps with React.js
Page 16: Robust web apps with React.js

Most of modern applications consist from message queues of

different types and forms.

Data flow

Page 17: Robust web apps with React.js

React.js basics

React.js basics

Page 18: Robust web apps with React.js

A JavaScript library for building UI Wikipedia

React.js basics

Page 19: Robust web apps with React.js

ComponentsWhat’s inside React.js

‣ Object-oriented widgets definition

‣ Nested widgets support

‣ HTML-Like Widget DOM definition (VirtualDOM)

‣ State spreading to nested components - one way reactive data flow

‣ Optimised rendering to the real DOM tree

‣ Two-way data binding helpers

Page 20: Robust web apps with React.js

Widgets definition

What’s inside React.js

Page 21: Robust web apps with React.js

JSX

What’s inside React.js

‣ To simplify Virtual DOM definition added html-subset language called JSX

‣ JSX allow to define Widget DOM piece directly within your JavaScript file

‣ JSX convert for production into raw JavaScript with preprocessor

Page 22: Robust web apps with React.js

Widgets definition

What’s inside React.js

Page 23: Robust web apps with React.js

Nested widgets & state spread

What’s inside React.js

Page 24: Robust web apps with React.js

Virtual DOM

What’s inside React.js

‣ Modification within real DOM tree is very slow

‣ To speed up things created Virtual DOM which consist from lightweight JavaScript objects which represent Widgets DOM tree

‣ When state changed Virtual and real DOM trees are compared and real DOM modified only where it’s required

Page 25: Robust web apps with React.js

What’s inside React.js

Page 26: Robust web apps with React.js

What’s inside React.js

‣ Complexity to compare two trees is O(n^3) complexity

‣ React.js managed to turn O(n^3) problem into linear O(n)

‣ So it’s really fast.

Page 27: Robust web apps with React.js

Virtual DOM

What’s inside React.js

Page 28: Robust web apps with React.js

Simply express how your app should look at any given point in time, and React will automatically manage all UI updates when your underlying data changes.

React.js website

React.js basics

Page 29: Robust web apps with React.js

Flux

FLUX Architecture

Page 30: Robust web apps with React.js

React.js is a JavaScript library for building UI Wikipedia

FLUX

Page 31: Robust web apps with React.js

FLUX is application architecture for building User Interfaces

Flux website

FLUX

Page 32: Robust web apps with React.js

FLUX

Page 33: Robust web apps with React.js

FLUX

FLUX

‣ Data flows in a single direction (cycle)

‣ Dispatcher - hub to manage all data flow

‣ Stores - contain application state and logic

‣ Views - representation of state within Stores, listen to events from depend stores

‣ Actions - dispatcher helper methods

Page 34: Robust web apps with React.js

Store and View

FLUX Store and View

Page 35: Robust web apps with React.js

Events Dependency

FLUX

Page 36: Robust web apps with React.js

Conclusion

Page 37: Robust web apps with React.js

Conclusion

‣ React.js is not about right thing, React.js is all about data flow

‣ You’ll start from pattern which accurately provide abilities to deeply understand flow within your app

‣ It’s easier to not make mistakes within your app architecture

‣ Immutability helpers help you develop !

Page 38: Robust web apps with React.js

Thanks!

React.js

@maxmaxmaxmax