result-core
Advanced tools
Comparing version 1.1.1 to 1.1.2
32
index.js
@@ -39,3 +39,3 @@ | ||
this.value = value | ||
run(this._onValue, value, this) | ||
this._onValue && run(this, this._onValue) | ||
} | ||
@@ -56,3 +56,3 @@ return this | ||
this.value = reason | ||
run(this._onError, reason, this) | ||
this._onError && run(this, this._onError) | ||
} | ||
@@ -66,3 +66,2 @@ return this | ||
* @param {Function} fns | ||
* @param {Any} value | ||
* @param {ctx} Result | ||
@@ -72,7 +71,6 @@ * @api private | ||
function run(fns, value, ctx){ | ||
if (!fns) return | ||
if (typeof fns == 'function') runFn(fns, value, ctx) | ||
function run(ctx, fns){ | ||
if (typeof fns == 'function') runFn(ctx, fns) | ||
else for (var i = 0, len = fns.length; i < len;) { | ||
runFn(fns[i++], value, ctx) | ||
runFn(ctx, fns[i++]) | ||
} | ||
@@ -97,3 +95,2 @@ } | ||
* @param {Function} fn | ||
* @param {Any} value | ||
* @param {Result} ctx | ||
@@ -103,5 +100,5 @@ * @api private | ||
function runFn(fn, value, ctx){ | ||
try { fn.call(ctx, value) } | ||
catch (e) { nextTick(function(){ throw e }) } | ||
function runFn(ctx, fn){ | ||
try { fn.call(ctx, ctx.value) } | ||
catch (e) { rethrow(e) } | ||
} | ||
@@ -120,10 +117,11 @@ | ||
case 'pending': | ||
if (onValue) listen(this, '_onValue', onValue) | ||
if (onError) listen(this, '_onError', onError) | ||
onValue && listen(this, '_onValue', onValue) | ||
listen(this, '_onError', onError || rethrow) | ||
break | ||
case 'done': | ||
runFn(onValue, this.value, this) | ||
onValue && runFn(this, onValue) | ||
break | ||
case 'fail': | ||
runFn(onError, this.value, this) | ||
if (onError) runFn(this, onError) | ||
else rethrow(this.value) | ||
break | ||
@@ -134,2 +132,6 @@ } | ||
function rethrow(error){ | ||
nextTick(function(){ throw error }) | ||
} | ||
/** | ||
@@ -136,0 +138,0 @@ * add a listener |
{ | ||
"name": "result-core", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"description": "minimal result reification", | ||
@@ -10,3 +10,2 @@ "dependencies": { | ||
}, | ||
"devDependencies": {}, | ||
"repository": { | ||
@@ -21,3 +20,4 @@ "type": "git", | ||
"author": "Jake Rosoman", | ||
"license": "MIT" | ||
"license": "MIT", | ||
"files": [ "index.js" ] | ||
} |
5770
3
121