Slide 1

Slide 1 text

No content

Slide 2

Slide 2 text

Pedro Nauck FRONTEND DEVELOPER @pedronauck pedronauck.com

Slide 3

Slide 3 text

why we choose MVC?

Slide 4

Slide 4 text

at all times…

Slide 5

Slide 5 text

Because we want to achieve

Slide 6

Slide 6 text

scalability performance adaptability maintainability decoupling }We want

Slide 7

Slide 7 text

App Architecture

Slide 8

Slide 8 text

MVC Controller View Model

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

Tim B. Lee 1991

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

Backend Rulez!

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

what is flux?

Slide 17

Slide 17 text

by

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

Action Dispatcher Store View just a simple model

Slide 20

Slide 20 text

Uniderectional DataFlow

Slide 21

Slide 21 text

focused on client-side APPS

Slide 22

Slide 22 text

Because we want to achieve

Slide 23

Slide 23 text

scalability performance adaptability maintainability decoupling }We want

Slide 24

Slide 24 text

what isn't flux?

Slide 25

Slide 25 text

Framework Library or

Slide 26

Slide 26 text

Action Dispatcher Store View

Slide 27

Slide 27 text

“ The dispatcher is the central hub that manages all data flow in a Flux application. It is essentially a registry of callbacks into the stores and has no real intelligence of its own — it is a simple mechanism for distributing the actions to the stores. Dispatcher http://facebook.github.io/flux

Slide 28

Slide 28 text

✓ Central hub of your app ✓ Only one dispatcher per application ✓ Manage data based on named actions ✓ Simple way to apply on your app ✓ Register callback to the stores Dispatcher

Slide 29

Slide 29 text

Store All actions are registered on the dispatcher, receives some payload, then are sent to a specific store. Dispatcher Callbacks Store Action Action

Slide 30

Slide 30 text

var Dispatcher = require('flux').Dispatcher; Dispatcher just a simple library

Slide 31

Slide 31 text

The dispatcher exposes a method that allows us to trigger a dispatch to the stores, and to include a payload of data, which we call an action. Actions http://facebook.github.io/flux

Slide 32

Slide 32 text

