SlideShare a Scribd company logo
Marionette.jsMarionette.js
The Backbone Framework
ahumphreys87
ahumphreys87
Days
JavaScript Architect at Bede Gaming.
JavaScript Game Framework that powers cross
platform Bingo client and Slots games.
Node.js Slots Engine, Chat Server.
Node.js API facade.
Evenings
Core contributor to Marionette.js
Issue triaging, Pull Request reviews.
Bug fixing.
New features!
The Path to JavaScript MV*The Path to JavaScript MV*
Server side rendering
Adding JavaScript.
jQuery.
It's MV* Time!!
Server Side RenderingServer Side Rendering
Markup generated server side.
Styled with CSS.
No animation, fancy image
image sliders or interactivity.
It's all pretty bland.
Something is missing....
Adding JavaScriptAdding JavaScript
Create dynamic content.
Animations.
Asynchronous loading.
Better page load performance.
Example...Example...
var xmlhttp;
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open('POST', 'example.com', true);
xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
document.getElementById("myDiv").innerHTML = xmlhttp.responseText;
}
};
xmlhttp.send('fname=Henry&lname=Ford');
This should be much easier!
Along came jQueryAlong came jQuery
$.ajax({
method: "POST",
url: "http://www.example.com",
data: { fname: "Henry", lname: "Ford" }
})
.done(function(data) {
$("#myDiv").html(data);
});
jQuery saved JavaScript and Front End Development
The jQuery HoleThe jQuery Hole
$('#myDiv')
.append('<div class="link"><a href="javascript:void(0)">Link 1</a></div>')
.append('<div class="link"><a href="javascript:void(0)">Link 1</a></div>')
.append('<button>Close</button>');
Creating markup strings in jQuery is a code smell!
<button id="playGame" data-gameid="game1" data-gamename="Demo Game" data-players="1">
Play
</button>
And then you need data...And then you need data...
$(document).on('click', '#playGame', function() {
var playButton = $(this);
$.ajax({
method: "POST",
url: "http://www.example.com",
data: {
gameId: playButton.data('gameid'),
gameName: playButton.data('gamename'),
players: playButton.data('players')
}
})
.done(function(data) {
console.log('Game Playing');
});
});
This get very messy very quick!This get very messy very quick!
Which way now?Which way now?
Why Backbone?Why Backbone?
Flexible.
Un-opinionated.
Models.
Collections.
Separates data from your view.
Why Marionette?Why Marionette?
Fills Backbone's gaps.
Battle tested in large applications.
Actively maintained.
Vibrant community.
Implements render on some useful
pre defined views.
What gaps does it fill?What gaps does it fill?
Who uses Marionette?Who uses Marionette?
Who maintains?Who maintains?
The core team.
The community.
The CommunityThe Community
Number 1 room in Gitter.
Over 5000 members.
Lots of code examples and help!
https://gitter.im/marionettejs/backbone.marionette
Enough of the fluff - lets goEnough of the fluff - lets go
deep!deep!
Application.
Router.
Modules.
Events (Wreqr/Radio).
Object.
Architecture Layer View Layer
Region.
ItemView.
CollectionView.
CompositeView.
LayoutView.
The View LayerThe View Layer
All views have Backbone.Event baked
in.
This allows us to:
Listen for view events.
Show nested views.
Capture and manipulate during view
lifecycle.
Example time....
var MyView = Marionette.View.extend({
template: '<div>test</div>',
events: {
'click #myButton': 'doSomething'
},
doSomething: function() {
console.log('button clicked');
},
onRender: function() {
console.log('did some data change?');
},
onShow: function() {
console.log('BOOM, I am in the DOM');
},
onDestroy: function() {
console.log('Clean me up');
},
onSwapOut: function() {
console.log('If I gotta leave, I wanna go in style');
},
onSwap: function() {
console.log('Now thats what I call an entrance');
}
});
ItemViewItemView
Extends from the base View.
Ideal for rendering a Backbone.Model.
modelEvents.
var person = new Backbone.Model({
fname: 'Henry',
lname: 'Ford'
});
var MyView = Marionette.ItemView.extend({
template: '{{fname}} {{lname}}',
modelEvents: {
change: 'render'
}
});
myView = new MyView({
model: person
});
myView.render();
<div>Henry Ford</div>
CollectionViewCollectionView
Render a Collection.
Renders a list of ItemViews.
collectionEvents.
childEvents.
Auto update on add/remove/update.
Sorting and Filtering.
Pagination.
Another example...
var Person = Backbone.Model.extend({
defaults: {
fname: 'Andrew',
lname: 'Humphreys'
}
});
var People = Backbone.Collection.extend({
model: Person
});
var people = new People([
{fname: 'Henry', lname: 'Ford', age: 67},
{fname: 'John', lname: 'Smith', age: 25},
{fname: 'Henry', lname: 'Hoover', age: 42}
]);
var MyCollectionView = Marionette.CollectionView.extend({
childView: MyView,
onChildviewDoSomething: function() {
console.log('a childs button was clicked');
}
});
var myCollectionView = new MyCollectionView({
collection: people
});
myCollectionView.render();
<div>Henry Ford</div>
<div>John Smith</div>
<div>Henry Hoover</div>
Is that it????
Add sorting.
Add filtering.
var People = Backbone.Collection.extend({
model: Person,
comparator: 'age'
});
var people = new People([
{fname: 'Henry', lname: 'Ford', age: 67},
{fname: 'John', lname: 'Smith', age: 25},
{fname: 'Henry', lname: 'Hoover', age: 42}
]);
var MyView = Marionette.ItemView.extend({
template: '{{fname}} {{lname}}'
});
var MyCollectionView = Marionette.CollectionView.extend({
childView: MyView,
filter: function (child, index, collection) {
return child.get('fname') === 'Henry';
}
});
var myCollectionView = new MyCollectionView({
collection: people
});
myCollectionView.render();
<div>Henry Hoover</div>
<div>Henry Ford</div>
CompositeViewCompositeView
Renders a collection within a template.
Ideal for tabular data.
Nested lists/Tree views
Time to see it in action...
var People = Backbone.Collection.extend({
model: Person,
comparator: 'age'
});
var people = new People([
{fname: 'Henry', lname: 'Ford', age: 67},
{fname: 'John', lname: 'Smith', age: 25},
{fname: 'Henry', lname: 'Hoover', age: 42}
]);
var MyView = Marionette.ItemView.extend({
tagName: 'tr',
template: '<td>{{fname}}</td><td>{{lname}}</td>'
});
var MyCompositeView = Marionette.CompositeView.extend({
template: '<table><thead><th>Forename</th><th>Surname</th></thead><tbody></tbody></table>',
childView: MyView,
childViewContainer: 'tbody'
filter: function (child, index, collection) {
return child.get('fname') === 'Henry';
}
});
var myCompositeView = new MyCompositeView({
collection: people
});
myCompositeView.render();
<table>
<thead>
<th>Forename</th><th>Surname</th>
</thead>
<tbody>
<tr>
<td>Henry</td><td>Hoover</td>
</tr>
<tr>
<td>Henry</td><td>Ford</td>
</tr>
</tbody>
</table>
LayoutViewLayoutView
The big daddy of all views.
Create complex nested layouts.
Render all in 1 call.
A view with regions.
Yeah, you guessed it - example time...
var MyLayoutView = Marionette.LayoutView.extend({
template: "#layout-template",
regions: {
myRegion: "#some-div",
anotherRegion: ".another-element"
}
});
var MyLayoutView2 = Marionette.LayoutView.extend({
template: "#layout-template2",
regions: {
myRegion: "#some-div2",
anotherRegion: ".another-element"
}
});
var myLayoutView = new MyLayoutView(
onShow: function(){
this.showChildView('myRegion', new MyLayoutView2());
this.showChildView('anotherRegion', new Marionette.View());
}
);
MyApp.getRegion('someRegion').show(myLayoutView);
<div id="some-region">
<!-- LayoutView -->
<div>
<div id="some-div">
<!-- LayoutView 2 -->
<div>
<div id="some-div2"></div>
<div class="another-element"></div>
</div>
</div>
<div class="another-element">
<!-- ItemView -->
<div></div>
</div>
</div>
</div>
Whats so great?Whats so great?
Using this pattern we can infinitely
nest views.
The event bindings on subviews
ensure only views that need to re-
render actually do.
Similar to a CollectionView's children
we can listen for childEvents.
Use as an "app root" view.
Or something smaller!
What does the future hold?What does the future hold?
v3.0.0
LayoutView => ItemView => View.
Views replacing a regions element.
Backbone.Radio.
Backbone.Metal.
Improved Router.
Application lifecycle.
Modules => Sub-apps.
Simple decision making - 2 views:
v3.0.0v3.0.0View
CollectionView
Questions???Questions???

More Related Content

PPTX
Backbone/Marionette recap [2015]
PPTX
Introduction to Backbone.js & Marionette.js
PDF
Make your Backbone Application dance
PDF
Marionette: Building your first app
PPT
Creating the interfaces of the future with the APIs of today
PDF
Enjoy the vue.js
PDF
Angular Directives from Scratch
PDF
Modern frontend development with VueJs
Backbone/Marionette recap [2015]
Introduction to Backbone.js & Marionette.js
Make your Backbone Application dance
Marionette: Building your first app
Creating the interfaces of the future with the APIs of today
Enjoy the vue.js
Angular Directives from Scratch
Modern frontend development with VueJs

What's hot (19)

PDF
Intro to Angular.JS Directives
PDF
The Art of AngularJS in 2015 - Angular Summit 2015
PDF
Building a Startup Stack with AngularJS
PDF
Gitter marionette deck
PDF
HTML5: where flash isn't needed anymore
PDF
Sane Async Patterns
PDF
Angular JS blog tutorial
PPTX
Ext JS Architecture Best Practices - Mitchell Simeons
PDF
Advanced Tips & Tricks for using Angular JS
PDF
Scalable CSS You and Your Back-End Coders Can Love - @CSSConf Asia 2014
PPTX
Web components
PPTX
Intro to AngularJs
PDF
Introduction to VueJS & Vuex
PDF
AngularJS - Overcoming performance issues. Limits.
PPTX
Practical AngularJS
PPTX
JavaScripters Event Oct 22, 2016 · 2:00 PM: Common Mistakes made by Angular D...
PDF
iPhone Appleless Apps
PPTX
Getting the Most Out of jQuery Widgets
PPT
jQuery 1.7 Events
Intro to Angular.JS Directives
The Art of AngularJS in 2015 - Angular Summit 2015
Building a Startup Stack with AngularJS
Gitter marionette deck
HTML5: where flash isn't needed anymore
Sane Async Patterns
Angular JS blog tutorial
Ext JS Architecture Best Practices - Mitchell Simeons
Advanced Tips & Tricks for using Angular JS
Scalable CSS You and Your Back-End Coders Can Love - @CSSConf Asia 2014
Web components
Intro to AngularJs
Introduction to VueJS & Vuex
AngularJS - Overcoming performance issues. Limits.
Practical AngularJS
JavaScripters Event Oct 22, 2016 · 2:00 PM: Common Mistakes made by Angular D...
iPhone Appleless Apps
Getting the Most Out of jQuery Widgets
jQuery 1.7 Events
Ad

