Skip to content

Commit 0dc8518

Browse files
committed
jQuery.Callbacks: Clean up grammar, punctuation, etc.
1 parent f6f9943 commit 0dc8518

File tree

1 file changed

+26
-17
lines changed

1 file changed

+26
-17
lines changed

entries/jQuery.Callbacks.xml

+26-17
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0"?>
2-
<entry name="jQuery.Callbacks" type="method" return="">
2+
<entry name="jQuery.Callbacks" type="method" return="Callbacks">
33
<title>jQuery.Callbacks()</title>
44
<signature>
55
<added>1.7</added>
@@ -10,7 +10,7 @@
1010
<desc>A multi-purpose callbacks list object that provides a powerful way to manage callback lists.</desc>
1111
<longdesc>
1212
<p>The <code>$.Callbacks()</code> function is internally used to provide the base functionality behind the jQuery <code>$.ajax()</code> and <code>$.Deferred()</code> components. It can be used as a similar base to define functionality for new components.</p>
13-
<p><code>$.Callbacks()</code> support a number of methods including <code><a href="/callbacks.add/">callbacks.add()</a></code>,<code><a href="/callbacks.remove/">callbacks.remove()</a></code>, <code><a href="/callbacks.fire/">callbacks.fire()</a></code> and <code><a href="/callbacks.disable/">callbacks.disable()</a></code>.</p>
13+
<p><code>$.Callbacks()</code> supports a number of methods including <code><a href="/callbacks.add/">callbacks.add()</a></code>,<code><a href="/callbacks.remove/">callbacks.remove()</a></code>, <code><a href="/callbacks.fire/">callbacks.fire()</a></code> and <code><a href="/callbacks.disable/">callbacks.disable()</a></code>.</p>
1414
<h3 id="getting-started">Getting started</h3>
1515
<p>The following are two sample methods named <code>fn1</code> and <code>fn2</code>:</p>
1616
<pre><code>
@@ -23,37 +23,45 @@ function fn2( value ){
2323
return false;
2424
}
2525
</code></pre>
26-
<p>These can be added as callbacks to a <code>$.Callbacks</code> list and invoked follows:</p>
26+
<p>These can be added as callbacks to a <code>$.Callbacks</code> list and invoked as follows:</p>
2727
<pre><code>
2828
var callbacks = $.Callbacks();
2929
callbacks.add( fn1 );
30-
callbacks.fire( "foo!" ); // outputs: foo!
30+
31+
// outputs: foo!
32+
callbacks.fire( "foo!" );
3133

3234
callbacks.add( fn2 );
33-
callbacks.fire( "bar!" ); // outputs: bar!, fn2 says: bar!
35+
36+
// outputs: bar!, fn2 says: bar!
37+
callbacks.fire( "bar!" );
3438
</code></pre>
3539
<p>The result of this is that it becomes simple to construct complex lists of callbacks where input values can be passed through to as many functions as needed with ease.</p>
36-
<p>Two specific methods were being used above: <code>.add()</code> and <code>.fire()</code> .add() supports adding new callbacks to the callback list, whilst fire() provides a way to pass arguments to be processed by the callbacks in the same list.</p>
37-
<p>Another method supported by <code>$.Callbacks</code> is remove(), which has the ability to remove a particular callback from the callback list. Here"s a practical example of .remove() being used:</p>
40+
<p>Two specific methods were being used above: <code>.add()</code> and <code>.fire()</code>. The <code>.add()</code> method supports adding new callbacks to the callback list, while the <code>.fire()</code> method executes the added functions and provides a way to pass arguments to be processed by the callbacks in the same list.</p>
41+
<p>Another method supported by <code>$.Callbacks</code> is <code>.remove()</code>, which has the ability to remove a particular callback from the callback list. Here"s a practical example of <code>.remove()</code> being used:</p>
3842
<pre><code>
3943
var callbacks = $.Callbacks();
4044
callbacks.add( fn1 );
41-
callbacks.fire( "foo!" ); // outputs: foo!
45+
46+
// outputs: foo!
47+
callbacks.fire( "foo!" );
4248

4349
callbacks.add( fn2 );
44-
callbacks.fire( "bar!" ); // outputs: bar!, fn2 says: bar!
50+
51+
// outputs: bar!, fn2 says: bar!
52+
callbacks.fire( "bar!" );
4553

4654
callbacks.remove(fn2);
47-
callbacks.fire( "foobar" );
4855

