-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpresentation.html
398 lines (309 loc) · 9.16 KB
/
presentation.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
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<style>
h2 {
page-break-before: always;
page-break-before: always;
}
h1,
h2,
h3,
h4,
h5,
h6,
p,
blockquote {
margin: 0;
padding: 0;
}
body {
font-family: "Helvetica Neue", Helvetica, "Hiragino Sans GB", Arial, sans-serif;
font-size: 13px;
line-height: 18px;
color: #737373;
margin: 10px 13px 10px 13px;
}
a {
color: #0069d6;
}
a:hover {
color: #0050a3;
text-decoration: none;
}
a img {
border: none;
}
p {
margin-bottom: 9px;
}
h1,
h2,
h3,
h4,
h5,
h6 {
color: #404040;
line-height: 36px;
}
h1 {
margin-bottom: 18px;
font-size: 30px;
}
h2 {
font-size: 24px;
}
h3 {
font-size: 18px;
}
h4 {
font-size: 16px;
}
h5 {
font-size: 14px;
}
h6 {
font-size: 13px;
}
hr {
margin: 0 0 19px;
border: 0;
border-bottom: 1px solid #ccc;
}
blockquote {
padding: 13px 13px 21px 15px;
margin-bottom: 18px;
font-family:georgia,serif;
font-style: italic;
}
blockquote:before {
content:"\201C";
font-size:40px;
margin-left:-10px;
font-family:georgia,serif;
color:#eee;
}
blockquote p {
font-size: 14px;
font-weight: 300;
line-height: 18px;
margin-bottom: 0;
font-style: italic;
}
code, pre {
font-family: Monaco, Andale Mono, Courier New, monospace;
}
code {
background-color: #fee9cc;
color: rgba(0, 0, 0, 0.75);
padding: 1px 3px;
font-size: 12px;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
}
pre {
display: block;
padding: 14px;
margin: 0 0 18px;
line-height: 16px;
font-size: 11px;
border: 1px solid #d9d9d9;
white-space: pre-wrap;
word-wrap: break-word;
}
pre code {
background-color: #fff;
color:#737373;
font-size: 11px;
padding: 0;
}
@media screen and (min-width: 768px) {
body {
width: 748px;
margin:10px auto;
}
}
</style>
<title>SpinejsPresentation.html</title>
</head>
<body>
<h2>JavascriptMVC</h2>
<p>Ideas and best practices from server side frameworks (Rails, Django, Zend…) are on the move to client side programming.</p>
<h2>Spine.js</h2>
<p>Is a JavaScript MVC among many.</p>
<p>A lot of great alternatives out there.</p>
<p>I think it’s less about which framework you choose and more what you learn from the MVC approach.</p>
<h2>Why JavaScript MVC?</h2>
<p>Programming should be fun. What isn’t fun?</p>
<pre><code>Complicated Code
Unorganized Code
Breaking Things
Not understanding things
</code></pre>
<h2>Make Client Side Programming Fun Again</h2>
<pre><code>Structured
Organized
Maintainable
Tested
Challenging - learn something new
Applied design patterns for well architected applications
</code></pre>
<h2>JavaScript is a First Class Citizen!</h2>
<pre><code>Applications are pushing functionality to the client
responsive, rich and asynchronous
It is the most ubiquitous programming language around (you should learn it)
Enjoy all the benefits of shared framework and environment (Think server side… Rails, Django… etc)
</code></pre>
<h2>Don’t Cook Spaghetti Code</h2>
<p>…or deal with crazy assets!</p>
<h2>Why Spine.js in Particular?</h2>
<pre><code>500 readable LOC ~ 2K minified
No dependencies (but you'll probably want to use jQuery/Zepto…)
Has some nice conventions (elements, events)
Written in CoffeeScript
By Alex MacCaw O'Reilly Author
Great Documentation and Many Sample Applications
Spine Mobile
Code generators
Inspired by and borrows great ideas from other frameworks
</code></pre>
<h2>Getting Started</h2>
<p>You can use as much or as little MVC as you want.</p>
<p>Your whole application doesn’t have to be MVC.</p>
<pre><code>Experiment writing your own "single page apps" Todo, Contacts, etc…
Identify "single page apps" even within your application where there is complex interaction
</code></pre>
<h2>Warning: It is complicated!</h2>
<p>A different way of thinking about the client side programming.</p>
<p>Some traditional MVC concepts don’t apply so cleanly.</p>
<p>Start simple and get more advanced over time.</p>
<p>It is a lot of code at first. But just like Rails, Django and others, the value is earned over time.</p>
<h2>Some Core Concepts</h2>
<h2>MVC</h2>
<p>Model View Controller is a tried and true design pattern for separating application code into logical concerns.</p>
<h2>Your Models</h2>
<p>Deal with application data, relationships/structures and persistence.</p>
<p>AJAX</p>
<p>HTML5 LocalStorage</p>
<h2>Your Views</h2>
<p>Often are the visual representation of your models.</p>
<p>Templates and helpers for rendering complex structures.</p>
<p>Logic less templates such as Mustache, Handlebars, Eco, jQuery.tmpl… the list goes on.</p>
<h2>Your Controllers</h2>
<p>Are responsible for orchestrating and handling events, rending models… and much much more.</p>
<h2>On to the Code…</h2>
<p>Keep it simple.</p>
<h2>Sample Application: Weight Watchr</h2>
<p>Log and chart weight over time</p>
<p><em>Save Weight as number</em></p>
<p><em>Plot that number as it changes</em></p>
<p><em>Delete entries</em></p>
<h2>Step 1 ) Project Directory Structure and Dependencies</h2>
<pre><code>index.html
lib/spine.js
lib/local.spine.js
lib/jquery.js
lib/application.coffee -> lib/application.js (dynamically compiled)
</code></pre>
<h2>Step 2 ) What Templates Look Like (jQuery.tmpl)</h2>
<pre><code><script type="text/x-jquery-tmpl" id="template">
<div class="entry">
I weighed <span class='weight'>${weight}</span>
<span><a href="#" class="delete">x</a></span>
</div>
</script>
</code></pre>
<h2>Step 3 ) Your index.html (Excluding Stylesheets)</h2>
<pre><code><body>
<head>
<!-- My Dependencies -->
<script src="lib/jquery.js" type="text/javascript" charset="utf-8"></script>
<script src="lib/jquery.tmpl.js" type="text/javascript" charset="utf-8"></script>
<script src="lib/spine.js" type="text/javascript" charset="utf-8"></script>
<!-- LocalStorage Adapter -->
<script src="lib/local.js" type="text/javascript" charset="utf-8"></script>
<!-- My Spine Code -->
<script src="lib/application.js" type="text/javascript" charset="utf-8"></script>
<!-- My Template -->
<script type="text/x-jquery-tmpl" id="template">
<div class="entry">
I weighed <span class='weight'>${weight}</span>
<span><a href="#" class="delete">x</a></span>
</div>
</script>
</head>
<h1>Weight Watchr</h1>
<!-- Spine App Controller Element #app -->
<div id="app">
<input name='weight' type="text" value="Enter weight:">
<!-- Spine Entries Go Here .entries -->
<div class="entries"></div>
</div>
</body>
</code></pre>
<h2>Give Me Some Coffee!</h2>
<h2>The App Controller</h2>
<p>The entry point for our single page app (Some code Omitted)</p>
<h2>Events Tied to DOM Elements and Have a Friendly Name</h2>
<p>events { ‘event element’: ‘callbackName’ }</p>
<h2>DOM Elements Accessors</h2>
<p>elements: { ‘#element.selector’: ‘friendlyName’ } => @friendlyName</p>
<h2>App Controller Code</h2>
<pre><code>class App extends Spine.Controller
events:
'keyup input[name=weight]': 'create'
'click input[name=weight]': 'initInput'
elements:
".entries": "entries"
"input[name=weight]": "input"
"#donut": "donut"
constructor: ->
super
Entry.bind("refresh change", @updateCurrentWeight)
Entry.fetch()
create: (event)->
event.preventDefault()
if event.keyCode == 13
new Entry(weight: @input.val()).save()
@input.val('')
updateCurrentWeight: =>
@currentWeight.html(Entry.currentWeight())
@donut.css({width: Entry.currentWeight() - 50})
new App(el: $("#app"))
</code></pre>
<h2>The Entries Controller</h2>
<p>Responsible for rendering individual elements</p>
<pre><code>class Entries extends Spine.Controller
events:
"click .delete": "delete"
constructor: ->
super
@entry.bind('update', @render)
@entry.bind("destroy", @release)
render: =>
@replace($("#template").tmpl(@entry))
@
delete: ->
@entry.destroy()
</code></pre>
<h2>Our Model</h2>
<p>Extends Spine.Model</p>
<p>Declare attributes using @configure(“ModelName”, “attr_1”, “attr_2”, …)</p>
<p>Add methods with @methodName: (anyArgs…)–></p>
<pre><code> class window.Entry extends Spine.Model
@configure 'Entry', 'weight'
@extend Spine.Model.Local # Use local Storage
@weights: ->
Entry.all().map (entry)->
return entry.weight
</code></pre>
<h2>Boot It Up</h2>
<pre><code>$ ->
new App(el: $("#app"))
</code></pre>
<h2>Visit The App…</h2>
<p><a href="http://seanbehan.com/weightwatchr/">http://seanbehan.com/weightwatchr</a></p>
</body>
</html>