aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorDan Finlay <dan@danfinlay.com>2016-11-29 09:27:20 +0800
committerDan Finlay <dan@danfinlay.com>2016-11-29 09:27:20 +0800
commit9e764b193517c935fa04d4722357cb48abcfb2a2 (patch)
tree3a94636ea384252118eb04cf42a7c11c7fc6cea4 /app
parent80e76b45ee67900b5a60da1ddcd8b310f1e92413 (diff)
downloadtangerine-wallet-browser-9e764b193517c935fa04d4722357cb48abcfb2a2.tar
tangerine-wallet-browser-9e764b193517c935fa04d4722357cb48abcfb2a2.tar.gz
tangerine-wallet-browser-9e764b193517c935fa04d4722357cb48abcfb2a2.tar.bz2
tangerine-wallet-browser-9e764b193517c935fa04d4722357cb48abcfb2a2.tar.lz
tangerine-wallet-browser-9e764b193517c935fa04d4722357cb48abcfb2a2.tar.xz
tangerine-wallet-browser-9e764b193517c935fa04d4722357cb48abcfb2a2.tar.zst
tangerine-wallet-browser-9e764b193517c935fa04d4722357cb48abcfb2a2.zip
Fix nodeify
Diffstat (limited to 'app')
-rw-r--r--app/scripts/lib/nodeify.js68
1 files changed, 13 insertions, 55 deletions
diff --git a/app/scripts/lib/nodeify.js b/app/scripts/lib/nodeify.js
index f48df34ef..56b793852 100644
--- a/app/scripts/lib/nodeify.js
+++ b/app/scripts/lib/nodeify.js
@@ -1,59 +1,17 @@
-/* NODEIFY
- * Modified from original npm package "nodeify"
- * https://github.com/then/nodeify
- *
- * Removed Promise dependency, to only support
- * native Promises and reduce bundle size.
- */
-
-var isPromise = require('is-promise')
-
-var nextTick
-if (typeof setImmediate === 'function') nextTick = setImmediate
-else if (typeof process === 'object' && process && process.nextTick) nextTick = process.nextTick
-else nextTick = function (cb) { setTimeout(cb, 0) }
-
-module.exports = nodeify
-function nodeify(promise, cb) {
- if (typeof cb !== 'function') return promise
- return promise
- .then(function (res) {
- nextTick(function () {
- cb(null, res)
- })
- }, function (err) {
- nextTick(function () {
- cb(err)
- })
- })
-}
-function nodeifyThis(cb) {
- return nodeify(this, cb)
-}
-
-nodeify.extend = extend
-nodeify.Promise = NodeifyPromise
-
-function extend(prom) {
- if (prom && isPromise(prom)) {
- prom.nodeify = nodeifyThis
- var then = prom.then
- prom.then = function () {
- return extend(then.apply(this, arguments))
+module.exports = function (promiseFn) {
+ return function () {
+ var args = []
+ for (var i = 0; i < arguments.length - 1; i++) {
+ args.push(arguments[i])
}
- return prom
- } else if (typeof prom === 'function') {
- prom.prototype.nodeify = nodeifyThis
- }
-}
+ var cb = arguments[arguments.length - 1]
-function NodeifyPromise(fn) {
- if (!(this instanceof NodeifyPromise)) {
- return new NodeifyPromise(fn)
+ return promiseFn.apply(this, args)
+ .then(function (result) {
+ cb(null, result)
+ })
+ .catch(function (reason) {
+ cb(reason)
+ })
}
- Promise.call(this, fn)
- extend(this)
}
-
-NodeifyPromise.prototype = Object.create(Promise.prototype)
-NodeifyPromise.prototype.constructor = NodeifyPromise