-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
587 lines (507 loc) · 18.3 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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=1024" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<title>Insira seu codigo_sujo.js aqui.</title>
<meta name="description" content="impress.js is a presentation tool based on the power of CSS3 transforms and transitions in modern browsers and inspired by the idea behind prezi.com." />
<meta name="author" content="Bartek Szopka" />
<!-- <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/impress.css" rel="stylesheet" />
<link href="css/monokai.css" rel="stylesheet" />
<link rel="shortcut icon" href="favicon.png" />
<link rel="apple-touch-icon" href="apple-touch-icon.png" />
</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 class="step slide capa" data-x="-1000" data-y="-1500">
<div class="fundo">
<q>Insira o seu codigo_sujo.js aqui</q>
<div class="autor">
<span>Mauricio Matsuda</span>
<span>Michael Kuhinica</span>
</div>
<img src="img/webgoal.png">
</div>
</div>
<div class="step slide cat-sad" data-x="0" data-y="-1500">
Fazer manutenção em código JavaScript é triste...
</div>
<div class="step slide evil-parts" data-x="1000" data-y="-1500">
<h1>E grande parte da culpa é sua!</h1>
<img src="img/crappy_javascript.gif" />
<p>Só essa funçãozinha, essa variávelzinha...</p>
</div>
<div class="step slide depende-de-todos" data-x="2000" data-y="-1500">
<h1>Código de qualidade é responsabilidade de todos!</h1>
</div>
<div class="step" data-x="0" data-y="0" data-scale="2">
<p>Ciclo do TDD</p><br/><br/><br/><br/><br/><br/><br/>
</div>
<div class="step" data-x="0" data-y="-200" data-scale="1">
<canvas id="redCanvas" width="900" height="800"></canvas>
<canvas id="arrowCanvasRed" width="600" height="600" style="position: absolute;top: 440px;left: 880px;"></canvas>
</div>
<div class="step" data-x="550" data-y="500" data-scale="1">
<canvas id="greenCanvas" width="900" height="800"></canvas>
<canvas id="arrowCanvasGreen" width="1200" height="600" style="position: absolute;top: 300px;left: -1000px;"></canvas>
</div>
<div class="step" data-x="-640" data-y="500" data-scale="1">
<canvas id="blueCanvas" width="900" height="800"></canvas>
<canvas id="arrowCanvasBlue" width="600" height="600" style="position: absolute;top: -280px;left: 505px;"></canvas>
</div>
<div class="step" data-x="0" data-y="0" data-scale="2">
<p>Ciclo do TDD</p><br/><br/><br/><br/><br/><br/><br/>
</div>
<script>
window.onload = function() {
Presentation.canvasOval('red', "Vermelho", 190, 430);
Presentation.canvasArrowRed();
Presentation.canvasOval('green', "Verde", 300, 430);
Presentation.canvasArrowGreen();
Presentation.canvasOval('blue', "Refatoração", 130, 430);
Presentation.canvasArrowBlue();
};
</script>
<div class="step qunit" data-x="600" data-y="1100" data-rotate="-45" data-scale="1">
</div>
<div class="step jquery" data-x="-600" data-y="1100" data-rotate="45" data-scale="1">
</div>
<div class="step code" data-x="0" data-y="1800" data-rotate="0" data-scale="1">
Criando os primeiros testes com QUnit
<div class="split">
<pre><code class="xml"><!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Exemplo de página QUnit</title>
<link rel="stylesheet" href="/src/qunit.css">
</head>
<body>
<div id="qunit"></div>
<script src="/src/qunit.js"></script>
<script src="/src/caculadora.js"></script>
<script src="/src/testes.js"></script>
</body>
</html></code></pre>
</div>
<div class="split">
<pre><code class="javascript">module("Funcionamento");
test("Tem carga", function() {
ok(temCarga() , "Calculadora descarregada");
});
module("Calculos");
test("Somar dois números", function() {
var a = 1, b = 4;
equal(somar(a, b), 5);
});
test("Multiplicar dois números", function() {
var a = 2, b = 3;
equal(multiplicar(a, b), 6);
});</code></pre>
</div>
</div>
<div class="step exemplo_qunit" data-x="0" data-y="2600" data-rotate="0" data-scale="1">
Resultado ao executar os testes
</div>
<div class="step juarez" data-x="0" data-y="3300" data-rotate="0" data-scale="1">
MAS NÃO É SÓ ISSO!
</div>
<div class="step" data-x="100" data-y="4300" data-rotate="90" data-scale="1">
<h2><span style="color:red">CUIDADO</span> com o escopo das variáveis!</h2>
</div>
<div class="step code" data-x="100" data-y="5300" data-rotate="90" data-scale="1">
<ul class="descricao">
<li>Criar variáveis globais é mais fácil e perigoso do que parece;</li>
<li>Váriaveis tem escopo por função e não por bloco;</li>
</ul>
<div>
<div class="split">
<pre><code class="javascript">cachorro = "Bidu"; // variável global
function cebolinha(){
cachorro = "Floquinho"; // variável global
}</code></pre>
</div>
<div class="split">
<pre><code class="javascript">var porco = "Chovinista"; // variável global
function chico_bento(){
var porco = "Torresmo"; // variável local
}</code></pre>
</div>
</div>
</div>
<div class="step" data-x="1100" data-y="5300" data-rotate="-90" data-scale="1">
<h2>Você está declarando suas variáveis certo?</h2>
</div>
<div class="step code" data-x="1100" data-y="4300" data-rotate="-90" data-scale="1">
<ul class="descricao">
<li>O rastreador "declara" as variáveis no topo do escopo, o chamado hoisting;</li>
<li>Pode gerar erros lógicos de interpretação;</li>
</ul>
<div>
<div class="split">
<pre><code class="javascript">pokemon = "Pikachu"; // variável global
alert(pokemon); // "Pikachu"
function ash(){
alert(pokemon); // "undefined"
var pokemon = "Squirtle"; // variável local
alert(pokemon); // "Squirtle"
}
ash();
alert(pokemon); // "Pikachu"
</code></pre>
</div>
<div class="split">
<pre><code class="javascript">pokemon = "Pikachu"; // variável global
alert(pokemon); // "Pikachu"
function ash(){
var pokemon;
alert(pokemon); // "undefined"
pokemon = "Squirtle"; // variável local
alert(pokemon); // "Squirtle"
}
ash();
alert(pokemon); // "Pikachu"
</code></pre>
</div>
</div>
</div>
<div class="step" data-x="3240" data-y="3700" data-rotate="-180" data-scale="1">
<h2>Onde estão as suas variáveis?</h2>
</div>
<div class="step code" data-x="2240" data-y="3700" data-rotate="-180" data-scale="1">
<ul class="descricao">
<li>Evite erros causados pelo hoisting;</li>
<li>Declare todas as variáveis no início do escopo com o padrão Single var;</li>
</ul>
<div>
<div class="split">
<pre><code class="javascript">function looping(){
...
var divs = ["sidebar", "aviso", "footer"];
for(var i = 0; i < divs.length; i++) {
$("#"+divs[i]).removeClass("ativo");
}
}
</code></pre>
</div>
<div class="split">
<pre><code class="javascript">function looping(){
var divs, i, max;
divs = ["sidebar", "aviso", "news_1", "footer"];
...
for(i = 0, max = divs.length; i < max; i++) {
$("#"+divs[i]).removeClass("ativo");
}
}
</code></pre>
</div>
</div>
</div>
<div class="step code" data-x="2240" data-y="2500" data-rotate="0" data-scale="1">
<h2>Funções e variáveis perdidas?</h2>
</div>
<div class="step code" data-x="3240" data-y="2500" data-rotate="0" data-scale="1">
<ul class="descricao">
<li>Tenha controle do escopo com o padrão Module;</li>
<li>Encapsule as funções por funcionalidade;</li>
<li>Código independente;</li>
<li>Variável undefined segura;</li>
</ul>
<div>
<div class="split">
<pre><code class="javascript">aviso_id = "#aviso";
function someAviso() {
$(aviso_id).fadeOut('slow');
}
function mudaAviso(msg) {
$(aviso_id).html(msg);
}
</code></pre>
</div>
<div class="split">
<pre><code class="javascript">var avisoModule = (function($, undefined){
var aviso_id = "#aviso";
return {
someAviso: function() {
$(aviso_id).fadeOut('slow');
},
mudaAviso: function(msg) {
$(aviso_id).html(msg);
}
};
})(jQuery);
avisoModule.mudaAviso("Teste");
</code></pre>
</div>
</div>
</div>
<div class="step code" data-x="2700" data-y="1700" data-rotate="180" data-scale="1">
<h2>E agora? Como testar?</h2>
</div>
<div class="step code" data-x="3000" data-y="1000" data-rotate="180" data-scale="1">
<ul class="descricao">
<li>Variável global e funções com dependências não explícitas;</li>
<li>Dependência entre os casos de testes;</li>
</ul>
<div>
<div class="split">
<pre><code class="javascript">var pilha = [];
function adicionar(item) {
pilha.push(item);
}
function retirar() {
return pilha.pop();
}
function tamanho() {
return pilha.length;
}</code></pre>
</div>
<div class="split">
<pre><code class="javascript">module("Pilha sem estrutura");
test("Tamanho", function() {
adicionar("item1");
equal(tamanho(), 1);
});
test("Retirar", function() {
adicionar("item1");
adicionar("item2")
equal(retirar(), "item2");
});</code></pre>
</div>
</div>
</div>
<div class="step code" data-x="2700" data-y="400" data-rotate="180" data-scale="1">
<ul class="descricao">
<li>O padrão Singleton ajuda a organizar o escopo;</li>
<li>As vezes pode gerar dependências indesejadas;</li>
</ul>
<div>
<div class="split">
<pre><code class="javascript">var appLista = (function() {
var pilha = [];
return {
adicionar: function (item) {
pilha.push(item);
},
retirar: function() {
return pilha.pop();
},
tamanho: function() {
return pilha.length;
}
};
}());</code></pre>
</div>
<div class="split">
<pre><code class="javascript">module("Pilha com Singleton");
test("Tamanho", function() {
appLista.adicionar("item1");
equal(appLista.tamanho(), 1);
});
test("Retirar", function() {
appLista.adicionar("item1");
appLista.adicionar("item2")
equal(appLista.retirar(), "item2");
});</code></pre>
</div>
</div>
</div>
<div class="step code" data-x="3000" data-y="-300" data-rotate="180" data-scale="1">
<ul class="descricao">
<li>Resolva problemas de dependências com o padrão "Construtor";</li>
</ul>
<div>
<div class="split">
<pre><code class="javascript">function novaAppLista() {
var pilha = [];
return {
adicionar: function (item) {
pilha.push(item);
},
retirar: function() {
return pilha.pop();
},
tamanho: function() {
return pilha.length;
}
};
}
var appLista = novaAppLista();</code></pre>
</div>
<div class="split">
<pre><code class="javascript">module("Pilha com Contrutor");
test("Retirar", function() {
var appLista = novaAppLista();
appLista.adicionar("item1");
appLista.adicionar("item2")
equal(appLista.retirar(), "item2");
});
test("Tamanho", function() {
var appLista = novaAppLista();
appLista.adicionar("item1");
equal(appLista.tamanho(), 1);
});</code></pre>
</div>
</div>
</div>
<div class="step code" data-x="4000" data-y="-1000" data-rotate="0" data-scale="1">
<h2>Tenha controle do seu DOM!</h2>
</div>
<div class="step code" data-x="5000" data-y="-1000" data-rotate="0" data-scale="1">
<ul class="descricao">
<li>Muito comum manipular elementos do DOM com seletores JavaScript;</li>
<li>As Fixtures lhe ajudam na simulação desse ambiente;</li>
</ul>
<div>
<div class="split">
<pre><code class="xml"><!DOCTYPE html>
<html>
<head>
<title>Exemplo Fixture</title>
<link rel="stylesheet" href="qunit.css">
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture"></div>
<script src="../qunit.js"></script>
<script src="../jquery.js"></script>
<script src="../exemplo.js"></script>
<script src="../testes.js"></script>
</body>
</html></code></pre>
</div>
<div class="split">
<pre><code class="javascript">test("Adicionar fixture", function() {
$('#qunit-fixture').html(
$('<div id="conta">').html(
'<label id="saldo">Saldo: 1.00</label>'+
'<input id="valor">'+
'<button id="atualizar">OK</button>'
)
);
bindAtualizarSaldo();
$('#valor').val('5.00')
$('#atualizar').click();
equal($('#saldo').html(), 'Saldo: 5.00');
});
</code></pre>
</div>
</div>
</div>
<div class="step code" data-x="4500" data-y="0" data-rotate="0" data-scale="1">
<h2>Não fique esperando o loading...</h2>
</div>
<div class="step code" data-x="5500" data-y="0" data-rotate="0" data-scale="1">
<ul class="descricao">
<li>As requisições Ajax dependem da resposta do servidor;</li>
<li>O MockAjax controla a requisição e os dados de resposta;</li>
</ul>
<div>
<div class="split">
<pre><code class="xml"><body>
<div id="saldo"></div>
<script>
$(function(){ atualizaSaldo(1); });
</script>
</body></code></pre>
<pre style="margin-top:10px;"><code class="javascript">function atualizaSaldo(id){
$.getJSON('/busca_saldo?id='+id, function(response) {
if ( response.status == 'valido') {
$('#saldo').html( 'Saldo: ' + response.saldo );
} else {
$('#saldo').html( 'Conta inválida' );
}
});
}</code></pre>
</div>
<div class="split">
<pre><code class="javascript">asyncTest("Mockajax", function() {
expect( 1 );
$('#qunit-fixture').html($('<div id="saldo">'));
$.mockjax({
url: '/buscar_saldo?id=1',
responseTime: 75,
responseText: { status: 'valido', saldo: '1.00' }
});
atualizaSaldo(1);
setTimeout(function() {
equal($('#saldo').html(), 'Saldo: 1.00');
start();
}, 100);
});
</code></pre>
</div>
</div>
</div>
<div class="step" data-x="7000" data-y="-1000" data-rotate="0" data-scale="1">
<h2>Automatize sempre!</h2>
</div>
<div class="step phantomjs" data-x="7000" data-y="0" data-rotate="-45" data-scale="1">
</div>
<div class="step" data-x="7000" data-y="1000" data-rotate="0" data-scale="1">
Rodando em linha de comando
<ol class="descricao">
<li>Instalar o PhantomJS <br /><a href="http://phantomjs.org/download.html">http://phantomjs.org/download.html</a></li>
<li>Executar usando o script run-qunit.js <br /><a href="https://github.com/ariya/phantomjs/blob/master/examples/run-qunit.js">https://github.com/ariya/phantomjs/blob/master/examples/run-qunit.js</a></li>
<pre><code class="no-highlight">phantomjs run-qunit.js tests/js/index.html</code></pre>
<li>Se retornar 0, não existem falhas, se retornar 1, algum teste falhou.</li>
<pre><code class="no-highlight">Tests completed in 454 milliseconds.
230 tests of 230 passed, 0 failed.</code></pre>
</ol>
</div>
<div class="step real-code" data-x="7100" data-y="2000" data-rotate="0" data-scale="1">
REAL CODE!
</div>
<div class="step armstrong" data-x="5100" data-y="1500" data-rotate="0" data-scale="3">
...um salto gigantesco <br /><br /><br /><br /><br /><br />para a humanidade!
</div>
<div class="step github-intro" data-x="5000" data-y="3000" data-rotate="0" data-scale="1">
github.com/MichaelKuhinica/codigo-sujo
</div>
<div class="step github-ask" data-x="6300" data-y="3000" data-rotate="0" data-scale="1">
Faça perguntas!
</div>
<div class="step github-social" data-x="7600" data-y="3000" data-rotate="0" data-scale="1">
Critique nosso código!
</div>
<div class="step referencias" data-x="5000" data-y="3700" data-rotate="0" data-scale="1">
<strong>JavaScript Scoping and Hoisting</strong>
<p>http://www.adequatelygood.com/2010/2/JavaScript-Scoping-and-Hoisting</p>
<strong>JavaScript Module Pattern: In-Depth</strong>
<p>http://www.adequatelygood.com/2010/3/JavaScript-Module-Pattern-In-Depth</p>
<strong>Writing Testable JavaScript</strong>
<p>http://www.adequatelygood.com/2010/7/Writing-Testable-JavaScript</p>
</div>
<div class="step referencias" data-x="6000" data-y="3700" data-rotate="0" data-scale="1">
<strong>Mock Your Ajax Requests with Mockjax</strong>
<p>http://enterprisejquery.com/2010/07/mock-your-ajax-requests-with-mockjax-for-rapid-development/</p>
<strong>13 JavaScript Performance Tips</strong>
<p>http://www.jonefox.com/blog/2012/07/10/13-javascript-performance-tips/</p>
<strong>Padrões JavaScript</strong>
<p>Stoyan Stefanov</p>
</div>
<div class="step referencias" data-x="5000" data-y="4300" data-rotate="0" data-scale="1">
<strong>impress.js</strong>
<p>https://github.com/bartaz/impress.js/</p>
</div>
<div class="step duvidas" data-x="5000" data-y="5100" data-rotate="0" data-scale="1">
Dúvidas e comentários
</div>
<div class="step obrigado" data-x="5000" data-y="5100" data-z="-1000px" data-rotate="360" data-scale="0.001">
</div>
<div id="overview" class="step" data-x="3000" data-y="1500" data-scale="10">
</div>
</div>
<script src="js/impress.js"></script>
<script src="js/functions.js"></script>
<script src="js/highlight.js"></script>
<script>impress().init();</script>
<script>hljs.initHighlightingOnLoad();</script>
</body>
</html>