Comparing version 0.0.23 to 0.0.25
@@ -8,8 +8,6 @@ { | ||
"ignore": [ | ||
"**/.*", | ||
"test", | ||
"static", | ||
"spec", | ||
"node_modules", | ||
"bower_components" | ||
"bower_components", | ||
".travis.yml" | ||
], | ||
@@ -16,0 +14,0 @@ "homepage": "https://github.com/vitaly-t/spex", |
@@ -66,33 +66,11 @@ 'use strict'; | ||
values.forEach(function (item, i) { | ||
var err; | ||
while (item instanceof Function) { | ||
try { | ||
item = item.call(self); | ||
} catch (e) { | ||
err = e; | ||
break; | ||
} | ||
} | ||
if (err) { | ||
result[i] = {success: false, result: err}; | ||
$utils.resolve.call(self, item, null, function (data) { | ||
result[i] = data; | ||
check(i, true, data); | ||
}, function (reason) { | ||
result[i] = {success: false, result: reason}; | ||
errors.push(i); | ||
check(i, false, err); | ||
} else { | ||
if ($utils.isPromise(item)) { | ||
item | ||
.then(function (data) { | ||
result[i] = data; | ||
check(i, true, data); | ||
}, function (reason) { | ||
result[i] = {success: false, result: reason}; | ||
errors.push(i); | ||
check(i, false, reason); | ||
}); | ||
} else { | ||
result[i] = item; | ||
check(i, true, item); | ||
} | ||
} | ||
check(i, false, reason); | ||
}); | ||
}); | ||
// TODO: Missing resolve the optional promise returned by the callback; | ||
function check(idx, pass, data) { | ||
@@ -99,0 +77,0 @@ if (cb) { |
@@ -8,3 +8,3 @@ 'use strict'; | ||
// Resolves with {duration, pages, total}; | ||
// Acquires next page via page index + THIS context + previous data; | ||
// Acquires next page via page index + THIS context; | ||
// Provides pages tracking: dest(pageIdx, data) | ||
@@ -21,3 +21,3 @@ | ||
// We need to indicate clearly the nature if failure: | ||
// 1. error or reject from the source {index, error, source=last data passed;}; | ||
// 1. error or reject from the source {index, error;}; | ||
// 2. page rejected (batch returned reject) {index, data=batch reject data}; | ||
@@ -37,2 +37,3 @@ // 3. dest rejected or threw an error {index, error, dest=resolved data passed in}; | ||
function page(source, dest, maxSize) { | ||
if (typeof source !== 'function') { | ||
@@ -46,53 +47,45 @@ throw new Error("Invalid page source."); | ||
var self = this, idx = 0, result = [], start = Date.now(); | ||
var self = this, result = [], start = Date.now(); | ||
/* | ||
return $p(function (resolve, reject) { | ||
function loop() { | ||
var value; | ||
try { | ||
value = factory.call(self, idx); | ||
} catch (e) { | ||
return $p.reject({ | ||
index: idx, | ||
error: e | ||
}); | ||
} | ||
while (value instanceof Function) { | ||
try { | ||
value = value.call(self, idx, request); | ||
} catch (e) { | ||
return $p.reject({ | ||
source: request, | ||
index: idx, | ||
error: e | ||
}); | ||
} | ||
} | ||
if (value === undefined) { | ||
// no more data left in the sequence; | ||
var length = Date.now() - start; | ||
if (track) { | ||
$utils.extend(result, 'duration', length); | ||
} else { | ||
result = { | ||
total: idx, | ||
duration: length | ||
function loop(idx) { | ||
$utils.resolve.call(self, source, [idx], function (value, delayed) { | ||
if (value === undefined) { | ||
// no more pages left; | ||
finish(); | ||
} else { | ||
if (value instanceof Array) { | ||
if (!value.length) { | ||
finish(); | ||
} else { | ||
// carry one; | ||
$utils.batch(value) | ||
.then(function (data) { | ||
}, function (reason) { | ||
reject({ | ||
error: reason, | ||
index: idx, | ||
data: value | ||
}); | ||
}); | ||
} | ||
} else { | ||
reject({ | ||
index: idx, | ||
error: "Invalid data returned" | ||
}); | ||
} | ||
} | ||
} | ||
return $p.resolve(result); | ||
} | ||
if (!$utils.isPromise(value)) { | ||
value = $p.resolve(value); // to avoid direct recursion; | ||
} | ||
return value | ||
.then(function (data) { | ||
request = data; | ||
if (track) { | ||
result.push(data); // accumulate resolved data; | ||
} | ||
var destResult; | ||
// sequence continues; | ||
if (dest) { | ||
var destResult; | ||
try { | ||
destResult = dest.call(self, idx, data); | ||
destResult = dest.call(self, idx, value); | ||
} catch (e) { | ||
return $p.reject({ | ||
reject({ | ||
dest: data, | ||
@@ -102,10 +95,10 @@ index: idx, | ||
}); | ||
return; | ||
} | ||
if (utils.isPromise(destResult)) { | ||
return destResult | ||
if ($utils.isPromise(destResult)) { | ||
destResult | ||
.then(function () { | ||
idx++; | ||
return loop(); | ||
next(true); | ||
}, function (reason) { | ||
return $p.reject({ | ||
reject({ | ||
dest: data, | ||
@@ -116,8 +109,12 @@ index: idx, | ||
}); | ||
} else { | ||
next(delayed); | ||
} | ||
} else { | ||
next(delayed); | ||
} | ||
idx++; | ||
return loop(); | ||
}, function (reason) { | ||
return $p.reject({ | ||
reject({ | ||
source: data, | ||
index: idx, | ||
@@ -127,5 +124,36 @@ error: reason | ||
}); | ||
} | ||
return loop(); | ||
function next(delayed) { | ||
idx++; | ||
if (maxSize && maxSize === idx) { | ||
finish(); | ||
} else { | ||
if (delayed) { | ||
loop(idx); | ||
} else { | ||
$p.resolve() | ||
.then(function () { | ||
loop(idx); | ||
}); | ||
} | ||
} | ||
} | ||
function finish() { | ||
var length = Date.now() - start; | ||
if (track) { | ||
$utils.extend(result, 'duration', length); | ||
} else { | ||
result = { | ||
total: idx, | ||
duration: length | ||
} | ||
} | ||
resolve(result); | ||
} | ||
} | ||
loop(0); | ||
}); | ||
*/ | ||
} | ||
@@ -132,0 +160,0 @@ |
@@ -47,3 +47,3 @@ 'use strict'; | ||
try { | ||
value = value.apply(self, params); | ||
value = params ? value.apply(self, params) : value.call(self); | ||
} catch (e) { | ||
@@ -50,0 +50,0 @@ onError(e); |
{ | ||
"name": "spex", | ||
"version": "0.0.23", | ||
"version": "0.0.25", | ||
"description": "Specialized Promise Extensions", | ||
@@ -10,4 +10,3 @@ "main": "lib/index.js", | ||
"coverage": "istanbul cover ./node_modules/jasmine-node/bin/jasmine-node test", | ||
"doc": "./node_modules/.bin/jsdoc -c jsDoc.json", | ||
"publish": "npm publish && bower register spex git://github.com/vitaly-t/spex.git" | ||
"doc": "./node_modules/.bin/jsdoc -c jsDoc.json" | ||
}, | ||
@@ -14,0 +13,0 @@ "homepage": "https://github.com/vitaly-t/spex", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
30231
613