daily pastebin goal
34%
SHARE
TWEET

Untitled

a guest Jan 23rd, 2018 43 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Makes sequential getJSON requests, passing the processed results from the
  2. // previous request to the next request. seedData is optional.
  3. var chainedGetJSON = function(requests, seedData) {
  4.   var seed = $.Deferred(),
  5.       finalPromise;
  6.  
  7.   finalPromise = requests.reduce(function(promise, request) {
  8.     return promise.pipe(function(input) {
  9.       return $.getJSON(request.url(input)).pipe(function(json) {
  10.         return request.process(json, input);
  11.       });
  12.     });
  13.   }, seed.promise());
  14.  
  15.   // Start the chain
  16.   seed.resolve(seedData);
  17.  
  18.   return finalPromise;
  19. };
RAW Paste Data
Top