+ All Categories
Home > Engineering > Marionette talk 2016

Marionette talk 2016

Date post: 16-Apr-2017
Category:
Upload: kseniya-redunova
View: 379 times
Download: 0 times
Share this document with a friend
39
Transcript
Page 1: Marionette talk 2016
Page 2: Marionette talk 2016

MARIONETTESHALL WE DANCE?

Page 3: Marionette talk 2016

KSENIA REDUNOVA

Page 4: Marionette talk 2016

BACKBONE.JSPROS & CONS

Page 5: Marionette talk 2016

• Simple & flexible• Event-driven architecture• Model/Collection implementation for REST• MVW

PROS

Page 6: Marionette talk 2016

• Simple :)• Too easy to go in wrong direction • No main Application class• No nesting of views• No layouts (header/footer/sidebar/content etc) • Method render does nothing by default• Memory management

CONS

Page 7: Marionette talk 2016

MARIONETTEComplex lib intended for large-scale apps development

Page 8: Marionette talk 2016

• Has a bunch of common design patterns• Lowers amount of standard code because of

view types• Has nested views• Manages memory• Combines event-driven architecture and event

aggregator

Page 9: Marionette talk 2016

Marionette.Application

• App management - start, stop, and other functionality

• Modularity• “application” is just an object

Page 10: Marionette talk 2016

MODULEIs deprecated!

use AMD/CommonJS/ES6 modules

Page 11: Marionette talk 2016

MARIONETTE VIEW MAGIC

Page 12: Marionette talk 2016

MARIONETTE VIEW MAGIC• Rendering connected to model changes• Template management• Has UI object• Has .close() method• Extensible

Page 13: Marionette talk 2016

TEMPLATE HELPERS

Page 14: Marionette talk 2016

TEMPLATE HELPERS

Page 15: Marionette talk 2016

Marionette.ItemView• View is rendered based on model data• “model” attribute• “template” attribute• is rendered automatically• modelEvents – view methods are called on

model events

Page 16: Marionette talk 2016

UI OBJECTUI hash in the view maps UI elements by their jQuery selectors

Page 17: Marionette talk 2016

Marionette.CollectionView• View is rendered based on Collection data• Automatic re-render on add/remove/reset/etc

events• childView attribute is automatically

instantiated and linked with model

Page 18: Marionette talk 2016

COLLECTION VIEWS

Page 19: Marionette talk 2016

Marionette.CompositeView

• CompositeView = CollectionView + template• combination of ItemView and CollectionView • renders elements of Backbone.Collection inside

wrapper• inherits Marionette.CollectionView

Page 20: Marionette talk 2016

MODEL EVENTS & COLLECTION EVENTS

Page 21: Marionette talk 2016

ZOMBIE APOCALYPSE

Page 22: Marionette talk 2016
Page 23: Marionette talk 2016

REGION

• View intended to manage the lifecycle of other views• Renders view instance and adds it to DOM• It’s a bridge between DOM and backbone• Nested regions - LayoutView class

Page 24: Marionette talk 2016

DISPLAY A VIEWIN A REGION

Page 25: Marionette talk 2016

LAYOUT

• Unlike ItemView it contains regions• Is good to be a widget with several views

Page 26: Marionette talk 2016

LAYOUT

Page 27: Marionette talk 2016

BACKBONE.WREQR& BACKBONE.RADIO

Page 28: Marionette talk 2016

MESSAGING BUS

• Event - app-level events• Commands - run commands• Request/Response - request of specific

values/states

Page 29: Marionette talk 2016

EVENT AGGREGATOR• pub/sub• trigger/bind• Notifies the app about events in different parts

(“user:logged-in”)• App level events are like global function calls• Different event types, namespaces define the

semantics

Page 30: Marionette talk 2016

EVENT AGGREGATOR

Page 31: Marionette talk 2016

COMMANDSCommands are used to make any component tell another component to perform an action without a direct reference to it.• Subscribe for a command - only once• Example: Save command

• cmd-s• Clicking a toolbar button• Choosing File => Save from the menubar

Page 32: Marionette talk 2016

COMMANDS

Page 33: Marionette talk 2016

REQUEST / RESPONSE• Request Response is a means for any

component to request information from another component without being tightly coupled.

• For app level data (e. g. shopping cart status)• Requests have intention• The requests are 'one-to-one'

Page 34: Marionette talk 2016

REQUEST / RESPONSE

Page 35: Marionette talk 2016

Backbone.Radio.channel

// Get a reference to the channel named 'user'var userChannel = Backbone.Radio.channel('user');

userChannel.on('some:event', function() { console.log('An event has happened!');});

userChannel.reply('some:request', 'food is good');

userChannel.trigger('some:event');

Combination of Backbone.Events and Radio.Requests

Page 36: Marionette talk 2016

SUMMARYMESSAGING BUS

• Application.vent - instance of Backbone.Wreqr.EventAggregator. pub/sub.

• Application.commands - instance of Backbone.Wreqr.Commands. Subscribe to command execution - once

• Application.reqres - instance of Backbone.Wreqr.RequestResponse. Only one subscriber performs the request

• Backbone.Radio.channel

Page 37: Marionette talk 2016

• Child views - Backbone.BabySitter

• Marionette.RegionManager

• Marionette.TemplateCache

OTHER COOL THINGS FORVIEWS MANAGEMENT

Page 38: Marionette talk 2016

LINKSMarionetteJS.com (Derick Bailey)BackboneRails.com (Brian Mann)

“Marionette: gentle introduction” by David Sulchttp://benmccormick.org/2015/01/26/backbone-radio

/

Page 39: Marionette talk 2016

THANK YOU!


Recommended