-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
executable file
·542 lines (511 loc) · 20.6 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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Leveling Up in Angular - HTML5DevConf</title>
<meta name="description" content="Leveling Up in Angular - HTML5DevConf">
<meta name="author" content="Alicia Liu">
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<link rel="stylesheet" href="css/reveal.min.css">
<link rel="stylesheet" href="css/theme/sky.css" id="theme">
<link rel="stylesheet" href="css/theme/mario.css">
<link rel="stylesheet" href="examples/css/mario.css">
<!-- For syntax highlighting -->
<link rel="stylesheet" href="lib/css/zenburn.css">
<!-- If the query includes 'print-pdf', use the PDF print sheet -->
<script>
document.write( '<link rel="stylesheet" href="css/print/' + ( window.location.search.match( /print-pdf/gi ) ? 'pdf' : 'paper' ) + '.css" type="text/css" media="print">' );
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.12/angular.min.js"></script>
<script src="examples/js/mario.js"></script>
<!--[if lt IE 9]>
<script src="lib/js/html5shiv.js"></script>
<![endif]-->
</head>
<body>
<div class="reveal">
<!-- Any section element inside of this container is displayed as a slide -->
<div class="slides">
<section data-background="images/1-1.png" data-background-size="auto 25%" data-background-position="0 bottom">
<h1>Leveling Up</h1>
<h2>in Angular</h2>
<a href="http://alicialiu.net/leveling-up-angular-talk">http://alicialiu.net/leveling-up-angular-talk</a>
<h3 style="font-weight: bold;"><a href="http://alicialiu.net">Alicia Liu</a></h3>
<p><a href="https://twitter.com/aliciatweet">@aliciatweet</a></p>
<p>Sr Software Engineer, <a href="https://lift.do">Lift</a></p>
</section>
<section data-background="images/1-1.png" data-background-size="auto 25%" data-background-position="right bottom">
<h3>Enjoyment of Angular</h3>
<div class="img-wrapper enjoyment">
<img src="images/enjoyment.png">
<div class="enjoy-1 img-label fragment" data-fragment-index="1">Angular<br>RULEZ</div>
<div class="enjoy-2 img-label fragment" data-fragment-index="2">I'm doing<br>it wrong!</div>
<div class="enjoy-3 img-label fragment" data-fragment-index="3">services,<br>modules</div>
<div class="enjoy-4 img-label fragment" data-fragment-index="4">@#$%</div>
<div class="enjoy-5 img-label fragment" data-fragment-index="5">promises,<br>directives,<br>...</div>
</div>
</section>
<section class="dark" data-background-color="#000" data-background-image="images/1-2.png" data-background-size="auto 50%" data-background-position="right bottom">
<img class="image fragment" src="images/mario-walk.gif">
</section>
<section data-background="images/4-3.png" data-background-size="auto 20%" data-background-position="50% bottom">
<h2>Module Organization</h2>
<img class="svg-module fragment" src="images/module1.svg">
<img class="svg-module fragment" src="images/module2.svg">
<img class="image fragment" src="images/goomba.png" style="position: absolute; right: 0.5em;">
</section>
<section data-background="images/4-3.png" data-background-size="auto 20%" data-background-position="50% bottom">
<h2>Module By Feature</h2>
<img class="svg-module fragment" src="images/module3.svg">
<img class="svg-module fragment" src="images/module4.svg">
<p class="fragment">
Supports asynchronous loading of modules in the future
</p>
<img class="image fragment" src="images/star.gif">
</section>
<section data-background="images/5-1.png" data-background-size="auto 25%" data-background-position="0 bottom">
<h1>Services</h1>
<div class="fragment">
<table class=" table table-condensed">
<thead>
<tr>
<th>Features / Recipe type</th>
<th>Factory</th>
<th>Service</th>
<th>Provider</th>
</tr>
</thead>
<tbody>
<tr>
<td>can have dependencies</td>
<td class="success">yes</td>
<td class="success">yes</td>
<td class="success">yes</td>
</tr>
<tr>
<td>uses type friendly injection</td>
<td class="error">no</td>
<td class="success">yes</td>
<td class="error">no</td>
</tr>
<tr>
<td>object available in config phase</td>
<td class="error">no</td>
<td class="error">no</td>
<td class="success">yes</td>
</tr>
<tr>
<td>can create functions/primitives</td>
<td class="success">yes</td>
<td class="error">no</td>
<td class="success">yes</td>
</tr>
</tbody>
</table>
<small><a href="http://docs.angularjs.org/guide/providers#conclusion">From Angular Developer Guide</a></small>
</div>
</section>
<section data-background="images/5-1.png" data-background-size="auto 25%" data-background-position="0 bottom">
<h3>Service vs Factory</h3>
<pre class="fragment"><code data-trim contenteditable>
var Mario = function() {
this.size = 'small';
};
Mario.prototype.eatMushroom = function() {
this.size = 'large';
};
myModule.service('marioService', Mario); // calls new Mario()
</code></pre>
<pre class="fragment"><code data-trim contenteditable>
myModule.factory('marioService', function() {
var mario = {
size: 'small'
};
return {
eatMushroom: function() {
mario.size = 'large';
}
};
});
</code></pre>
</section>
<section data-background="images/5-1.png" data-background-size="auto 50%" data-background-position="0 bottom">
<h3>Provider</h3>
<pre class="fragment"><code data-trim contenteditable>
myModule.provider('marioService', function() {
var config = {
size: 'small'
};
return {
setSize: function(size) {
config.size = size;
},
$get: function(utilities) {
return {
eatMushroom: function() { ... },
// other methods
}
}
};
});
</code></pre>
</section>
<section class="dark" data-background-color="#003399" data-background-image="images/7-2.png" data-background-size="auto 25%" data-background-position="0 bottom">
<h2>Asynchronous Events</h2>
<pre class="fragment" data-fragment-index="1"><code data-trim contenteditable>
// in some service
$rootScope.$broadcast(MARIO_LOADED, { mario: data}); // when data loads
</code></pre>
<pre class="fragment" data-fragment-index="2"><code data-trim contenteditable>
// in some controller
$scope.$on(MARIO_LOADED, doStuffWithMario);
</code></pre>
<p class="fragment" data-fragment-index="3">What happens if the data doesn't load?</p>
</section>
<section class="dark" data-background-color="#003399" data-background-image="images/7-2.png" data-background-size="auto 25%" data-background-position="33% bottom">
<h2>Promises <code style="text-transform: lowercase;">$q</code></h2>
<pre class="fragment" data-fragment-index="1"><code data-trim contenteditable>
// in some service
var deferred = $q.defer();
svc.getMario = function() {
return deferred.promise;
};
...
deferred.resolve(data); // when some data loads
...
deferred.reject(error); // if data doesn't load
</code></pre>
<pre class="fragment" data-fragment-index="2"><code data-trim contenteditable>
// in some controller
svc.getMario().then( doStuffWithMario, displayError );
</code></pre>
<div class="fragment" data-fragment-index="3">
Promises in the View
<pre ><code data-trim contenteditable>
// in some controller
$scope.mario = marioService.getMario();
// in a view
{{mario.size}}
</code></pre></div>
</section>
<section class="dark" data-background-color="#003399" data-background-image="images/7-2.png" data-background-size="auto 25%" data-background-position="60% bottom">
<h3>Using Promises</h3>
<ul>
<li class="fragment">Chaining</li>
<li class="fragment"><code>$q.all</code></li>
<li class="fragment"><code>$q.when</code></li>
<li class="fragment">Interceptors</li>
</ul>
</section>
<section class="dark" data-background-color="#003399" data-background-image="images/7-2.png" data-background-size="auto 25%" data-background-position="right bottom">
<h3>Resolve</h3>
<pre class="fragment" data-fragment-index="0"><code data-trim contenteditable>
myModule.config(function($routeProvider) {
$routeProvider.when('/character/:id', {
templateUrl: 'profile.html',
controller: 'CharacterCtrl',
resolve: {
character: function($route, CharacterService) {
// returns a promise
return CharacterService.get($route.current.params.id);
}
}
});
});
</code></pre>
<pre class="fragment" data-fragment-index="1"><code data-trim contenteditable>
myModule.controller('CharacterCtrl', function($scope, character) {
$scope.character = character;
});
</code></pre>
</section>
<section class="dark" data-background-color="#000" data-background-image="images/8-4.png" data-background-size="auto 25%" data-background-position="0 bottom">
<h1>Directives</h1>
<br>
<img class="image" src="images/bowser.gif">
<br><br>
<p class="fragment" data-fragment-index="1">
Why Write Custom Directives?
</p>
<ul>
<li class="fragment" data-fragment-index="2">Reusable Components</li>
<li class="fragment" data-fragment-index="3">Manipulate the DOM</li>
</ul>
</section>
<section class="dark" data-background-color="#000" data-background-image="images/8-4.png" data-background-size="auto 25%" data-background-position="0 bottom">
<h3>Directive Example</h3>
<div id="example-directive" ng-controller="exampleCtrl" class="example-wrapper">
<enemy enemy-type="{{enemyType}}" lives="lives" on-destroy="destroy()"></enemy>
<label>Enemy Type: <input type="text" ng-model="enemyType"></label>
</div>
<pre><code contenteditable><enemy enemy-type="{{enemyType}}" lives="lives" on-destroy="destroy()"></enemy>
</code></pre>
<pre class="fragment"><code data-trim contenteditable>
angular.module('demo.characters').directive('enemy', function() {
return {
restrict: "E",
scope: {
type: "@enemyType",
currentLives: "=lives",
onDestroy: "&"
},
template: "<div ng-class='{goomba: type == \"small\", bowser: type == \"big\"}'></div>",
replace: true
};
});
</code></pre>
</section>
<section class="dark" data-background-color="#000" data-background-image="images/8-4.png" data-background-size="auto 25%" data-background-position="0 bottom">
<h3>Restrict</h3>
<ul>
<li>"E": Element, <code><my-directive></code></li>
<li>"A": Attribute, <code><div my-directive></code></li>
<li>"C": Class, <code><div class="my-directive"></code></li>
<li>Combination e.g. "EA"</li>
</ul>
</section>
<section class="dark" data-background-color="#000" data-background-image="images/8-4.png" data-background-size="auto 25%" data-background-position="0 bottom">
<h3>Scope</h3>
<ul>
<li>false: use existing scope (default)</li>
<li>true: new scope</li>
<li class="fragment"><span class="preferred-method">object: isolated scope, e.g.</span>
<ul>
<li class="fragment" data-fragment-index="1">"@": pass as string, can be interpolated</li>
<li class="fragment" data-fragment-index="2">"=": data bind this property</li>
<li class="fragment" data-fragment-index="3">"&": pass a function</li>
</ul>
</li>
</ul>
</section>
<section class="dark" data-background-color="#000" data-background-image="images/8-4.png" data-background-size="auto 25%" data-background-position="0 bottom">
<h3>$watch</h3>
<div id="example-watch" ng-controller="exampleCtrl" class="example-wrapper">
<enemy enemy-type="{{enemyType}}" lives="lives" on-destroy="destroy()"></enemy>
<label>Lives: <input type="number" ng-model="lives" min="0" max="10"></label>
</div>
<pre class="fragment"><code data-trim contenteditable class="language-javascript">
link: function(scope, iElement, iAttrs) {
...
scope.$watch("currentLives", function(newLives, oldLives) {
if (newLives > oldLives) {
$enemy.animate({width:"+=10px",height:"+=10px"},150).animate({width:"-=10px",height:"-=10px"},150);
} else if (newLives < oldLives) {
$enemy.animate({width:"-=10px",height:"-=10px"},150).animate({width:"+=10px",height:"+=10px"},150);
}
});
...
}
</code></pre>
</section>
<section class="dark" data-background-color="#000" data-background-image="images/8-4.png" data-background-size="auto 25%" data-background-position="0 bottom">
<h3>Wrapping jQuery</h3>
<pre class="fragment"><code data-trim contenteditable class="language-javascript">
// jQuery Land
$(document).on('click.fireball', function(e) {
var $fireball = $("<div class='fire-ball'></div>");
var offset = $character.offset();
$fireball.css({top: offset.top + ($character.height()/2), left: offset.left + $character.width()});
$character.after($fireball);
$fireball.animate({top: e.pageY, left: e.pageX}, function() {
$fireball.remove();
$(e.target).trigger("attack");
});
});
</code></pre>
<pre class="fragment"><code data-trim contenteditable class="language-javascript">
// in Angular directive
link: function(scope, iElement, iAttrs) {
var $enemy = $(iElement[0]);
$enemy.on("attack", function(e) {
scope.$apply(function() {
scope.currentLives = scope.currentLives - 1;
if (scope.currentLives === 0) {
$enemy.remove();
scope.onDestroy();
}
});
});
}
</code></pre>
</section>
<section>
<h1><a href="examples/directive.html" target="_blank">DEMO</a></h1>
</section>
<section data-background="images/1-1.png" data-background-size="auto 25%" data-background-position="right bottom">
<h1>The End<br>Thanks!</h1>
<h3 style="font-weight: bold;"><a href="http://alicialiu.net">Alicia Liu</a></h3>
<p><a href="http://twitter.com/aliciatweet">@aliciatweet</a></p>
<p><a href="http://alicialiu.net/leveling-up-angular-talk">http://alicialiu.net/leveling-up-angular-talk</a></p>
<p><br><br><small>Images adapted from <a href="http://mariowiki.com" target="_blank">Mario Wiki</a></small></p>
</section>
<section>
<section>
<h1>Bonus Levels</h1>
</section>
<section>
<h3>Bad Smells</h3>
<ul>
<li>Referencing DOM elements inside controllers</li>
<li>Using $parent</li>
<li>Over-reliance on $rootScope</li>
<li>Over-reliance on $rootScope.$broadcast</li>
</ul>
</section>
<section>
<h3>Digest Loop Triggers</h3>
<ul>
<li>Event handlers</li>
<li>Navigation</li>
<li>$http</li>
<li>$timeout</li>
</ul>
</section>
<section>
<h3>Compile vs Link</h3>
<ul>
<li>No scope</li>
<li>Runs once</li>
<li>Runs earlier</li>
<li>Can return preLink</li>
</ul>
<ul style="float: right;">
<li>Has scope</li>
<li>Runs n times inside ng-repeat</li>
</ul>
</section>
<section>
<h3>Compile Example</h3>
<pre class="fragment"><code data-trim contenteditable class="language-javascript">
angular.module('static').directive('staticLinky', function ($filter) {
return {
restrict: 'A',
compile: function(tElem) {
var $elem = $(tElem);
$elem.html($filter('linky')($elem.text(), "_blank"));
}
};
});
</code></pre>
<pre class="fragment"><code data-trim contenteditable>
<p static-linky>Link this http://example.com</p>
</code></pre>
</section>
<section>
<h3>Precompiling Templates</h3>
<pre><code data-trim contenteditable>
// templates.js
angular.module('myTemplates', [])
.run(['$templateCache', function($templateCache) {
$templateCache.put("template1.html", "<h1>Hello World!</h1>");
$templateCache.put("template2.html", "...");
}]);
</code></pre>
<p>Rails/Ruby example</p>
<pre><code data-trim contenteditable language-javascript>
// templates.js.erb
angular.module('myTemplates', [])
.run(['$templateCache', function($templateCache) {
<% Dir.glob(Rails.root.join('app','assets','templates', '*.html')).each do |f| %>
$templateCache.put("<%= File.basename(f) %>", <%= File.read(f).to_json %>);
<% end %>
}]);
</code></pre>
</section>
<section class="dark" data-background-color="#000" data-background-image="images/8-4.png" data-background-size="auto 25%" data-background-position="0 bottom">
<h4>Communicating Between Directives</h4>
<pre class="fragment"><code contenteditable=""><mario fire-mode="{{mario.mode}}"></mario></code></pre>
<pre class="fragment"><code data-trim contenteditable class="language-javascript">
myModule.directive('mario', function() {
return {
restrict: "E",
scope: {
fireMode: "@"
}
}
}).
directive('fireMode', function() {
return {
restrict: "A",
link: function(scope, iElement, iAttrs) {
var $character = $(iElement[0]);
iAttrs.$observe('fireMode', function(mode) {
if (mode === "fire") {
$character.addClass("fire-mode");
} else {
$character.removeClass("fire-mode");
}
});
}
};
})
</code></pre>
</section>
<section data-background="images/4-3.png" data-background-size="auto 25%" data-background-position="0 bottom">
<p>Angular sample code</p>
<pre><code data-trim contenteditable>
// declare a module
var myAppModule = angular.module('myApp', []);
// configure the module
myAppModule.config(
//...
);
// Add a controller
function Ctrl($scope) {
//...
}
</code></pre>
<p class="fragment">Global variables WTF?!</p>
<pre class="fragment"><code data-trim contenteditable>
angular.module('myApp').config(
//...
);
angular.module('myApp').controller('myController', function() {
//...
});
</code></pre>
</section>
</section>
</div>
</div>
<audio id="sound-pipe" src="audio/pipe.wav"></audio>
<script src="lib/js/head.min.js"></script>
<script src="js/reveal.min.js"></script>
<script>
// Full list of configuration options available here:
// https://github.com/hakimel/reveal.js#configuration
Reveal.initialize({
controls: true,
progress: true,
history: true,
center: true,
theme: 'sky',
transition: 'linear', // default/cube/page/concave/zoom/linear/fade/none
backgroundTransition: 'slide',
// Optional libraries used to extend on reveal.js
dependencies: [
{ src: 'lib/js/classList.js', condition: function() { return !document.body.classList; } },
{ src: 'plugin/markdown/marked.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'plugin/markdown/markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } },
{ src: 'plugin/zoom-js/zoom.js', async: true, condition: function() { return !!document.body.classList; } }
]
});
Reveal.addEventListener( 'slidechanged', function( event ) {
if (event.indexh === 3) {
document.getElementById("sound-pipe").play();
}
});
// bootstrap angular examples, as separate apps, so Angular doesn't try to interpolate random code samples, which can create errors
angular.bootstrap(document.getElementById("example-directive"), ['demo.examples']);
angular.bootstrap(document.getElementById("example-watch"), ['demo.examples']);
</script>
</body>
</html>
<!--
<pre><code data-trim contenteditable>
</code></pre>
-->