Viewers also liked (20)

PDF
introduction to Marionette.js (jscafe14)
PPTX
Binary Studio Academy PRO. JS course. Lecture 4. backbone architecture
PDF
Backbone js in action
PDF
Чик чик и в продакшн: быстрый обзор маленьких библиотек для большого Backbone...
PPTX
Backgrid - A Backbone Plugin
PDF
JavaScript: Past, Present, Future
PDF
Workshop 7: Single Page Applications
PDF
Introduction to Backbone.js
PPT
Backbone.js
PDF
Intro to Backbone.js by Azat Mardanov for General Assembly
PPTX
Backbone And Marionette : Take Over The World
PDF
Introduction to Backbone.js
PDF
AngularJS vs. Ember.js vs. Backbone.js
PDF
Introduction à Marionette
PPTX
MVC & backbone.js
KEY
Beautiful Maintainable ModularJavascript Codebase with RequireJS - HelsinkiJ...
PPTX
Single page application and Framework
PDF
Introduction to Marionette Collective
PDF
Опыт разработки эффективного SPA
PPT
Javascript Frameworks
introduction to Marionette.js (jscafe14)
Binary Studio Academy PRO. JS course. Lecture 4. backbone architecture
Backbone js in action
Чик чик и в продакшн: быстрый обзор маленьких библиотек для большого Backbone...
Backgrid - A Backbone Plugin
JavaScript: Past, Present, Future
Workshop 7: Single Page Applications
Introduction to Backbone.js
Backbone.js
Intro to Backbone.js by Azat Mardanov for General Assembly
Backbone And Marionette : Take Over The World
Introduction to Backbone.js
AngularJS vs. Ember.js vs. Backbone.js
Introduction à Marionette
MVC & backbone.js
Beautiful Maintainable ModularJavascript Codebase with RequireJS - HelsinkiJ...
Single page application and Framework
Introduction to Marionette Collective
Опыт разработки эффективного SPA
Javascript Frameworks
Ad

