Comparing version 0.7.3-0 to 0.7.4-0
25
API.md
@@ -631,3 +631,28 @@ #API Reference | ||
**Tip:** | ||
When `Promise.spawn` is called as a method of an object, that object becomes the receiver of the generator function too. | ||
```js | ||
function ChatRoom(roomId) { | ||
this.roomId = roomId | ||
} | ||
ChatRoom.prototype.spawn = Promise.spawn; | ||
ChatRoom.prototype.addUser = function( userId ) { | ||
return this.spawn(function* () { | ||
var isBanned = yield chatStore.userIsBannedForRoom(this.roomId, userId); | ||
if (isBanned) { | ||
throw new ChatError("You have been banned from this room"); | ||
} | ||
return chatStore.addUserToRoom(this.roomId, userId); | ||
}); | ||
}; | ||
var room = new ChatRoom(1); | ||
room.addUser(2); | ||
``` | ||
In the above example, all the methods of `ChatRoom` can avoid the `var self = this` prologue and just use `this` normally inside the generator. | ||
#####`Promise.noConflict()` -> `Object` | ||
@@ -634,0 +659,0 @@ |
{ | ||
"name": "bluebird", | ||
"description": "Full featured Promises/A+ implementation with exceptionally good performance", | ||
"version": "0.7.3-0", | ||
"version": "0.7.4-0", | ||
"keywords": [ | ||
@@ -6,0 +6,0 @@ "promise", |
@@ -0,1 +1,6 @@ | ||
<a href="http://promisesaplus.com/"> | ||
<img src="http://promisesaplus.com/assets/logo-small.png" alt="Promises/A+ logo" | ||
title="Promises/A+ 1.0 compliant" align="right" /> | ||
</a> | ||
#Introduction | ||
@@ -2,0 +7,0 @@ |
var PromiseSpawn = (function() { | ||
function PromiseSpawn( generatorFunction, caller ) { | ||
var haveEs6Generators = (function(){ | ||
try { | ||
/* jshint nonew: false */ | ||
new Function("(function*(){})"); | ||
return true; | ||
} | ||
catch(e) { | ||
return false; | ||
} | ||
})(); | ||
function PromiseSpawn( generatorFunction, receiver, caller ) { | ||
this._resolver = Promise.pending( caller ); | ||
this._generatorFunction = generatorFunction; | ||
this._receiver = receiver; | ||
this._generator = void 0; | ||
this._caller = caller; | ||
} | ||
@@ -18,4 +29,5 @@ var method = PromiseSpawn.prototype; | ||
ASSERT( typeof this._generatorFunction === "function" ); | ||
this._generator = this._generatorFunction(); | ||
this._generatorFunction = void 0; | ||
this._generator = this._generatorFunction.call( this._receiver ); | ||
this._receiver = | ||
this._generatorFunction = void 0; | ||
this._next( void 0, caller ); | ||
@@ -73,3 +85,5 @@ }; | ||
PromiseSpawn.isSupported = | ||
new Function("return " + (haveEs6Generators)); | ||
return PromiseSpawn;})(); |
@@ -848,3 +848,12 @@ var Promise = (function() { | ||
Promise.spawn = function Promise$Spawn( generator ) { | ||
var spawn = new PromiseSpawn( generator, Promise.spawn ); | ||
if( typeof generator !== "function" ) { | ||
throw new TypeError( "generator must be a function" ); | ||
} | ||
if( !PromiseSpawn.isSupported() ) { | ||
var defer = Promise.pending( Promise.spawn ); | ||
defer.reject( new Error( "Attempting to use Promise.spawn "+ | ||
"without generator support" )); | ||
return defer.promise; | ||
} | ||
var spawn = new PromiseSpawn( generator, this, Promise.spawn ); | ||
var ret = spawn.promise(); | ||
@@ -851,0 +860,0 @@ spawn._run( Promise.spawn ); |
Sorry, the diff of this file is too big to display
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
222804
5503
268