Slide 1

Slide 1 text

ENEMY of STATE the

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

ammeep

Slide 4

Slide 4 text

GitHub

Slide 5

Slide 5 text

State

Slide 6

Slide 6 text

State & events

Slide 7

Slide 7 text

State & events a shit load of

Slide 8

Slide 8 text

as complexity increases our sanity decreases

Slide 9

Slide 9 text

conflated models

Slide 10

Slide 10 text

conflated models views conflated

Slide 11

Slide 11 text

conflated models views state conflated conflated

Slide 12

Slide 12 text

conflated models views state events conflated conflated conflated

Slide 13

Slide 13 text

everything is terrible

Slide 14

Slide 14 text

design http://www.flickr.com/photos/neononac/ patterns

Slide 15

Slide 15 text

ideas

Slide 16

Slide 16 text

mv what ever

Slide 17

Slide 17 text

Server versus client

Slide 18

Slide 18 text

server versus client

Slide 19

Slide 19 text

where the magic happens Models

Slide 20

Slide 20 text

Views presentation of the magic

Slide 21

Slide 21 text

coordination of the magic Controllers

Slide 22

Slide 22 text

Routes interaction with the magic

Slide 23

Slide 23 text

on the server State

Slide 24

Slide 24 text

Stateon the server

Slide 25

Slide 25 text

How do we transition state ?

Slide 26

Slide 26 text

and events Routes address state

Slide 27

Slide 27 text

matches a pattern Router

Slide 28

Slide 28 text

matches a pattern Router has action invoked Controller

Slide 29

Slide 29 text

matches a pattern Router has action invoked Controller look up and update Model

Slide 30

Slide 30 text

matches a pattern Router has action invoked Controller look up and update Model snapshot returned View

Slide 31

Slide 31 text

client server boundary addressable & linear

Slide 32

Slide 32 text

server versus Client

Slide 33

Slide 33 text

STATEFUL CLIENTS no boundaries

Slide 34

Slide 34 text

the state space no boundaries

Slide 35

Slide 35 text

models the state space no boundaries

Slide 36

Slide 36 text

models view state the state space no boundaries

Slide 37

Slide 37 text

models view state the state space no boundaries application state

Slide 38

Slide 38 text

