mirror of
https://github.com/zotero/zotero.git
synced 2026-10-05 02:43:38 +00:00
Add Zotero.Utilities.processAsync(sets, callbacks, onDone) -- this can be used from translators to make it easier to correctly chain sets of asynchronous callbacks, since most translators that require multiple callbacks currently do it incorrectly.
This function definition will be automatically prepended to translators sent to older clients from the repo.
This commit is contained in:
parent
303ba34554
commit
78365a095f
1 changed files with 37 additions and 0 deletions
|
|
@ -535,6 +535,42 @@ Zotero.Utilities.prototype.capitalizeTitle = function(string, force) {
|
|||
return string;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Run sets of data through multiple asynchronous callbacks
|
||||
*
|
||||
* Each callback is passed the current set and a callback to call when done
|
||||
*
|
||||
* @param {Object[]} sets Sets of data
|
||||
* @param {Function[]} callbacks
|
||||
* @param {Function} onDone Function to call when done
|
||||
*/
|
||||
Zotero.Utilities.prototype.processAsync = function (sets, callbacks, onDone) {
|
||||
var currentSet;
|
||||
var index = 0;
|
||||
|
||||
var nextSet = function () {
|
||||
if (!sets.length) {
|
||||
onDone();
|
||||
return;
|
||||
}
|
||||
index = 0;
|
||||
currentSet = sets.shift();
|
||||
callbacks[0](currentSet, nextCallback);
|
||||
};
|
||||
var nextCallback = function () {
|
||||
callbacks[index](currentSet, nextCallback);
|
||||
index++;
|
||||
};
|
||||
|
||||
// Add a final callback to proceed to the next set
|
||||
callbacks[callbacks.length] = function () {
|
||||
nextSet();
|
||||
}
|
||||
nextSet();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @class All functions accessible from within Zotero.Utilities namespace inside sandboxed
|
||||
* translators
|
||||
|
|
@ -666,6 +702,7 @@ Zotero.Utilities.Translate.prototype.getItemArray = function(doc, inHere, urlRe,
|
|||
return availableItems;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load a single document in a hidden browser
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue