Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Add non ajax example.

  • Loading branch information...
commit cde6b644d49802f0fdd5fe6b4d877c18280fbcee 1 parent 0ce8e84
Patrick Berkeley authored November 07, 2012

Showing 1 changed file with 21 additions and 3 deletions. Show diff stats Hide diff stats

  1. 24  index.html
24  index.html
@@ -165,7 +165,7 @@ <h1 class='fragment'>Give me something better.</h1>
165 165
         </section>
166 166
 				<section>
167 167
           <section>
168  
-            <h1>The Writers</h1>
  168
+            <h1>The Changers</h1>
169 169
           </section>
170 170
           <section>
171 171
             <h2>resolve()</h2>
@@ -211,7 +211,7 @@ <h1 class='fragment'>Give me something better.</h1>
211 211
         </section>
212 212
 				<section>
213 213
           <section>
214  
-            <h1>The Readers</h1>
  214
+            <h1>The Responders</h1>
215 215
           </section>
216 216
           <section>
217 217
             <h2>done()</h2>
@@ -344,19 +344,37 @@ <h1 class='fragment'>Give me something better.</h1>
344 344
   });
345 345
             </code></pre>
346 346
           </section>
  347
+          <section>
  348
+            <h2>Create your own deferred</h2>
  349
+            <pre><code>
  350
+  function showSpinner(){
  351
+    var deferred = $.Deferred();
  352
+    $('#spinner').fadeIn(1000, deferred.resolve);
  353
+    return deferred.promise();
  354
+  }
  355
+  function disableInputs(){ /* Disable form, return promise */ }
  356
+  function postData(){ return $.post('api/'); }
  357
+
  358
+  $.when(showSpinner, disableInputs, postData)
  359
+    .done(function() { /* Clear form */ })
  360
+    .fail(function() { /* Don't clear form, show error */ })
  361
+    .always(function() { /* Hide spinner, re-enable form */ });
  362
+            </code></pre>
  363
+          </section>
347 364
         </section>
348 365
 
349 366
 				<section>
350 367
           <section>
351 368
             <h1>Summary</h1>
352 369
             <ul>
353  
-              <li class='fragment'>Really good when you need to guarantee something else has completed before proceeding, either one after another or all together.</li>
  370
+              <li class='fragment'>Use a deferred when you need to guarantee something has completed before proceeding.</li>
354 371
               <li class='fragment'>Improves code composition:
355 372
                 <ul>
356 373
                   <li class='fragment'>flat</li>
357 374
                   <li class='fragment'>decoupled</li>
358 375
                 </ul>
359 376
               </li>
  377
+              <li class='fragment'>Good for AJAX and non-AJAX i.e., anything async.</li>
360 378
             </ul>
361 379
           </section>
362 380
 				</section>

0 notes on commit cde6b64

Please sign in to comment.
Something went wrong with that request. Please try again.