Similar to Marionette: the Backbone framework (20)

PDF
Th 0230 turbo_chargeyourui-howtomakeyourandroidu_ifastandefficient
PPTX
Big Data for each one of us
PPT
Backbone js
PDF
Intro to HTML5
PDF
EP2016 - Moving Away From Nodejs To A Pure Python Solution For Assets
PPTX
Utility libraries to make your life easier
PPTX
Will your code blend? : Toronto Code Camp 2010 : Barry Gervin
PPTX
Bringing the light to the client with KnockoutJS
PDF
JavaScript para Graficos y Visualizacion de Datos
PDF
JavaScript para Graficos y Visualizacion de Datos - BogotaJS
PPTX
Ext JS Introduction
PPTX
ProTips DroidCon Paris 2013
PDF
Backbone Basics with Examples
PDF
Prototype UI Intro
PDF
Prototype UI
PPTX
A Microsoft Silverlight User Group Starter Kit Made Available for Everyone to...
PDF
The Future of Responsive Design Standards
PPT
Vanjs backbone-powerpoint
PDF
MVC pattern for widgets
PDF
Vaadin 7 CN
Th 0230 turbo_chargeyourui-howtomakeyourandroidu_ifastandefficient
Big Data for each one of us
Backbone js
Intro to HTML5
EP2016 - Moving Away From Nodejs To A Pure Python Solution For Assets
Utility libraries to make your life easier
Will your code blend? : Toronto Code Camp 2010 : Barry Gervin
Bringing the light to the client with KnockoutJS
JavaScript para Graficos y Visualizacion de Datos
JavaScript para Graficos y Visualizacion de Datos - BogotaJS
Ext JS Introduction
ProTips DroidCon Paris 2013
Backbone Basics with Examples
Prototype UI Intro
Prototype UI
A Microsoft Silverlight User Group Starter Kit Made Available for Everyone to...
The Future of Responsive Design Standards
Vanjs backbone-powerpoint
MVC pattern for widgets
Vaadin 7 CN

More from frontendne (7)

PDF
Reacting pragmatically
PDF
Improving your workflow with gulp
PDF
An introduction in to the world of front end automation - frontend ne (02 07-15)
PDF
CSS Pseudo Classes
PDF
CSS Selectors
PDF
Css to-scss
PDF
Speedy, solid, semantic layout with Susy
Reacting pragmatically
Improving your workflow with gulp
An introduction in to the world of front end automation - frontend ne (02 07-15)
CSS Pseudo Classes
CSS Selectors
Css to-scss
Speedy, solid, semantic layout with Susy

Recently uploaded (20)

PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPT
Teaching material agriculture food technology
PDF
Modernizing your data center with Dell and AMD
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Encapsulation theory and applications.pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
NewMind AI Monthly Chronicles - July 2025
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Empathic Computing: Creating Shared Understanding
PDF
Electronic commerce courselecture one. Pdf
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Teaching material agriculture food technology
Modernizing your data center with Dell and AMD
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Review of recent advances in non-invasive hemoglobin estimation
Digital-Transformation-Roadmap-for-Companies.pptx
Encapsulation theory and applications.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Diabetes mellitus diagnosis method based random forest with bat algorithm
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
NewMind AI Monthly Chronicles - July 2025
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Empathic Computing: Creating Shared Understanding
Electronic commerce courselecture one. Pdf
Advanced methodologies resolving dimensionality complications for autism neur...
Agricultural_Statistics_at_a_Glance_2022_0.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?