4956
// only outputs foobar, as fn2 has been removed.
57+
callbacks.fire( "foobar" );
5058
</code></pre>
5159
<h3 id="supported-flags">Supported Flags</h3>
5260
<p>The <code>flags</code> argument is an optional argument to <code>$.Callbacks()</code>, structured as a list of space-separated strings that change how the callback list behaves (eg. <code>$.Callbacks( 'unique stopOnFalse' )</code>).</p>
5361
<h2>Possible flags:</h2>
5462
<ul>
5563
<li><code>once</code>: Ensures the callback list can only be fired once (like a Deferred).</li>
56-
<li><code>memory</code>: Keep track of previous values and will call any callback added after the list has been fired right away with the latest "memorized" values (like a Deferred).</li>
64+
<li><code>memory</code>: Keeps track of previous values and will call any callback added after the list has been fired right away with the latest "memorized" values (like a Deferred).</li>
5765
<li><code>unique</code>: Ensures a callback can only be added once (so there are no duplicates in the list).</li>
5866
<li><code>stopOnFalse</code>: Interrupts callings when a callback returns false.</li>
5967
</ul>
@@ -137,7 +145,7 @@ bar
137145
foobar
138146
*/
139147
</code></pre>
140-
<p>Because $.Callbacks() supports a list of flags rather than just one, setting several flags has a cumulative effect similar to "&amp;&amp;". This means it's possible to combine flags to create callback lists that are say, both <i>unique</i> and <i>ensure if list was already fired, adding more callbacks will have it called with the latest fired value</i> (i.e. <code>$.Callbacks("unique memory")</code>).</p>
148+
<p>Because <code>$.Callbacks()</code> supports a list of flags rather than just one, setting several flags has a cumulative effect similar to "&amp;&amp;". This means it's possible to combine flags to create callback lists that, say, both are <i>unique</i> and <i>ensure if list was already fired, adding more callbacks will have it called with the latest fired value</i> (i.e. <code>$.Callbacks("unique memory")</code>).</p>
141149
<h2 id="unique-memory"><code>$.Callbacks( 'unique memory' )</code>:</h2>
142150
<pre><code>
143151
function fn1( value ){
@@ -172,8 +180,8 @@ fn2 says:baz
172180
foobar
173181
*/
174182
</code></pre>
175-
<p>Flag combinations are internally used with <code>$.Callbacks()</code> in jQuery for the <code>.done()</code> and <code>.fail()</code> buckets on a Deferred - both of which use <code>$.Callbacks('memory once')</code>.</p>
176-
<p>$.Callbacks methods can also be detached, should there be a need to define short-hand versions for convenience:</p>
183+
<p>Flag combinations with <code>$.Callbacks()</code> are internally in jQuery for the <code>.done()</code> and <code>.fail()</code> functions on a Deferred both of which use <code>$.Callbacks('memory once')</code>.</p>
184+
<p>The methods of <code>$.Callbacks</code> can also be detached, should there be a need to define short-hand versions for convenience:</p>
177185
<pre><code>
178186
var callbacks = $.Callbacks(),
179187
add = callbacks.add,
@@ -185,14 +193,15 @@ fire( "hello world");
185193
remove( fn1 );
186194
</code></pre>
187195
<h3 id="pubsub">$.Callbacks, $.Deferred and Pub/Sub</h3>
188-
<p>The general idea behind pub/sub (the Observer pattern) is the promotion of loose coupling in applications. Rather than single objects calling on the methods of other objects, an object instead subscribes to a specific task or activity of another object and is notified when it occurs. Observers are also called Subscribers and we refer to the object being observed as the Publisher (or the subject). Publishers notify subscribers when events occur</p>
189-
<p>As a demonstration of the component-creation capabilities of <code>$.Callbacks()</code>, it's possible to implement a Pub/Sub system using only callback lists. Using <code>$.Callbacks</code> as a topics queue, a system for publishing and subscribing to topics can be implemented as follows:</p>
196+
<p>The general idea behind pub/sub (the Observer pattern) is the promotion of loose coupling in applications. Rather than single objects calling on the methods of other objects, an object instead subscribes to a specific task or activity of another object and is notified when it occurs. Observers are also called Subscribers, and we refer to the object being observed as the Publisher (or the subject). Publishers notify subscribers when events occur.</p>
197+
<p>To demonstrate the component-creation capabilities of <code>$.Callbacks()</code>, it's possible to implement a Pub/Sub system using only callback lists. Using <code>$.Callbacks</code> as a topics queue, a system for publishing and subscribing to topics can be implemented as follows:</p>
190198
<pre><code>var topics = {};
191199

192200
jQuery.Topic = function( id ) {
193201
var callbacks,
194202
method,
195203
topic = id &amp;&amp; topics[ id ];
204+
196205
if ( !topic ) {
197206
callbacks = jQuery.Callbacks();
198207
topic = {
@@ -254,4 +263,4 @@ dfd.resolve( "its been published!" );
254263
</longdesc>
255264
<category slug="callbacks-object"/>
256265
<category slug="version/1.7"/>
257-
</entry>
266+
</entry>

0 commit comments

Comments
 (0)