Flux

25
FLUX

Transcript of Flux

Page 1: Flux

FLUX

Page 2: Flux

What’s FLUX?

• application architecture for building user interface

• created by Facebook

• very useful for React.js as it uses immutable data structures

Page 3: Flux

But first… MVC recap

Page 4: Flux

MVC Diagram

Source http://fluxxor.com/what-is-flux.html

Page 5: Flux

TodoMVC as an example app

Page 6: Flux

MVC - Step by step

Page 7: Flux

MVC - Step by step

Page 8: Flux

MVC - Step by step

Page 9: Flux

MVC in React.js

• React.js doesn’t need very granular „change:*” events since it rerenders the whole app

• It’s better to prepare all the data and then notify the view layer

• React.js prefers immutable data for the best performance

Page 10: Flux

FLUX Diagram

Source http://fluxxor.com/what-is-flux.html

Page 11: Flux

MVC Diagram once again

Source http://fluxxor.com/what-is-flux.html

Page 12: Flux

FLUX - Step by step

Page 13: Flux

FLUX - Step by step

Page 14: Flux

FLUX - Step by step

Page 15: Flux

FLUX - Step by step

Page 16: Flux

FLUX - Diagram

Source http://fluxxor.com/what-is-flux.html

Page 17: Flux

FLUX - more scalable

Source http://fluxxor.com/what-is-flux.html

Page 18: Flux

MVC - „is not so scalable”*

Image source http://fluxxor.com/what-is-flux.html * According to http://www.infoq.com/news/2014/05/facebook-mvc-flux

Page 19: Flux

FLUX - additional concepts

• No cascading actions - AppDispatcher forbids to call 2 actions at the same time (!!!)

• It’s possible to define the order of Store handlers

• Might be hard - depends on implementation

• Application is extensible out of the box (AppDispatcher)

Page 20: Flux

FLUX - Antipatterns?

• Store as a singleton?

• AppDispatcher as a singleton?

• View has an AppDispatcher as a dependency?

• View has Store as a dependency?

Page 21: Flux

FLUX - is not an antipattern

• FLUX is just an architecture

• Singletons could be easly removed by introducing additional layers

Page 22: Flux

FLUX - Frameworks

• Fluxxor - http://fluxxor.com/

• Delorean - http://deloreanjs.com/

• Dispatcher - https://github.com/facebook/flux

• and many more… created each day…

Page 23: Flux

Is it worth to use?

Page 24: Flux

YES!Or at least some parts of it…

Page 25: Flux

Worth to use

• Dispatcher

• Extensibility

• Unambiguous events

• Actions