{❴ {❴ state and transitions inside the boundary

Slide 39

Slide 39 text

need decent plans non linear state space because, complicated

Slide 40

Slide 40 text

model view controller stateful presentation patterns

Slide 41

Slide 41 text

routes model view controller stateful presentation patterns

Slide 42

Slide 42 text

whats all this then? routes model view controller stateful presentation patterns

Slide 43

Slide 43 text

addressability we still need

Slide 44

Slide 44 text

play out on the client mv what ever you want to call it how does

Slide 45

Slide 45 text

! ! /** Models **/ Animal = Backbone.Model.extend({}); PartyAnimals = Backbone.Collection.extend({ model: Animal }); ! /** View /Controller / Worlds most poorly named object **/ PartyAnimalView = Backbone.View.extend({ ! template: "#party-animal-template", render: function(){ var html = $(this.template).tmpl(this.collection); $(this.el).html(html);

Slide 46

Slide 46 text

encapsulation breaking

Slide 47

Slide 47 text

! ! AppRouter = Backbone.Router.extend({ ! routes: { '#/party': 'startTheParty', '#/party/uninvite/:animal': 'revokePartyRights' }, revokePartyRights: function(animal){ model = partyAnimalCollection.find(animal); model.destroy(); $("#animal-party").remove(); }, ! startTheParty: function(animal){ var view = new PartyView({ collection : partyAnimalCollection }); partyAnimalCollection.fetch(); view.render(); } ! }); !

Slide 48

Slide 48 text

! ! AppRouter = Backbone.Router.extend({ ! routes: { '#/party': 'startTheParty', '#/party/uninvite/:animal': 'revokePartyRights' }, revokePartyRights: function(animal){ model = partyAnimalCollection.find(animal); model.destroy(); $("#animal-party").remove(); }, ! startTheParty: function(animal){ var view = new PartyView({ collection : partyAnimalCollection }); partyAnimalCollection.fetch(); view.render(); } ! }); !

Slide 49

Slide 49 text

SECOND CLASS citizens

Slide 50

Slide 50 text

rows in a database our models are more than they are rich and interactive

Slide 51

Slide 51 text

Routes are a feature

Slide 52

Slide 52 text

enemy are routes the

Slide 53

Slide 53 text

the enemy over use of routes is

Slide 54

Slide 54 text

shoe horned a web server onto the client

Slide 55

Slide 55 text

address state but never transitions

Slide 56

Slide 56 text

refactor transitions ‘

Slide 57

Slide 57 text

! /** Models **/ Animal = Backbone.Model.extend({}); PartyAnimals = Backbone.Collection.extend({ model: Animal }); ! ! /** View /Controller / Worlds most poorly named object **/ PartyAnimalView = Backbone.View.extend({ ! el: "#animal-party", template: "#party-animal-template",

Slide 58

Slide 58 text

no more unnecessary look ups

Slide 59

Slide 59 text

and the view is in charge

Slide 60

Slide 60 text

addressability is still a key concern

Slide 61

Slide 61 text

embraces events an architecture which

Slide 62

Slide 62 text

models Syncs state, Transition state. Raises events

Slide 63

Slide 63 text

models Syncs state, Transition state. Raises events views Handles model events Handles DOM events

Slide 64

Slide 64 text

models Syncs state, Transition state. Raises events views Handles model events Handles DOM events templates HTML rendered by the view

Slide 65

Slide 65 text

controller Initialises models and views keeps track of their placement within a given container models Syncs state, Transition state. Raises events views Handles model events Handles DOM events templates HTML rendered by the view

Slide 66

Slide 66 text

module A strand alone component

Slide 67

Slide 67 text

The secret to building large apps is never build large apps. Break your application into small pieces. Then, assemble those testable, bite-sized pieces into your big application ” “ Justin Meyer, author JavaScriptMVC

Slide 68

Slide 68 text

Modules

Slide 69

Slide 69 text

never place themselves a modules views on the application shell

Slide 70

Slide 70 text

! Layout Composition

Slide 71

Slide 71 text

! ! ! ! ! var rm = new Marionette.RegionManager(); ! var region = rm.addRegion("foo", “#bar”); ! var regions = rm.addRegions({ mainContent: "#mainContent", sideBar: “#sideBar" }); ! regions.mainContent.show(myView);

Slide 72

Slide 72 text

! ! ! ! ! var composer = new LayoutComposer(); ! var region = composer.addRegion(“mainContent", “#mainContent"); ! var composer = rm.addRegions({ mainContent: "#mainContent", sideBar: “#sideBar" }); ! composer.mainContent.show(suchModule); ! // region.show() function // will supply the module with the el to render to

Slide 73

Slide 73 text

layout composer Initialises models and views keeps track of their placement within a given container module A strand alone component

Slide 74

Slide 74 text

the dispatcher

Slide 75

Slide 75 text

the router

Slide 76

Slide 76 text

! ! ! ! ! ! module.exports = Dispatcher = (function() { ! Dispatcher.extend = Backbone.Model.extend; ! _.extend(Dispatcher.prototype, EventBroker); ! Dispatcher.prototype.previousRoute = null; ! Dispatcher.prototype.currentModules = null; ! Dispatcher.prototype.currentRoute = null; ! Dispatcher.prototype.initialize = function(options) {

Slide 77

Slide 77 text

layout composer Initialises models and views keeps track of their placement within a given container module A strand alone component dispatcher Loads new modules disposes of old

Slide 78

Slide 78 text

layout composer Initialises models and views keeps track of their placement within a given container module A strand alone component dispatcher Loads new modules disposes of old router Mediates address bar events

Slide 79

Slide 79 text

composable and event driven a new design

Slide 80

Slide 80 text

scaling a state space can be really hard work TL;DR

Slide 81

Slide 81 text

especially when we don’t separate concerns TL;DR

Slide 82

Slide 82 text

address states never transitions TL;DR

Slide 83

Slide 83 text

take inspiration and evolve ideas TL;DR

Slide 84

Slide 84 text

dont build servers on the client TL;DR

Slide 85

Slide 85 text

Thank you @ammeep amy.palamounta.in internet related activities: github.com/ammeep ENEMY ofSTATE the chaplinjs.org marionettejs.com