Finally finished giant ES6 refactor

This commit is contained in:
Jonathan Cremin 2015-08-20 23:22:57 +01:00
parent c6d48cc424
commit 03e2666958
39 changed files with 553 additions and 635 deletions

View file

@ -4,25 +4,19 @@ import fs from 'fs';
var services = [];
fs.readdirSync(path.join(__dirname, 'services')).forEach(function(file) {
var service = require(path.join(__dirname, 'services', file));
const service = require(path.join(__dirname, 'services', file));
if (service.search) {
services.push(service);
}
});
module.exports = function(url) {
var matchedService;
services.some(function(service) {
matchedService = service.match(url) ? service : null;
return matchedService;
});
if (matchedService) {
return matchedService.parseUrl(url).timeout(10000).then(function(result) {
return matchedService.lookupId(result.id, result.type).then(function(item) {
return item;
});
});
export default function* (url) {
let matchedService;
for (let service of services) {
matchedService = yield service.match(url);
if (matchedService) {
const result = yield service.parseUrl(url);
return yield service.lookupId(result.id, result.type);
}
}
};