Marionette: the Backbone framework

  • 2. ahumphreys87 ahumphreys87 Days JavaScript Architect at Bede Gaming. JavaScript Game Framework that powers cross platform Bingo client and Slots games. Node.js Slots Engine, Chat Server. Node.js API facade. Evenings Core contributor to Marionette.js Issue triaging, Pull Request reviews. Bug fixing. New features!
  • 3. The Path to JavaScript MV*The Path to JavaScript MV* Server side rendering Adding JavaScript. jQuery. It's MV* Time!!
  • 4. Server Side RenderingServer Side Rendering Markup generated server side. Styled with CSS. No animation, fancy image image sliders or interactivity. It's all pretty bland. Something is missing....
  • 5. Adding JavaScriptAdding JavaScript Create dynamic content. Animations. Asynchronous loading. Better page load performance.
  • 6. Example...Example... var xmlhttp; if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else { // code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.open('POST', 'example.com', true); xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded'); xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("myDiv").innerHTML = xmlhttp.responseText; } }; xmlhttp.send('fname=Henry&lname=Ford');
  • 7. This should be much easier!
  • 8. Along came jQueryAlong came jQuery $.ajax({ method: "POST", url: "http://www.example.com", data: { fname: "Henry", lname: "Ford" } }) .done(function(data) { $("#myDiv").html(data); }); jQuery saved JavaScript and Front End Development
  • 9. The jQuery HoleThe jQuery Hole $('#myDiv') .append('<div class="link"><a href="javascript:void(0)">Link 1</a></div>') .append('<div class="link"><a href="javascript:void(0)">Link 1</a></div>') .append('<button>Close</button>'); Creating markup strings in jQuery is a code smell!
  • 10. <button id="playGame" data-gameid="game1" data-gamename="Demo Game" data-players="1"> Play </button> And then you need data...And then you need data... $(document).on('click', '#playGame', function() { var playButton = $(this); $.ajax({ method: "POST", url: "http://www.example.com", data: { gameId: playButton.data('gameid'), gameName: playButton.data('gamename'), players: playButton.data('players') } }) .done(function(data) { console.log('Game Playing'); }); });
  • 11. This get very messy very quick!This get very messy very quick!
  • 14. Why Marionette?Why Marionette? Fills Backbone's gaps. Battle tested in large applications. Actively maintained. Vibrant community. Implements render on some useful pre defined views.
  • 15. What gaps does it fill?What gaps does it fill?
  • 16. Who uses Marionette?Who uses Marionette?
  • 17. Who maintains?Who maintains? The core team. The community.
  • 18. The CommunityThe Community Number 1 room in Gitter. Over 5000 members. Lots of code examples and help! https://gitter.im/marionettejs/backbone.marionette
  • 19. Enough of the fluff - lets goEnough of the fluff - lets go deep!deep! Application. Router. Modules. Events (Wreqr/Radio). Object. Architecture Layer View Layer Region. ItemView. CollectionView. CompositeView. LayoutView.
  • 20. The View LayerThe View Layer All views have Backbone.Event baked in. This allows us to: Listen for view events. Show nested views. Capture and manipulate during view lifecycle. Example time....
  • 21. var MyView = Marionette.View.extend({ template: '<div>test</div>', events: { 'click #myButton': 'doSomething' }, doSomething: function() { console.log('button clicked'); }, onRender: function() { console.log('did some data change?'); }, onShow: function() { console.log('BOOM, I am in the DOM'); }, onDestroy: function() { console.log('Clean me up'); }, onSwapOut: function() { console.log('If I gotta leave, I wanna go in style'); }, onSwap: function() { console.log('Now thats what I call an entrance'); } });
  • 22. ItemViewItemView Extends from the base View. Ideal for rendering a Backbone.Model. modelEvents. var person = new Backbone.Model({ fname: 'Henry', lname: 'Ford' }); var MyView = Marionette.ItemView.extend({ template: '{{fname}} {{lname}}', modelEvents: { change: 'render' } }); myView = new MyView({ model: person }); myView.render();
  • 24. CollectionViewCollectionView Render a Collection. Renders a list of ItemViews. collectionEvents. childEvents. Auto update on add/remove/update. Sorting and Filtering. Pagination. Another example...
  • 25. var Person = Backbone.Model.extend({ defaults: { fname: 'Andrew', lname: 'Humphreys' } }); var People = Backbone.Collection.extend({ model: Person }); var people = new People([ {fname: 'Henry', lname: 'Ford', age: 67}, {fname: 'John', lname: 'Smith', age: 25}, {fname: 'Henry', lname: 'Hoover', age: 42} ]); var MyCollectionView = Marionette.CollectionView.extend({ childView: MyView, onChildviewDoSomething: function() { console.log('a childs button was clicked'); } }); var myCollectionView = new MyCollectionView({ collection: people }); myCollectionView.render();
  • 26. <div>Henry Ford</div> <div>John Smith</div> <div>Henry Hoover</div> Is that it???? Add sorting. Add filtering.
  • 27. var People = Backbone.Collection.extend({ model: Person, comparator: 'age' }); var people = new People([ {fname: 'Henry', lname: 'Ford', age: 67}, {fname: 'John', lname: 'Smith', age: 25}, {fname: 'Henry', lname: 'Hoover', age: 42} ]); var MyView = Marionette.ItemView.extend({ template: '{{fname}} {{lname}}' }); var MyCollectionView = Marionette.CollectionView.extend({ childView: MyView, filter: function (child, index, collection) { return child.get('fname') === 'Henry'; } }); var myCollectionView = new MyCollectionView({ collection: people }); myCollectionView.render();
  • 29. CompositeViewCompositeView Renders a collection within a template. Ideal for tabular data. Nested lists/Tree views Time to see it in action...
  • 30. var People = Backbone.Collection.extend({ model: Person, comparator: 'age' }); var people = new People([ {fname: 'Henry', lname: 'Ford', age: 67}, {fname: 'John', lname: 'Smith', age: 25}, {fname: 'Henry', lname: 'Hoover', age: 42} ]); var MyView = Marionette.ItemView.extend({ tagName: 'tr', template: '<td>{{fname}}</td><td>{{lname}}</td>' }); var MyCompositeView = Marionette.CompositeView.extend({ template: '<table><thead><th>Forename</th><th>Surname</th></thead><tbody></tbody></table>', childView: MyView, childViewContainer: 'tbody' filter: function (child, index, collection) { return child.get('fname') === 'Henry'; } }); var myCompositeView = new MyCompositeView({ collection: people }); myCompositeView.render();
  • 32. LayoutViewLayoutView The big daddy of all views. Create complex nested layouts. Render all in 1 call. A view with regions. Yeah, you guessed it - example time...
  • 33. var MyLayoutView = Marionette.LayoutView.extend({ template: "#layout-template", regions: { myRegion: "#some-div", anotherRegion: ".another-element" } }); var MyLayoutView2 = Marionette.LayoutView.extend({ template: "#layout-template2", regions: { myRegion: "#some-div2", anotherRegion: ".another-element" } }); var myLayoutView = new MyLayoutView( onShow: function(){ this.showChildView('myRegion', new MyLayoutView2()); this.showChildView('anotherRegion', new Marionette.View()); } ); MyApp.getRegion('someRegion').show(myLayoutView);
  • 34. <div id="some-region"> <!-- LayoutView --> <div> <div id="some-div"> <!-- LayoutView 2 --> <div> <div id="some-div2"></div> <div class="another-element"></div> </div> </div> <div class="another-element"> <!-- ItemView --> <div></div> </div> </div> </div>
  • 35. Whats so great?Whats so great? Using this pattern we can infinitely nest views. The event bindings on subviews ensure only views that need to re- render actually do. Similar to a CollectionView's children we can listen for childEvents. Use as an "app root" view. Or something smaller!
  • 36. What does the future hold?What does the future hold? v3.0.0 LayoutView => ItemView => View. Views replacing a regions element. Backbone.Radio. Backbone.Metal. Improved Router. Application lifecycle. Modules => Sub-apps. Simple decision making - 2 views: v3.0.0v3.0.0View CollectionView