-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
204 lines (198 loc) · 8.47 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
<!doctype html>
<html lang="pt">
<head>
<meta charset="utf-8">
<title>jQuery.Callbacks()</title>
<meta name="description" content="Pequena apresentação sobre jQuery.Callbacks">
<meta name="author" content="Thiago Lagden">
<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, minimal-ui">
<link rel="stylesheet" href="css/reveal.css">
<link rel="stylesheet" href="css/theme/night.css" id="theme">
<!-- Code syntax highlighting -->
<link rel="stylesheet" href="lib/css/railscasts.css">
<!-- Printing and PDF exports -->
<script>
var link = document.createElement('link');
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = window.location.search.match(/print-pdf/gi) ? 'css/print/pdf.css' : 'css/print/paper.css';
document.getElementsByTagName('head')[0].appendChild(link);
</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>
<h1>jQuery</h1>
<h2>write less, do more.</h2>
<h3>$.Callbacks()</h3>
<p>
<small>Criado por <a href="http://lagden.in">Thiago Lagden</a> / <a href="http://twitter.com/thiagolagden">@thiagolagden</a> / <a href="https://github.com/lagden">Github</a></small>
</p>
</section>
<section>
<h2>O que é?</h2>
<p>
É um jeito interessante de gerenciar listas de callback.
</p>
</section>
<section>
<h1>Quem já usou?</h1>
</section>
<section>
<section>
<h3>Você sabia?</h3>
<p><b>$.Callbacks()</b> é usado internamente pelo jQuery nos componentes:</p>
<p>$.ajax()</p>
<p>$.Deferred()</p>
</section>
<section>
<h2>$.ajax()</h2>
<pre>
<code class="javascript">// https://github.com/jquery/jquery/blob/master/src/ajax.js#L409
completeDeferred = jQuery.Callbacks("once memory");
</code></pre>
<pre>
<code class="javascript">// https://github.com/jquery/jquery/blob/master/src/ajax.js#L620
completeDeferred.add( s.complete );
</code></pre>
<pre>
<code class="javascript">// https://github.com/jquery/jquery/blob/master/src/ajax.js#L764
completeDeferred.fireWith(callbackContext, [jqXHR, statusText]);
</code></pre>
</section>
<section>
<h2>$.Deferred()</h2>
<pre>
<code class="javascript">// https://github.com/jquery/jquery/blob/master/src/deferred.js#L16
Deferred: function( func ) {
var tuples = [
// action, add listener, callbacks,
// ... .then handlers, argument index, [final state]
[ "notify", "progress", jQuery.Callbacks("memory"),
jQuery.Callbacks("memory"), 2 ],
[ "resolve", "done", jQuery.Callbacks("once memory"),
jQuery.Callbacks("once memory"), 0, "resolved" ],
[ "reject", "fail", jQuery.Callbacks("once memory"),
jQuery.Callbacks("once memory"), 1, "rejected" ]
],
</code></pre>
</section>
</section>
<section data-background="http://i.giphy.com/90F8aUepslB84.gif">
</section>
<section>
<section>
<h2>Flags</h2>
<p><pre><code class="javascript">var listaA = $.Callbacks('once memory');
var listaB = $.Callbacks()</code></pre></p>
<p>As flags você passa ao criar uma instância do <b>$.Callbacks()</b></p>
<p>Observe que podemos utilizar mais de uma na mesma instância!</p>
<p>Veja abaixo as definições de cada flag e um link para os exemplos.</p>
</section>
<section>
<h3>Definições e exemplos</h3>
<ul style="list-style: none;">
<li><code style="color:red">once</code> A lista de callback só é disparado 1 vez</li>
<li><code style="color:red">memory</code> Chama o callback adicionado depois do disparo com o valor "memorizado".</li>
<li><code style="color:red">unique</code> O callback só será disparado 1 vez, mesmo que seja adicionado várias vezes</li>
<li><code style="color:red">stopOnFalse</code> É interrompido quando um callback da lista retornar <code>false</code></li>
</ul>
<p><a href="https://github.com/lagden/exemplos-cbs">https://github.com/lagden/exemplos-cbs</a></p>
</section>
</section>
<section>
<h2>Métodos</h2>
<p>Os mais comuns são o <b>add()</b>, <b>remove()</b> e <b>fire()</b>, mas temos outros.</p>
<p><code style="color:red">disable()</code></p>
<p><code style="color:red">disabled()</code></p>
<p><code style="color:red">empty()</code></p>
<p><code style="color:red">fired()</code></p>
<p><code style="color:red">fireWith()</code></p>
<p><code style="color:red">has()</code></p>
<p><code style="color:red">locked()</code></p>
<p>Veja a documentação: <a href="https://api.jquery.com/category/callbacks-object/">callbacks-object</a></p>
</section>
<section>
<h2>A idéia geral por trás Publish/Subscribe</h2>
<p>É possível implementar um sistema de Pub/Sub utilizando apenas <b>$.Callbacks</b></p>
<p><pre><code class="javascript">var Broadcast = {};
$.Broadcast = function(id) {
var callbacks, topic;
topic = id && Broadcast[id];
if (!topic) {
callbacks = $.Callbacks();
topic = {
publish: callbacks.fire,
subscribe: callbacks.add,
unsubscribe: callbacks.remove
};
if (id) {
Broadcast[id] = topic;
}
}
return topic;
};</code></pre></p>
<p><a href="https://github.com/lagden/exemplos-cbs-pub-sub">https://github.com/lagden/exemplos-cbs-pub-sub</a></p>
</section>
<section data-transition="slide" data-background="#4d7e65" data-background-transition="zoom">
<h1>Thanks ;)</h1>
<p>Não deixe de brincar com os exemplos!!</p>
<p><a href="https://github.com/lagden/exemplos-cbs">https://github.com/lagden/exemplos-cbs</a></p>
<p><a href="https://github.com/lagden/exemplos-cbs-pub-sub">https://github.com/lagden/exemplos-cbs-pub-sub</a></p>
</section>
</div>
</div>
<script src="lib/js/head.min.js"></script>
<script src="js/reveal.js"></script>
<script>
// Full list of configuration options available at:
// https://github.com/hakimel/reveal.js#configuration
Reveal.initialize({
controls: true,
progress: true,
history: true,
center: true,
transition: 'slide', // none/fade/slide/convex/concave/zoom
// Optional reveal.js plugins
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,
condition: function() {
return !!document.querySelector('pre code');
},
callback: function() {
hljs.initHighlightingOnLoad();
}
}, {
src: 'plugin/zoom-js/zoom.js',
async: true
}, {
src: 'plugin/notes/notes.js',
async: true
}]
});
</script>
</body>
</html>