Comparing version 3.4.0 to 3.4.1
/** @license MIT License (c) copyright 2010-2014 original author or authors */ | ||
/** @author Brian Cavalier */ | ||
/** @author John Hann */ | ||
/** | ||
* Licensed under the MIT License at: | ||
* http://www.opensource.org/licenses/mit-license.php | ||
* | ||
* @author: Brian Cavalier | ||
* @author: John Hann | ||
*/ | ||
(function(define) { 'use strict'; | ||
@@ -17,8 +11,2 @@ define(function(require) { | ||
return { | ||
apply: apply, | ||
call: call, | ||
lift: lift | ||
}; | ||
/** | ||
@@ -32,3 +20,3 @@ * Lift a generator to create a function that can suspend and | ||
return function() { | ||
return apply(generator, arguments); | ||
return run(generator, this, arguments); | ||
}; | ||
@@ -47,3 +35,4 @@ } | ||
function call(generator /*x, y, z...*/) { | ||
return apply(generator, slice.call(arguments, 1)); | ||
/*jshint validthis:true*/ | ||
return run(generator, this, slice.call(arguments, 1)); | ||
} | ||
@@ -56,2 +45,3 @@ | ||
* @param {function} generator | ||
* @param {Array} args arguments with which to initialize the generator | ||
* @returns {Promise} promise for the ultimate value returned | ||
@@ -62,27 +52,48 @@ * from the generator. | ||
/*jshint validthis:true*/ | ||
var iterator = generator.apply(this, args); | ||
return run(generator, this, args || []); | ||
} | ||
return next(); | ||
/** | ||
* Helper to initiate the provided generator as a coroutine | ||
* @returns {*} | ||
*/ | ||
function run(generator, thisArg, args) { | ||
var stepper = new Stepper(next, error, generator.apply(thisArg, args)); | ||
function next(x) { | ||
return step('next', x); | ||
} | ||
return stepper.step('next', void 0); | ||
function fail(e) { | ||
return step('throw', e); | ||
function next(x) { return stepper.step('next', x); } | ||
function error(e) { return stepper.step('throw', e); } | ||
} | ||
/** | ||
* Manages the process of stepping the provided iterator | ||
* @constructor | ||
*/ | ||
function Stepper(next, error, iterator) { | ||
this.next = next; | ||
this.error = error; | ||
this.iterator = iterator; | ||
} | ||
Stepper.prototype.step = function(action, x) { | ||
try { | ||
return this._continue(action, x); | ||
} catch (e) { | ||
return when.reject(e); | ||
} | ||
}; | ||
function step(action, x) { | ||
var result; | ||
Stepper.prototype._continue = function(action, x) { | ||
var result = this.iterator[action](x); | ||
return result.done ? result.value : when(result.value, this.next, this.error); | ||
}; | ||
try { | ||
result = iterator[action](x); | ||
} catch (e) { | ||
return when.reject(e); | ||
} | ||
return { | ||
lift: lift, | ||
call: call, | ||
apply: apply | ||
}; | ||
return result.done ? result.value : when(result.value, next, fail); | ||
} | ||
} | ||
}); | ||
}(typeof define === 'function' && define.amd ? define : function(factory) { module.exports = factory(require); })); |
@@ -73,8 +73,7 @@ /** @license MIT License (c) copyright 2010-2014 original author or authors */ | ||
if(typeof handler !== 'function') { | ||
// Optimization: result will not change, return same promise | ||
return this; | ||
} | ||
handler = isolate(handler, this); | ||
return this.then(handler, handler); | ||
var isolated = isolate(handler); | ||
return this.then(isolated, isolated)['yield'](this); | ||
}; | ||
@@ -136,13 +135,9 @@ | ||
// prevent argument passing to f and ignore return value | ||
function isolate(f, x) { | ||
function isolate(f) { | ||
return function() { | ||
f.call(this); | ||
return x; | ||
return f.call(this); | ||
}; | ||
} | ||
// function noop() {} | ||
}); | ||
}(typeof define === 'function' && define.amd ? define : function(factory) { module.exports = factory(); })); |
{ | ||
"name": "when", | ||
"version": "3.4.0", | ||
"version": "3.4.1", | ||
"description": "A lightweight Promises/A+ and when() implementation, plus other async goodies.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -8,3 +8,3 @@ /** @license MIT License (c) copyright 2010-2014 original author or authors */ | ||
* @author John Hann | ||
* @version 3.4.0 | ||
* @version 3.4.1 | ||
*/ | ||
@@ -11,0 +11,0 @@ (function(define) { 'use strict'; |
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
143852
4280