-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
721 lines (644 loc) · 25.9 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=1024" />
<title>Backbone introduction</title>
<!--<link href="http://fonts.googleapis.com/css?family=Open+Sans:regular,semibold,italic,italicsemibold|PT+Sans:400,700,400italic,700italic|PT+Serif:400,700,400italic,700italic" rel="stylesheet" />-->
<link href="css/backbone-pres.css" rel="stylesheet" />
<link rel="shortcut icon" href="favicon.png" />
<link href="css/shCore.css" rel="stylesheet" />
<link href="css/shCoreDefault.css" rel="stylesheet" />
<link href="css/shThemeDefault.css" rel="stylesheet" />
<script type="text/template" id="item-template">
<div class="view">
<input class="toggle" type="checkbox" <%= done ? 'checked="checked"' : '' %> />
<label><%= title %></label>
<a class="destroy">remove</a>
</div>
<input class="edit" type="text" value="<%= title %>" />
</script>
</head>
<body class="impress-not-supported">
<div class="fallback-message">
<p>Your browser <b>doesn't support the features required</b> by impress.js, so you are presented with a simplified version of this presentation.</p>
<p>For the best experience please use the latest <b>Chrome</b>, <b>Safari</b> or <b>Firefox</b> browser.</p>
</div>
<div id="impress">
<div id="overview" class="step slide invisible" data-x="5000" data-y="4000" data-scale="13">
</div>
<div id="landing" class="step slide" data-x="0" data-y="0">
<h1>Introduction to <a href="http://documentcloud.github.com/backbone/"><img src="backbone.png" alt="Backbone" /></a></h1>
</div>
<div id="sopragroup" class="step slide" data-x="1000" data-y="0">
<header>introduction</header>
<h1><img src="sopragroup.png" alt="Sopra Group" /></h1>
</div>
<div id="introduction-problem" class="step slide" data-x="2000" data-y="0">
<header>introduction</header>
<h2>The problem</h2>
<pre class="brush: html">
<div id="user123">
My name is
<span class="name">Foo</span>.
See my
<a
href="/user/123"
onclick="loadUserProfile(123);">
full profile
</a>.
</div>
</pre>
</div>
<div id="introduction-solution" class="step slide" data-x="3000" data-y="0">
<header>introduction</header>
<h2>One solution</h2>
<ul>
<li>Model:
<pre class="brush: js">
var user = { name: "foo", age: 54 }
</pre>
</li>
<li>View:
<pre class="brush: html">
<span>#{user.name}</span>
</pre>
</li>
<li>Controller:
<pre class="brush: js">
router.routes = { "user/:id": "user" }
router.on("route:user", function(id) {
// Display user
});
</pre>
</li>
</ul>
</div>
<div id="grounds-underscore" class="step slide" data-x="0" data-y="1000">
<header>dependencies</header>
<h2>JS plumbing: <a href="http://documentcloud.github.com/underscore/">Underscore</a></h2>
<pre class="brush: js">
// Collections and arrays
_.map({one: 1, two: 2}, function(num, key){
return num * 3;
});
_.union([1, 2, 3], [101, 2, 1, 10]);
// Functions
var f = _.memoize(function(n) {
return n < 2 ? n : f(n - 1) + f(n - 2);
});
// Objects
_.keys({one : 1, two : 2, three : 3});
</pre>
</div>
<div id="grounds-jquery" class="step slide" data-x="1000" data-y="1000">
<header>dependencies</header>
<h2>DOM plumbing: <a href="http://jquery.com/">jQuery</a> (or <a href="http://zeptojs.com/">Zepto</a>)</h2>
<pre class="brush: js">
// Selector
var t = $("#target")
// CSS
t.addClass("myClass yourClass");
// Events
t.click(function() { alert("Click!"); });
// AJAX
$.get('ajax/test.html', function(data) {
t.html(data);
});
</pre>
</div>
<div id="concepts-model-def" class="step slide" data-x="0" data-y="2000">
<header>concepts</header>
<h2>Model - definition</h2>
<pre class="brush: js; highlight: [1]" id="UserDefinition">
var User = Backbone.Model.extend({
// No definition of properties
// Default values
defaults: { age: 12 },
// Custom methods
addChild: function(u) {
alert(JSON.stringify(u.toJSON()));
}
});
</pre>
</div>
<div id="concepts-model-use" class="step slide" data-x="1000" data-y="2000">
<header>concepts</header>
<h2>Model - usage</h2>
<pre class="runnable brush: js; highlight: [5,8,14]" data-imports="UserDefinition">
// Create
var u = new User({ id: 123, name: 'Foo' });
// Read
alert(u.id);
alert(u.get('name'));
alert(u.has('name'));
// Write
u.set('name', 'Bar');
u.set({ name: 'Baz', age: 45 });
// Clean
u.unset('name');
u.clear();
// Methods
u.addChild(new User({ name: 'Bar' }));
</pre>
</div>
<div id="concepts-model-validation" class="step slide" data-x="2000" data-y="2000">
<header>concepts</header>
<h2>Model - validation</h2>
<pre class="runnable brush: js; highlight: [2,3,4,9,13]">
var User = Backbone.Model.extend({
validate: function(attrs) {
if (attrs.age < 0) {
return "Incorrect age"; }
}
});
var u = new User();
// General
u.on("error", function(m, e) { alert(e) });
u.set({ age: -123 });
// One shot
u.set({ age: -123 }, {
error: function(m, e) {
alert(e.toUpperCase()); }
});
</pre>
</div>
<div id="concepts-collection" class="step slide" data-x="3000" data-y="2000">
<header>concepts</header>
<h2>Collection - definition</h2>
<pre class="brush: js; highlight: [2]">
var UserList = Backbone.Collection.extend({
model: User
});
var users = new UserList([/* ... */]);
users.add(new User({ id: 123 });
var = users.create({ id: 456 });
users.get(456) == users.at(1);
users.remove(users.at(0));
// Underscore methods
var f = users.filter(function(user) {
return user.get('age') > 50;
});
</pre>
</div>
<div id="concepts-collection-ordered" class="step slide" data-x="4000" data-y="2000">
<header>concepts</header>
<h2>Collection - ordered</h2>
<pre class="brush: js; highlight: [4,5,6]">
var Players = Backbone.Collection.extend({
model: Player,
// Can also be a two-args comparator
comparator: function(player) {
return (- player.get('score'));
}
});
// Insert at correct place
players.add(new Player({ score: 5 }));
// Manually re-sort if model changes
players.at(0).set('score', 6);
players.sort();
</pre>
</div>
<div id="concepts-sync-model" class="step slide" data-x="5000" data-y="2000">
<header>concepts</header>
<h2>Sync - model</h2>
<pre class="runnable brush: js">
var User = Backbone.Model.extend({
urlRoot: '/api/users'
});
var u = new User({ name: 'Foo' });
u.save();// POST (new)
u = new User({ id: 123 });
u.fetch();// GET
u.save();// PUT (exists)
u.destroy(); // DELETE
</pre>
</div>
<div id="concepts-sync-collection" class="step slide" data-x="6000" data-y="2000">
<header>concepts</header>
<h2>Sync - collection</h2>
<pre class="runnable brush: js">
var Users = Backbone.Collection.extend({
// Can be a method!
url: '/api/user'
});
var u = new Users();
u.fetch();// GET all models in a JSON array
// Collection is used to build urls
u.add({ id: 678 })
alert(u.at(0).url());
</pre>
</div>
<div id="concepts-event" class="step slide" data-x="7000" data-y="2000">
<header>concepts</header>
<h2>Event</h2>
<pre class="brush: js">
user.on('change:score', /* ... */);
user.on('change', this.sort, this);
// Do not forget to cleanup!
user.off('change:score');
user.off(null, this.sort);
user.off(null, null, this);
user.trigger('custom', 'bar', 123);
// No events!
user.set({ name: 'Foo'}, { silent: true });
</pre>
</div>
<div id="concepts-view-render" class="step slide" data-x="8000" data-y="2000">
<header>concepts</header>
<h2>View</h2>
<pre class="brush: js">
var UserView = Backbone.View.extend({
tagName: 'li',
events: { 'click .edit': 'openEdit' },
render: function() {
this.$el.text(this.model.get('name'));
return this;
}
});
var v = new UserView({
model: new User()
});
$('#users').append(v.render().$el);
v.remove();
</pre>
</div>
<div id="concepts-view-events" class="step slide" data-x="9000" data-y="2000">
<header>concepts</header>
<h2>View - listen to your model</h2>
<pre class="runnable brush: js; highlight: [3,4]" data-imports="UserDefinition">
var UserView = Backbone.View.extend({
initialize: function() {
this.model.on('change',
this.onChange, this);
},
onChange: function() {
alert('want to render UI again?');
}
});
var v = new UserView({
model: new User()
});
v.model.set('name', 'Foo');
</pre>
</div>
<div id="concepts-router" class="step slide" data-x="10000" data-y="2000">
<header>concepts</header>
<h2>Router</h2>
<pre class="brush: js; highlight: [2, 11, 14]">
var Workspace = Backbone.Router.extend({
routes: {
'help/:topic': 'help',
'search/*tokens': 'search'
},
help: function(topic) { /* ... */ },
search: function(tokens) { /* ... */ }
});
var w = new Workspace();
w.navigate('help/foo', { trigger: true });
Backbone.history.start({
pushState: true
});
</pre>
</div>
<div id="realuse-collectioninmodel" class="step slide" data-x="0" data-y="3000">
<header>in practice</header>
<h2><a href="http://backbonejs.org/#FAQ-nested">Collection as Model property</a></h2>
<pre class="brush: js">
var Mailbox = Backbone.Model.extend({
initialize: function() {
this.messages = new Messages;
this.messages.url = '/mailbox/'
+ this.id + '/messages';
this.messages.on("reset",
this.updateCounts);
},
/* ... */
});
var Inbox = new Mailbox;
Inbox.messages.fetch();
</pre>
<ul>
<li>Set and get does not work well (events)</li>
<li>Too simplistic? => plugins!</li>
</ul>
</div>
<div id="realuse-requirejs" class="step slide" data-x="1000" data-y="3000">
<header>in practice</header>
<h2><a href="https://github.com/jrburke/requirejs/wiki/Upgrading-to-RequireJS-2.0#wiki-shim">RequireJS 2.0</a></h2>
<pre class="brush: js highlight: [2]">
requirejs.config({
shim: {
'backbone': {
// Load those before Backbone
deps: ['underscore', 'jquery'],
// Use the global value
exports: 'Backbone'
},
}
});
</pre>
</div>
<div id="limitations-verbose" class="step slide" data-x="2000" data-y="3000">
<header>in practice</header>
<h2>Limitations</h2>
<ul>
<li>Verbose!</li>
<li>Microframework: more to do, but you're running free</li>
<li>Properties are listed by String so hard to refactor</li>
</ul>
</div>
<div id="limitations-onecollection" class="step slide" data-x="3000" data-y="3000">
<header>in practice</header>
<h2>Collection/Model relation</h2>
<pre class="runnable brush: js; highlight: [4,6,10,12]">
var m = new Backbone.Model({ id: 123 });
var Some = Backbone.Collection.extend({
url: '/some'
});
var s = new Some([m]);
alert(s.at(0).url());
var Others = Backbone.Collection.extend({
url: '/others'
});
var o = new Others([m]);
alert(o.at(0).url());
</pre>
</div>
<div id="sampleapp-model" class="step slide" data-x="0" data-y="4000">
<header>sample application</header>
<h2><a href="http://backbonejs.org/#examples-todos">Todo model</a></h2>
<pre id="TodoModel" class="brush: js">
var Todo = Backbone.Model.extend({
defaults: function() {
return {
title: "empty todo...",
order: Todos.nextOrder(),
done: false
};
},
toggle: function() {
this.save({done: !this.get("done")});
},
clear: function() {
this.destroy();
},
sync: LocalStorageSync
});
</pre>
</div>
<div id="sampleapp-list" class="step slide" data-x="1000" data-y="4000">
<header>sample application</header>
<h2><a href="http://backbonejs.org/#examples-todos">Todo collection</a></h2>
<pre id="TodoList" data-imports="TodoModel" class="brush: js">
var TodoList = Backbone.Collection.extend({
model: Todo,
nextOrder: function() {
if (!this.length) return 1;
return this.last().get('order') + 1;
},
comparator: function(todo) {
return todo.get('order');
},
localStorage: new Store("todos"),
sync: LocalStorageSync
});
var Todos = new TodoList;
</pre>
</div>
<div id="sampleapp-view" class="step slide" data-x="2000" data-y="4000">
<header>sample application</header>
<h2><a href="http://backbonejs.org/#examples-todos">Todo item view</a></h2>
<div class="small">
<pre id="TodoView" data-imports="TodoList" class="brush: js">
var TodoView = Backbone.View.extend({
tagName: "li",
template: _.template($('#item-template').html()),
events: {
"click .toggle" : "toggleDone",
"click a.destroy" : "clear",
},
initialize: function() {
this.model.bind('change', this.render, this);
this.model.bind('destroy', this.remove, this);
},
render: function() {
this.$el.html(this.template(this.model.toJSON()));
this.$el.toggleClass('done', this.model.get('done'));
return this;
},
toggleDone: function() { this.model.toggle(); },
clear: function() { this.model.clear(); }
});
</pre>
</div>
</div>
<div id="sampleapp-template" class="step slide" data-x="3000" data-y="4000">
<header>sample application</header>
<h2><a href="http://backbonejs.org/#examples-todos">Todo item view template</a></h2>
<pre id="TodoTemplate" class="brush: html">
<script type="text/template"
id="item-template">
<div class="view">
<input
class="toggle"
type="checkbox"
<%= done?'checked="checked"':'' %>
/>
<label><%= title %></label>
<a class="destroy"></a>
</div>
<input
class="edit"
type="text"
value="<%= title %>"
/>
</script>
</pre>
</div>
<div id="sampleapp-app" class="step slide" data-x="4000" data-y="4000">
<header>sample application</header>
<h2><a href="http://backbonejs.org/#examples-todos">Todo Application</a></h2>
<div class="small">
<pre id="TodoApp" data-imports="TodoView" class="brush: js">
var AppView = Backbone.View.extend({
events: {
"keypress #new-todo": "createOnEnter",
"click #clearall": "clearAll",
},
initialize: function() {
this.input = this.$("#new-todo");
Todos.bind('add', this.addOne, this);
Todos.bind('reset', function() { Todos.each(this.addOne); }, this);
Todos.fetch();
},
addOne: function(todo) {
var view = new TodoView({model: todo});
this.$("#todo-list").append(view.render().el);
},
createOnEnter: function(e) {
if (e.keyCode != 13 || !this.input.val()) return;
Todos.create({title: this.input.val()});
this.input.val('');
},
clearAll: function() {
_.each(Todos.filter(function() { return true; }),
function(todo){ todo.clear(); });
return false;
},
});
</pre>
</div>
</div>
<div id="sampleapp-running" class="step slide" data-x="5000" data-y="4000">
<header>sample application</header>
<h2><a href="http://backbonejs.org/#examples-todos">Todo Running</a></h2>
<pre id="TodoRunning" data-imports="TodoApp" class="runnable brush: js">
var App = new AppView({el: $("#todoapp")});
</pre>
<div id="todoapp">
<input id="new-todo" type="text" placeholder="What needs to be done?">
<ul id="todo-list"></ul>
<a id="clearall">Clear!</a>
</div>
</div>
<div id="competitors-spine" class="step slide" data-x="0" data-y="5000">
<header>competitors</header>
<h2><a href="http://spinejs.com/docs/classes">Spine</a></h2>
<pre class="brush: js">
var Contact = Spine.Model.sub();
Contact.configure("Contact",
"name", "email");
Contact.extend( Spine.Model.Ajax );
var contact = new Contact({
name: "Sven Svensson",
email: "[email protected]"
});
contact.name = "John Johnson";
contact.save();
</pre>
<a href="http://hjortureh.tumblr.com/post/22117245794/spine-js-vs-backbone-js">Source</a>
</div>
<div id="competitors-knockout" class="step slide" data-x="1000" data-y="5000">
<header>competitors</header>
<h2><a href="http://knockoutjs.com/">Knockout</a></h2>
<pre class="brush: js">
function AppViewModel() {
this.name = ko.observable("Name");
this.capitalize = function() {
this.name(this.name().toUpperCase());
};
this.save = function() {
/* server sync is manual */
}
}
ko.applyBindings(new AppViewModel());
</pre>
<pre class="brush: html">
<input data-bind="value: name" />
<p data-bind="text: name">name</p>
<button data-bind="click: capitalize">
Capitalize
</button>
</pre>
</div>
<div id="competitors-mojito" class="step slide" data-x="2000" data-y="5000">
<header>competitors</header>
<h2><a href="http://developer.yahoo.com/cocktails/mojito/">Mojito</a></h2>
<ul>
<li>Also handles server side (Node.js)</li>
<li>Command line tool (à-la Rails, Zend, ...)</li>
<li>Heavier but maybe more production ready</li>
</ul>
</div>
<div id="ecosystem-developers" class="step slide" data-x="0" data-y="6000">
<header>ecosystem</header>
<h2><a href="https://en.wikipedia.org/wiki/DocumentCloud">Developers</a></h2>
<ul>
<li>DocumentCloud: searching, analyzing, annotation and publication of primary source documents</li>
<li>Young (2009)</li>
<li>Ruby On Rails enjoyers</li>
<li>Backbone is their main javascript contribution</li>
</ul>
<img alt="DocumentCloud homepage" src="documentcloud.png" />
</div>
<div id="ecosystem-extensions" class="step slide" data-x="1000" data-y="6000">
<header>ecosystem</header>
<h2>Extensions</h2>
<ul>
<li>Create forms? <a href="https://github.com/powmedia/backbone-forms">go</a></li>
<li>Save and restore states? <a href="https://github.com/derickbailey/backbone.memento">go</a></li>
<li>Enforce a workflow? <a href="https://github.com/kendagriff/workflow.js">go</a></li>
<li>Work offline and sync later? <a href="https://github.com/Ask11/backbone.offline">go</a></li>
<li>Want a more explicit relational model? <a href="https://github.com/PaulUithol/Backbone-relational">go</a></li>
<li>Find more on <a href="https://github.com/documentcloud/backbone/wiki/Extensions%2C-Plugins%2C-Resources">the wiki</a></li>
</ul>
</div>
<div id="ecosystem-usage" class="step slide" data-x="2000" data-y="6000">
<header>ecosystem</header>
<h2>Usage</h2>
<ul>
<li><a href="http://www.documentcloud.org/public/#search/">DocumentCloud</a> (creator of Backbone)</li>
<li><a href="http://engineering.foursquare.com/2011/12/08/web-sites-are-clients-too/">Foursquare</a></li>
<li><a href="http://www.walmart.com/">Walmart</a> (for the mobile app - only official evidence I found is their contributions)</li>
<li><a href="http://devblog.joindiaspora.com/2012/01/10/client-side-re-write-oh-my/">Diaspora</a> (open source decentralized social network)</li>
<li>And many more, see <a href="http://documentcloud.github.com/backbone/#examples">official site</a> and <a href="https://github.com/documentcloud/backbone/wiki/Projects-and-Companies-using-Backbone">wiki</a></li>
</ul>
</div>
<div id="about" class="step slide" data-x="0" data-y="7000">
<h2>About</h2>
<ul>
<li><a href="https://twitter.com/mathbruyen/">Written by Mathieu Bruyen</a></li>
<li>slideshow using <a href="http://bartaz.github.com/impress.js">impress.js</a></li>
<li>syntax highligthing via <a href="http://alexgorbatchev.com/SyntaxHighlighter">SyntaxHighlighter</a></li>
<li>Underscore code examples from Underscore's homepage</li>
<li>jQuery code examples from jQuery's documentation</li>
</ul>
</div>
</div>
<script type="text/javascript" src="js/impress.js"></script>
<script type="text/javascript" src="js/jquery-1.7.2.js"></script>
<script type="text/javascript" src="js/underscore-1.3.3.js"></script>
<script type="text/javascript" src="js/backbone-0.9.2.js"></script>
<script type="text/javascript" src="js/backbone-localstorage.js"></script>
<script type="text/javascript" src="js/shCore.js"></script>
<script type="text/javascript" src="js/shBrushJScript.js"></script>
<script type="text/javascript" src="js/shBrushXml.js"></script>
<script type="text/javascript">
$(function() {
// Mock calls to the server
$.ajax = function(options) {
alert(options.type + ' request on ' + options.url);
};
$('.runnable').each(function() {
var elem = $(this);
var included = [];
var script = "";
var append = function(e) {
if (e.data('imports')) {
var required = e.data('imports').split(',');
for (var i = 0; i < required.length; i++) {
if (!_.include(included, required[i])) {
append($('#' + required[i]));
}
}
}
script += e.text();
script += '\n';
included.push(e.attr('id'));
};
append(elem);
var button = $('<button>').text('Run!').addClass('runbutton');
button.click(function() {
eval(script);
});
elem.after(button);
elem.removeClass('runnable');
});
impress().init();
SyntaxHighlighter.defaults['toolbar'] = false;
SyntaxHighlighter.all();
});
</script>
</body>
</html>