-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add promise support #258
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add promise support #258
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,45 @@ | ||
{ | ||
"name" : "github", | ||
"version" : "0.2.4", | ||
"description" : "NodeJS wrapper for the GitHub API", | ||
"author": "Mike de Boer <[email protected]>", | ||
"contributors": [ | ||
{ "name": "Mike de Boer", "email": "[email protected]" }, | ||
{ "name": "Fabian Jakobs", "email": "[email protected]" } | ||
], | ||
"homepage": "http://github.com/mikedeboer/node-github", | ||
"repository" : { | ||
"type" : "git", | ||
"url" : "http://github.com/mikedeboer/node-github.git" | ||
"name": "github", | ||
"version": "0.2.4", | ||
"description": "NodeJS wrapper for the GitHub API", | ||
"author": "Mike de Boer <[email protected]>", | ||
"contributors": [ | ||
{ | ||
"name": "Mike de Boer", | ||
"email": "[email protected]" | ||
}, | ||
"engine" : { | ||
"node": ">=0.4.0" | ||
}, | ||
"dependencies": { | ||
"mime": "^1.2.11" | ||
}, | ||
"devDependencies": { | ||
"async": "^0.9.0", | ||
"oauth": "~0.9.7", | ||
"optimist": "~0.6.0", | ||
"mocha": "~1.13.0" | ||
}, | ||
"main" : ".", | ||
"scripts": { | ||
"test": "node ./test/all.js" | ||
}, | ||
"license": "MIT", | ||
"licenses": [{ | ||
"type": "The MIT License", | ||
"url": "http://www.opensource.org/licenses/mit-license.php" | ||
}] | ||
{ | ||
"name": "Fabian Jakobs", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"homepage": "http://github.com/mikedeboer/node-github", | ||
"repository": { | ||
"type": "git", | ||
"url": "http://github.com/mikedeboer/node-github.git" | ||
}, | ||
"engine": { | ||
"node": ">=0.4.0" | ||
}, | ||
"dependencies": { | ||
"es6-promise": "^2.2.0", | ||
"mime": "^1.2.11" | ||
}, | ||
"devDependencies": { | ||
"async": "^0.9.0", | ||
"oauth": "~0.9.7", | ||
"optimist": "~0.6.0", | ||
"mocha": "~1.13.0" | ||
}, | ||
"main": ".", | ||
"scripts": { | ||
"test": "node ./test/all.js" | ||
}, | ||
"license": "MIT", | ||
"licenses": [ | ||
{ | ||
"type": "The MIT License", | ||
"url": "http://www.opensource.org/licenses/mit-license.php" | ||
} | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/*jslint browser: true, node: true, maxlen: 128 */ | ||
/*global self */ | ||
|
||
"use strict"; | ||
|
||
var globalObject, hasPromiseSupport; | ||
|
||
function isFunction(x) { | ||
return typeof x === "function"; | ||
} | ||
|
||
// Seek the global object | ||
if (global !== undefined) { | ||
globalObject = global; | ||
} else if (window !== undefined && window.document) { | ||
globalObject = window; | ||
} else { | ||
globalObject = self; | ||
} | ||
|
||
hasPromiseSupport = | ||
|
||
globalObject.hasOwnProperty("Promise") && | ||
|
||
// Some of these methods are missing from | ||
// Firefox/Chrome experimental implementations | ||
globalObject.Promise.hasOwnProperty("resolve") && | ||
globalObject.Promise.hasOwnProperty("reject") && | ||
globalObject.Promise.hasOwnProperty("all") && | ||
globalObject.Promise.hasOwnProperty("race") && | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are you testing for all these methods on
EDIT: Drop lines 25-30 |
||
|
||
// Older version of the spec had a resolver object | ||
// as the arg rather than a function | ||
(function () { | ||
/*jslint unparam: true */ | ||
var resolve, p; | ||
p = new globalObject.Promise(function (r) { resolve = r; }); | ||
return isFunction(resolve); | ||
}()); | ||
|
||
// Export the native Promise implementation if it looks like it matches | ||
// the specificiation. Otherwise, return the es6-promise implementation | ||
// by @jaffathecake. | ||
if (hasPromiseSupport) { | ||
module.exports = globalObject.Promise; | ||
} else { | ||
module.exports = require("es6-promise").Promise; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd prefer bluebird. Better performance, and it's what all the cool kids are using. |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You do not need any of these tests. Just go ahead and use
global
directly. It has existed in node since the beginning.browserify
sets the value ofglobal
towindow
anyways, so it will exist even in the browser.