Slide 1

Slide 1 text

Marionette Getting the most out Backbone.js @th3hunt

Slide 2

Slide 2 text

Backbone.js • models with key-value binding and custom events • collections with a rich API of enumerable functions • views with declarative event handling • connects to your existing API over a RESTful JSON interface.

Slide 3

Slide 3 text

Backbone Rocks but is NOT a complete framework

Slide 4

Slide 4 text

it works on a Micro Level

Slide 5

Slide 5 text

Let’s see why

Slide 6

Slide 6 text

View • el //div.character • ‘click .kill’: ‘kill’ • kill: function () {…} Model { name: Ned surname: Stark } • urlRoot: ‘/characters’ Template {{name}} {{surname}} kill ~ part of a Collection

Slide 7

Slide 7 text

1 collection of 3 models behind 3 views Component Level

Slide 8

Slide 8 text

But what about…

Slide 9

Slide 9 text

Component B Component C Component D Sub Component A Sub Component A Sub Component A Component A

Slide 10

Slide 10 text

Coarse grained Views?

Slide 11

Slide 11 text

Then we did nothing View’s EL becomes our new DOM root

Slide 12

Slide 12 text

Each component also a View?

Slide 13

Slide 13 text

30,000 feet view

Slide 14

Slide 14 text

– Me :) “It would be like a town with beautiful apartments and terrible street planning”

Slide 15

Slide 15 text

and there is more to it

Slide 16

Slide 16 text

bootstrapping a new project you find yourself in front of a blank slate

Slide 17

Slide 17 text

day one

Slide 18

Slide 18 text

Application Structure Initialize / Shutdown Componentization Messaging Files Layout

Slide 19

Slide 19 text

28 days later

Slide 20

Slide 20 text

Boilerplate Nesting Views Swapping Views Collaboration of Components Enforcing Sensible Defaults Factoring out Practices

Slide 21

Slide 21 text

3 months later

Slide 22

Slide 22 text

Component Sharing Memory Leaks Performance Events Mayhem

Slide 23

Slide 23 text

6 months later

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

build scalable Backbone.js applications by Derick Bailey

Slide 26

Slide 26 text

Application Structure

Slide 27

Slide 27 text

App Sub-App Sub-App Sub-App Sub-App

Slide 28

Slide 28 text

Marionette.Application Module Module Module Module View | Module | Mediator Component Level

Slide 29

Slide 29 text

Components

Slide 30

Slide 30 text

Infrastructure

Slide 31

Slide 31 text

Marionette.Application

Slide 32

Slide 32 text

swap views initialization event bus

Slide 33

Slide 33 text

Marionette.Module

Slide 34

Slide 34 text

encapsulation initialization shutdown

Slide 35

Slide 35 text

–Phil Karlton “There are only two hard things in Computer Science: cache invalidation and naming things”

Slide 36

Slide 36 text

Marionette.Controller A general purpose object for controlling modules, routers, views and implementing a mediator pattern / public API for components

Slide 37

Slide 37 text

initialization shutdown Public API

Slide 38

Slide 38 text

View Management

Slide 39

Slide 39 text

View ItemView Collection View Composite View Layout

Slide 40

Slide 40 text

Backbone.View

Slide 41

Slide 41 text

boilerplate boilerplate

Slide 42

Slide 42 text

Marionette.ItemView

Slide 43

Slide 43 text

declarative Boilerplate Gone !

Slide 44

Slide 44 text

Marionette.CollectionView

Slide 45

Slide 45 text

ItemView CollectionView ItemView ItemView ItemView ItemView

Slide 46

Slide 46 text

sensible defaults

Slide 47

Slide 47 text

Marionette.CompositeView

Slide 48

Slide 48 text

CompositeView ItemView ItemView ItemView … …

Slide 49

Slide 49 text

Marionette.Layout

Slide 50

Slide 50 text

#logo #navigation #header #main Composite Another Layout Item Collection

Slide 51

Slide 51 text

Events / Messaging

Slide 52

Slide 52 text

Events ! On/Trigger Commands ! Handle/Execute Requests ! Handle/Request

Slide 53

Slide 53 text

Files Layout

Slide 54

Slide 54 text

componentization guides our files layout

Slide 55

Slide 55 text

Rails Style

Slide 56

Slide 56 text

No content

Slide 57

Slide 57 text

Domain Based

Slide 58

Slide 58 text

No content

Slide 59

Slide 59 text

Packages

Slide 60

Slide 60 text

No content

Slide 61

Slide 61 text

An Experiment

Slide 62

Slide 62 text

Marionette + Postal.js Replace EventAggregator with Postal

Slide 63

Slide 63 text

Questions ?

Slide 64

Slide 64 text

No content

Slide 65

Slide 65 text

Stratos Pavlakis! [email protected] th3hunt References! ! http://backbonejs.org/ https://github.com/marionettejs/backbone.marionette http://lostechies.com/derickbailey/2011/11/18/is-there-an-idiomatic-command-pattern-implementation-for-javascript/ http://lostechies.com/derickbailey/2012/04/03/revisiting-the-backbone-event-aggregator-lessons-learned/ https://github.com/addyosmani/backbone-fundamentals