Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Backbone & Marionette avec @xbourguignon à Soft...
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Philippe CHARRIERE
October 24, 2013
Programming
0
290
Backbone & Marionette avec @xbourguignon à SoftShake
Philippe CHARRIERE
October 24, 2013
Tweet
Share
More Decks by Philippe CHARRIERE
See All by Philippe CHARRIERE
The Plan v3 pour BDX.io
k33g
1
190
Le Plan
k33g
0
200
Prog Fonctionnelle 🐑
k33g
1
380
Apéro fonctionnel
k33g
0
120
Scala Facile
k33g
0
280
Golo, the Tiny Language that gives super powers
k33g
0
120
Golo, the Tiny Language that gives super powers
k33g
0
260
Apéro Fonctionnel
k33g
0
270
Programmation fonctionnelle 🐑 en JS
k33g
2
290
Other Decks in Programming
See All in Programming
なるべく楽してバックエンドに型をつけたい!(楽とは言ってない)
hibiki_cube
0
140
Rust 製のコードエディタ “Zed” を使ってみた
nearme_tech
PRO
0
210
React 19でつくる「気持ちいいUI」- 楽観的UIのすすめ
himorishige
11
7.5k
なぜSQLはAIぽく見えるのか/why does SQL look AI like
florets1
0
480
KIKI_MBSD Cybersecurity Challenges 2025
ikema
0
1.3k
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
610
余白を設計しフロントエンド開発を 加速させる
tsukuha
7
2.1k
コントリビューターによるDenoのすゝめ / Deno Recommendations by a Contributor
petamoriken
0
210
15年続くIoTサービスのSREエンジニアが挑む分散トレーシング導入
melonps
2
230
AIと一緒にレガシーに向き合ってみた
nyafunta9858
0
250
Oxlintはいいぞ
yug1224
5
1.4k
QAフローを最適化し、品質水準を満たしながらリリースまでの期間を最短化する #RSGT2026
shibayu36
2
4.4k
Featured
See All Featured
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
2
3.6k
How STYLIGHT went responsive
nonsquared
100
6k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
128
55k
How to Talk to Developers About Accessibility
jct
2
140
New Earth Scene 8
popppiees
1
1.5k
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
0
1.1k
B2B Lead Gen: Tactics, Traps & Triumph
marketingsoph
0
57
What’s in a name? Adding method to the madness
productmarketing
PRO
24
3.9k
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
1
110
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
1
130
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
Transcript
Backbone & Marionette Xavier Bourguignon Philippe Charrière
About Us @k33g_org Lyon Steria Golo Fan #1 @xbourguignon Genève
Hortis GenevaJUG Leader
Backbone.js @k33g_org / Lyon / Steria “tout nu”
1 librairie MVC par Jeremy Ashkenas jQuery + Underscore tous
navigateurs
1 librairie “extra légère” Backbone : 20 kb jQuery :
84 kb Underscore : 14 kb
BB = SPA Helper
Enorme communauté Nombreux plugins “sérieux”
Très simple Code facile à lire facile à “augmenter”
Backbone, c'est Play!> dans votre navigateur
BB est MVC ?
M♥ VC Backbone.Model Backbone.Collection
MVC Templates <%= something %>
MVC Backbone.View ?!*#!??? “la glue”
MVP Backbone.View model view presenter
Mais aussi Backbone.Sync Backbone.Router ...
Modèle Objet
Un modèle "interne"
Pompage var Kind = function() {}; Kind.extend = Backbone.Model.extend;
klass var TinyToon = Kind.extend({ constructor : function (firstName, lastName){
this.firstName = firstName; this.lastName = lastName; }, toString : function() { return this.firstName + " " +this.lastName } }); var babs = new TinyToon("Babs", "Bunny")
héritage var Elmyra = TinyToon.extend({ constructor : function (){ this.firstName
= "Elmyra"; this.lastName = "Duff"; Elmyra.__super__.constructor.call(this); console.log("Oh, it's so cute ♥ ♥ ♥"); }, isChasing : function(toon) { //foo } });
static var Elmyra = TinyToon.extend({ //instance members },{ //statics members
theOnlyOne : null, getInstance : function() { if(Elmyra.theOnlyOne == null) { Elmyra.theOnlyOne = new Elmyra(); } return Elmyra.theOnlyOne; } }); var elmyra = Elmyra.getInstance();
Backbone.Model Backbone.Collection Backbone.sync
var Player = Backbone.Model.extend({ urlRoot:"/players" }); var bob = new
Player({ firstName : "Bob", lastName : "Morane" }) Model
get() / set() bob.get("firstName") bob.set("firstName","Bob") bob.set({ lastName:"Morane", twitter:"@bobby" }) bob.on(
"change:lastName change:firstName", ...);
mais aussi save() fetch() destroy()
Backbone.sync Appelé à chaque lecture / écriture des modèles
Backbone.sync Par défaut : REST $.ajax()
bob.save() POST : http://domain/players save
var bob = new Player({ id:"001" }) bob.fetch() GET :
http://domain/players/001 fetch
bob.set("twitter","@bobby") bob.save() PUT : http://domain/players/001 save/update
bob.destroy() DELETE : http://domain/players/001 destroy
var Players = Backbone.Collection. extend({ url :"/players", model : Player
}); var players = new Players() Collection
players.fetch() GET : http://domain/players/ fetch : getAll
_.template()
<ol> <% _.each(players, function(player) { %> <li id="<%= player.id %>">
<%= player.firstName %> <%= player.lastName %> </li> <% }); %> </ol> Avec Underscore template
d'autres moteurs Mustache Handelbars TempoJS ...
Backbone.View Controller Presenter
var PlayersView = Backbone.View.extend({ el : "#players", initialize : function()
{ this.template = _.template($("#template").html()); }, render : function() { this.$el.html( this.template({ players:this.collection.toJSON() }) ); } });
var PlayersView = Backbone.View.extend({ /*...*/ events:{ "click :checkbox" : function(event)
{}, "click .btn-success" : function() {} } }); var playersView = new PlayersView({collection:players})
Backbone.Router
var router = Backbone.Router.extend({ routes: { "home": "index", "products/:computer": "display",
"products/:computer/:model": "display" }, index: function() { }, display: function(computer, model) { } });
1 Exemple simple 1 “blog”
Vue
Vue Modèles & Collections
Vue Modèles & Collections Contrôleur
Vue Modèles & Collections Contrôleur Go!
\o/
Plus loin: -> + commentaires
None
None
None
None
None
None
nouvelle version
Donc pas mal de code en plus, et ce n’est
pas fini ...
Memory leaks
None
None
None
Conclusion
BB != machine à tout faire
Marionette.js @xbourguigon / Genève / Hortis Make your Backbone application
dance !
1 librairie par Derick Bailey Pour aller encore plus loin
avec Backbone
Marionette = SPA with BB Helper
ItemView
MyItemView = Marionette.ItemView.extend({ template:"#my-view-template" }); var myView = new MyItemView({
model: someBBModel });
CollectionView
ItemsView = Marionette.CollectionView.extend({ itemView:MyItemView }); var myCollectionView = new ItemsView({
collection: someBBCollection });
Region
var mainRegion = new Marionette.Region({ el:"#main-container" }); var view =
new MyView(); mainRegion.show(view); var otherView = new AnotherView(); mainRegion.show(otherView);
Layout
(wrapper template) #someRegion #anotherRegion
var MyLayout = Marionette.Layout.extend({ template:"#my-layout-template", regions:{ region1:"#someRegion", region2:"#anotherRegion" } });
var layout = new MyLayout(); mainRegion.show(layout); layout.region1.show(new SomeView()); layout.region2.show(new OtherView());
Autres raffinements pour les vues
var itemView = new MyView({model: someModel}); itemView.render(); var collectionView =
newOtherView({ collection: someCollection }); collectionView.render(); automatic render
mainRegion.show(layout); layout.region1.show(new SomeView()); layout.region2.show(new OtherView()); layout.region1.show(new ThirdView()); mainRegion.show(anotherLayout); zombie killing
var myView = Marionette.ItemView.extend({ template:"#my-view-template", ui:{ mainButton: "#mainButton" }, clickButton:
function() { this.ui.mainButton.click(); } }); ui objects
var myView = Marionette.ItemView.extend({ template:"#my-view-template", modelEvents:{ "change:name":"doThing" }, doThing: function()
{ // call when the name changes ! } }); model events
var myView = Marionette.CollectionView.extend({ template:"#my-view-template", collectionEvents:{ "add":"itemAdded" }, itemAdded: function()
{ // call when the name changes ! } }); collection events
Marionette === scalable BB
None
App Sub-App Sub-App Sub-App
Découpage en modules
Application
(function(global) { var MyApp = new Marionette.Application(); MyApp.addRegions({ mainRegion:"#main" });
MyApp.on("initialize.after", function() { Backbone.history.start(); }) global.MyApp = MyApp; })(window)
<script src="/js/app.js" /> <script src="/js/itemView.js" /> <script> $(function(){ MyApp.start(); });
</script>
Module
MyApp.module("myModule", function(Mod, App, BB, Marionette, $, ...) { var SomeModel
= Backbone.Model.extend({...}); var ItemView = Marionette.ItemView.extend ({...}); var model = new SomeModel(); ...
… Mod.initializer(function() { var promise = model.fetch(); $.when(promise).then(function(){ var view
= new SomeView(); MyApp.mainRegion.show(view); }); }); });
MyApp.module("SubApp", function() { this.startWithParent = false; this.addInitializer(function() {...}) } MyApp.module("SubApp").start();
MyApp.module("myModule").stop(); start / stop
Controller
WTF ?
Mediator All purpose object Public API for component controller
var ThatThing = Marionette.Controller.extend({ doStuff: function() { ... } });
Blog Marionette version
Questions ?
On a plus le temps :-(
Merci
@k33g_org @xbourguignon