Skip to content

Commit ee4ebae

Browse files
committed
Clean up jQuery.Callbacks entry
1 parent 6559302 commit ee4ebae

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

entries/jQuery.Callbacks.xml

+18-18
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
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>
17-
function fn1( value ){
17+
function fn1( value ) {
1818
console.log( value );
1919
}
2020

21-
function fn2( value ){
22-
fn1("fn2 says:" + value);
21+
function fn2( value ) {
22+
fn1("fn2 says: " + value);
2323
return false;
2424
}
2525
</code></pre>
@@ -51,13 +51,13 @@ callbacks.add( fn2 );
5151
// outputs: bar!, fn2 says: bar!
5252
callbacks.fire( "bar!" );
5353

54-
callbacks.remove(fn2);
54+
callbacks.remove( fn2 );
5555

5656
// only outputs foobar, as fn2 has been removed.
5757
callbacks.fire( "foobar" );
5858
</code></pre>
5959
<h3 id="supported-flags">Supported Flags</h3>
60-
<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>
60+
<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>
6161
<h2>Possible flags:</h2>
6262
<ul>
6363
<li><code>once</code>: Ensures the callback list can only be fired once (like a Deferred).</li>
@@ -67,7 +67,7 @@ callbacks.fire( "foobar" );
6767
</ul>
6868
<p>By default a callback list will act like an event callback list and can be "fired" multiple times.</p>
6969
<p>For examples of how <code>flags</code> should ideally be used, see below:</p>
70-
<h2 id="once"><code>$.Callbacks( 'once' )</code>:</h2>
70+
<h2 id="once"><code>$.Callbacks( "once" )</code>:</h2>
7171
<pre><code>
7272
var callbacks = $.Callbacks( "once" );
7373
callbacks.add( fn1 );
@@ -82,7 +82,7 @@ output:
8282
foo
8383
*/
8484
</code></pre>
85-
<h2 id="memory"><code>$.Callbacks( 'memory' )</code>:</h2>
85+
<h2 id="memory"><code>$.Callbacks( "memory" )</code>:</h2>
8686
<pre><code>var callbacks = $.Callbacks( "memory" );
8787
callbacks.add( fn1 );
8888
callbacks.fire( "foo" );
@@ -100,7 +100,7 @@ fn2 says:bar
100100
foobar
101101
*/
102102
</code></pre>
103-
<h2 id="unique"><code>$.Callbacks( 'unique' )</code>:</h2>
103+
<h2 id="unique"><code>$.Callbacks( "unique" )</code>:</h2>
104104
<pre><code>var callbacks = $.Callbacks( "unique" );
105105
callbacks.add( fn1 );
106106
callbacks.fire( "foo" );
@@ -118,19 +118,19 @@ fn2 says:bar
118118
foobar
119119
*/
120120
</code></pre>
121-
<h2 id="stopOnFalse"><code>$.Callbacks( 'stopOnFalse' )</code>:</h2>
121+
<h2 id="stopOnFalse"><code>$.Callbacks( "stopOnFalse" )</code>:</h2>
122122
<pre><code>
123123
function fn1( value ){
124124
console.log( value );
125125
return false;
126126
}
127127

128128
function fn2( value ){
129-
fn1("fn2 says:" + value);
129+
fn1( "fn2 says: " + value );
130130
return false;
131131
}
132132

133-
var callbacks = $.Callbacks( "stopOnFalse");
133+
var callbacks = $.Callbacks( "stopOnFalse" );
134134
callbacks.add( fn1 );
135135
callbacks.fire( "foo" );
136136
callbacks.add( fn2 );
@@ -148,13 +148,13 @@ foobar
148148
<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>
149149
<h2 id="unique-memory"><code>$.Callbacks( 'unique memory' )</code>:</h2>
150150
<pre><code>
151-
function fn1( value ){
151+
function fn1( value ) {
152152
console.log( value );
153153
return false;
154154
}
155155

156-
function fn2( value ){
157-
fn1("fn2 says:" + value);
156+
function fn2( value ) {
157+
fn1( "fn2 says: " + value );
158158
return false;
159159
}
160160

@@ -189,11 +189,11 @@ var callbacks = $.Callbacks(),
189189
fire = callbacks.fire;
190190

191191
add( fn1 );
192-
fire( "hello world");
192+
fire( "hello world" );
193193
remove( fn1 );
194194
</code></pre>
195195
<h3 id="pubsub">$.Callbacks, $.Deferred and Pub/Sub</h3>
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>
196+
<p>The general idea behind pub/sub (Publish/Subscribe, or, 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>
197197
<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>
198198
<pre><code>var topics = {};
199199

@@ -238,7 +238,7 @@ fn2 says: hello world!
238238
woo! mail!
239239
*/
240240
</code></pre>
241-
<p>Whilst this is useful, the implementation can be taken further. Using <code>$.Deferreds</code>, it's possible to ensure publishers only publish notifications for subscribers once particular tasks have been completed (resolved). See the below code sample for some further comments on how this could be used in practice:</p>
241+
<p>While this is useful, the implementation can be taken further. Using <code>$.Deferreds</code>, it's possible to ensure publishers only publish notifications for subscribers once particular tasks have been completed (resolved). See the below code sample for some further comments on how this could be used in practice:</p>
242242
<pre><code>// subscribe to the mailArrived notification
243243
$.Topic( "mailArrived" ).subscribe( fn1 );
244244

@@ -258,7 +258,7 @@ dfd.done( topic.publish );
258258
// (eg. waiting on an ajax call to complete) so that
259259
// messages are only published once the task has actually
260260
// finished.
261-
dfd.resolve( "its been published!" );
261+
dfd.resolve( "it's been published!" );
262262
</code></pre>
263263
</longdesc>
264264
<category slug="callbacks-object"/>

0 commit comments

Comments
 (0)