Make asyncForEach available globally to reduce code duplication

This commit is contained in:
Johannes Zellner
2018-04-02 11:35:02 +02:00
parent c329541708
commit 75eae0d8ec
5 changed files with 25 additions and 71 deletions

View File

@@ -16,6 +16,22 @@ if (search.accessToken) {
window.location.search = encodeURIComponent(Object.keys(search).map(function (key) { return key + '=' + search[key]; }).join('&'));
}
// poor man's async in the global namespace
function asyncForEach(items, handler, callback) {
var cur = 0;
if (items.length === 0) return callback();
(function iterator() {
handler(items[cur], function (error) {
if (error) return callback(error);
if (cur >= items.length-1) return callback();
++cur;
iterator();
});
})();
}
// create main application module
var app = angular.module('Application', ['ngFitText', 'ngRoute', 'ngAnimate', 'ngSanitize', 'angular-md5', 'base64', 'slick', 'ui-notification', 'ui.bootstrap', 'ui.bootstrap-slider', 'ngTld', 'ui.multiselect']);