Обновить getMany. Убрать import

This commit is contained in:
2019-09-10 13:14:33 +03:00
parent 902051e77a
commit 69bbe42d20

View File

@@ -9,15 +9,15 @@ Reporter.prototype.subscribeMany = function(funcs)
} }
} }
murom.getMany = function(urls, completionCallback) murom.getMany = function(items, completionCallback)
{ {
var self = this; var self = this;
var results = new Array(urls.length).fill(null); var results = {};
var count = 0; var count = 0;
function reportCompletion() function reportCompletion()
{ {
if (++count == urls.length) if (++count == items.length)
{ {
if (completionCallback) if (completionCallback)
{ {
@@ -26,18 +26,19 @@ murom.getMany = function(urls, completionCallback)
} }
} }
for (var id in urls) for (var id in items)
{ {
const url = urls[id]; const item = items[id];
const urlId = id; const url = item[0];
murom.get( const name = item[1];
url, var isBinary = (item[2] == "b");
function(contents)
function success(contents)
{ {
results[urlId] = contents; results[name] = contents;
reportCompletion() reportCompletion()
}, }
function(status) function failure(status)
{ {
LOG( LOG(
formatString( formatString(
@@ -48,21 +49,14 @@ murom.getMany = function(urls, completionCallback)
); );
reportCompletion() reportCompletion()
} }
);
}
};
murom.import = function(urls, completionCallback) if (isBinary)
{ {
murom.getMany( murom.getb(url, success, failure);
urls, }
function(contents) else
{ {
for (var id in contents) murom.get(url, success, failure);
{
eval(contents[id]);
} }
completionCallback();
} }
);
}; };