Actions var AppDispatcher = require(‘flux').Dispatcher; var Action = { createItem: function(text) { AppDispatcher.dispatch({ type: 'ADD_ITEM', data: { text: text } }) } }; creating your action

Slide 33

Slide 33 text

Actions var AppDispatcher = require(‘flux').Dispatcher; var Action = { createItem: function(text) { AppDispatcher.dispatch({ type: 'ADD_ITEM', data: { text: text } }) } }; creating your action require dispatcher

Slide 34

Slide 34 text

Actions var AppDispatcher = require(‘flux').Dispatcher; var Action = { createItem: function(text) { AppDispatcher.dispatch({ type: 'ADD_ITEM', data: { text: text } }) } }; creating your action

Slide 35

Slide 35 text

Actions var AppDispatcher = require(‘flux').Dispatcher; var Action = { createItem: function(text) { AppDispatcher.dispatch({ type: 'ADD_ITEM', data: { text: text } }) } }; creating your action dispatch your action

Slide 36

Slide 36 text

Action Dispatcher When the user handle some action, the view triggers an action to the dispatcher View View triggers

Slide 37

Slide 37 text

Stores contain the application state and logic. Their role is somewhat similar to a model in a traditional MVC, but they manage the state of many objects — they do not represent a single record of data like ORM models do. Nor are they the same as Backbone's collections. More than simply managing a collection of ORM-style objects Stores “ http://facebook.github.io/flux

Slide 38

Slide 38 text

✓ Just a simple object-literal ✓ Contain the application state and logic ✓ Public interface: getters, no setter ✓ Setup: register with the dispatcher ✓ Emits a change event ✓ Receives data through a payload Stores

Slide 39

Slide 39 text

Payload Store Store receives new data in the form a payload, that is just a object literal registered on the dispatcher. Dispatcher Payloads

Slide 40

Slide 40 text

var _data = []; var Store = { getAll: function(){ return { data: _data }; } }; Stores receiving data

Slide 41

Slide 41 text

var _data = []; var Store = { getAll: function(){ return { data: _data }; } }; Stores receiving data

Slide 42

Slide 42 text

var _data = []; var Store = { getAll: function(){ return { data: _data }; } }; Stores receiving data

Slide 43

Slide 43 text

var _data = []; var Store = { getAll: function(){ return { data: _data }; } }; Stores private data receiving data

Slide 44

Slide 44 text

dispatcherIndex: AppDispatcher.register(function(payload) { switch(payload.type) { case 'ADD_ITEM': _data.push(payload.data); break; case 'REMOVE_ITEM': // logic to remove data break; } }) Stores registering on the dispatcher

Slide 45

Slide 45 text

dispatcherIndex: AppDispatcher.register(function(payload) { switch(payload.type) { case 'ADD_ITEM': _data.push(payload.data); break; case 'REMOVE_ITEM': // logic to remove data break; } }) Stores registering on the dispatcher

Slide 46

Slide 46 text

dispatcherIndex: AppDispatcher.register(function(payload) { switch(payload.type) { case 'ADD_ITEM': _data.push(payload.data); break; case 'REMOVE_ITEM': // logic to remove data break; } }) Stores registering on the dispatcher

Slide 47

Slide 47 text

dispatcherIndex: AppDispatcher.register(function(payload) { switch(payload.type) { case 'ADD_ITEM': _data.push(payload.data); break; case 'REMOVE_ITEM': // logic to remove data break; } }) Stores registering on the dispatcher

Slide 48

Slide 48 text

dispatcherIndex: AppDispatcher.register(function(payload) { switch(payload.type) { case 'ADD_ITEM': _data.push(payload.data); break; case 'REMOVE_ITEM': // logic to remove data break; } }) Stores registering on the dispatcher

Slide 49

Slide 49 text

View A view is updated when the store emit some change event. Store change event Updating Views

Slide 50

Slide 50 text

Stores based on events addChangeListener: function(callback) { this.on('change', callback); }, removeChangeListener: function(callback) { this.removeListener('change', callback); }, emitChange: function() { this.emit('change'); }

Slide 51

Slide 51 text

Stores based on events addChangeListener: function(callback) { this.on('change', callback); }, removeChangeListener: function(callback) { this.removeListener('change', callback); }, emitChange: function() { this.emit('change'); }

Slide 52

Slide 52 text

Stores based on events addChangeListener: function(callback) { this.on('change', callback); }, removeChangeListener: function(callback) { this.removeListener('change', callback); }, emitChange: function() { this.emit('change'); }

Slide 53

Slide 53 text

Stores based on events addChangeListener: function(callback) { this.on('change', callback); }, removeChangeListener: function(callback) { this.removeListener('change', callback); }, emitChange: function() { this.emit('change'); }

Slide 54

Slide 54 text

dispatcherIndex: AppDispatcher.register(function(payload) { switch(payload.type) { case 'ADD_ITEM': _data.push(payload.data); this.emitChange(); break; case 'REMOVE_ITEM': // logic to remove data break; } }) Stores registering on the dispatcher

Slide 55

Slide 55 text

dispatcherIndex: AppDispatcher.register(function(payload) { switch(payload.type) { case 'ADD_ITEM': _data.push(payload.data); this.emitChange(); break; case 'REMOVE_ITEM': // logic to remove data break; } }) Stores registering on the dispatcher emit change to the view

Slide 56

Slide 56 text

Fetching How fetch data from remote source Asynchronous

Slide 57

Slide 57 text

Action Dispatcher Store View

Slide 58

Slide 58 text

Action Dispatcher Store View Server Fetch Action SEARCH_ITEMS SEARCH_ITEMS_SUCCESS

Slide 59

Slide 59 text

var ItemsAPI = require('./ItemsApi'); var AppDispatcher = require('flux').Dispatcher; var Action = { searchItems: function(query) { AppDispatcher.dispatch({ type: 'SEARCH_ITEMS' }); ItemsApi.search(query).done(function(data) { AppDispatcher.dispatch({ type: 'SEARCH_ITEMS_SUCCESS', data: data }); }); } }; Actions fetching data from remote

Slide 60

Slide 60 text

var ItemsAPI = require('./ItemsApi'); var AppDispatcher = require('flux').Dispatcher; var Action = { searchItems: function(query) { AppDispatcher.dispatch({ type: 'SEARCH_ITEMS' }); ItemsApi.search(query).done(function(data) { AppDispatcher.dispatch({ type: 'SEARCH_ITEMS_SUCCESS', data: data }); }); } }; Actions fetching data from remote

Slide 61

Slide 61 text

var ItemsAPI = require('./ItemsApi'); var AppDispatcher = require('flux').Dispatcher; var Action = { searchItems: function(query) { AppDispatcher.dispatch({ type: 'SEARCH_ITEMS' }); ItemsApi.search(query).done(function(data) { AppDispatcher.dispatch({ type: 'SEARCH_ITEMS_SUCCESS', data: data }); }); } }; Actions fetching data from remote

Slide 62

Slide 62 text

var ItemsAPI = require('./ItemsApi'); var AppDispatcher = require('flux').Dispatcher; var Action = { searchItems: function(query) { AppDispatcher.dispatch({ type: 'SEARCH_ITEMS' }); ItemsApi.search(query).done(function(data) { AppDispatcher.dispatch({ type: 'SEARCH_ITEMS_SUCCESS', data: data }); }); } }; Actions fetching data from remote

Slide 63

Slide 63 text

var ItemsAPI = require('./ItemsApi'); var AppDispatcher = require('flux').Dispatcher; var Action = { searchItems: function(query) { AppDispatcher.dispatch({ type: 'SEARCH_ITEMS' }); ItemsApi.search(query).done(function(data) { AppDispatcher.dispatch({ type: 'SEARCH_ITEMS_SUCCESS', data: data }); }); } }; Actions fetching data from remote

Slide 64

Slide 64 text

var ItemsAPI = require('./ItemsApi'); var AppDispatcher = require('flux').Dispatcher; var Action = { searchItems: function(query) { AppDispatcher.dispatch({ type: 'SEARCH_ITEMS' }); ItemsApi.search(query).done(function(data) { AppDispatcher.dispatch({ type: 'SEARCH_ITEMS_SUCCESS', data: data }); }); } }; Actions fetching data from remote

Slide 65

Slide 65 text

Demo https:/ /github.com/facebook/flux/tree/master/examples/flux-todomvc/

Slide 66

Slide 66 text

That's a lot of code, no?

Slide 67

Slide 67 text

No content

Slide 68

Slide 68 text

No content

Slide 69

Slide 69 text

No content

Slide 70

Slide 70 text

No content

Slide 71

Slide 71 text

http://macgyvermartins.com.br/como-funciona-a-arquitetura-flux-com-react/ Learn more about https://reactjsnews.com/the-state-of-flux/ http://blog.andrewray.me/flux-for-stupid-people/ http://facebook.github.io/flux/docs/overview.html#content

Slide 72

Slide 72 text

No content

Slide 73

Slide 73 text

https:/ /www.youtube.com/watch?v=KtmjkCuV-EU ReactJS Conf 2015

Slide 74

Slide 74 text

https:/ /www.youtube.com/watch?v=i__969noyAM Facebook engineers

Slide 75

Slide 75 text

https:/ /www.youtube.com/watch?v=LTj4O7WJJ98 Flux Panel

Slide 76

Slide 76 text

I hope you enjoyed

Slide 77

Slide 77 text

Pedro Nauck FRONTEND DEVELOPER @pedronauck pedronauck.com

Slide 78

Slide 78 text

Questions?