You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: entries/jQuery.Callbacks.xml
+18-18
Original file line number
Diff line number
Diff line change
@@ -14,12 +14,12 @@
14
14
<h3id="getting-started">Getting started</h3>
15
15
<p>The following are two sample methods named <code>fn1</code> and <code>fn2</code>:</p>
16
16
<pre><code>
17
-
function fn1( value ){
17
+
function fn1( value ){
18
18
console.log( value );
19
19
}
20
20
21
-
function fn2( value ){
22
-
fn1("fn2 says:" + value);
21
+
function fn2( value ){
22
+
fn1("fn2 says:" + value);
23
23
return false;
24
24
}
25
25
</code></pre>
@@ -51,13 +51,13 @@ callbacks.add( fn2 );
51
51
// outputs: bar!, fn2 says: bar!
52
52
callbacks.fire( "bar!" );
53
53
54
-
callbacks.remove(fn2);
54
+
callbacks.remove(fn2);
55
55
56
56
// only outputs foobar, as fn2 has been removed.
57
57
callbacks.fire( "foobar" );
58
58
</code></pre>
59
59
<h3id="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>
61
61
<h2>Possible flags:</h2>
62
62
<ul>
63
63
<li><code>once</code>: Ensures the callback list can only be fired once (like a Deferred).</li>
@@ -67,7 +67,7 @@ callbacks.fire( "foobar" );
67
67
</ul>
68
68
<p>By default a callback list will act like an event callback list and can be "fired" multiple times.</p>
69
69
<p>For examples of how <code>flags</code> should ideally be used, see below:</p>
<p>Because <code>$.Callbacks()</code> supports a list of flags rather than just one, setting several flags has a cumulative effect similar to "&&". 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>
@@ -189,11 +189,11 @@ var callbacks = $.Callbacks(),
189
189
fire = callbacks.fire;
190
190
191
191
add( fn1 );
192
-
fire( "hello world");
192
+
fire( "hello world");
193
193
remove( fn1 );
194
194
</code></pre>
195
195
<h3id="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>
197
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>
198
198
<pre><code>var topics = {};
199
199
@@ -238,7 +238,7 @@ fn2 says: hello world!
238
238
woo! mail!
239
239
*/
240
240
</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>
242
242
<pre><code>// subscribe to the mailArrived notification
243
243
$.Topic( "mailArrived" ).subscribe( fn1 );
244
244
@@ -258,7 +258,7 @@ dfd.done( topic.publish );
258
258
// (eg. waiting on an ajax call to complete) so that
259
259
// messages are only published once the task has actually
0 commit comments