catberry
Version:
Catberry is an isomorphic framework for building universal front-end apps using components, Flux architecture and progressive rendering.
27 lines (23 loc) • 586 B
JavaScript
;
module.exports = {
/**
* Converts a method with a callback to the method that returns a promise.
* @param {Function} methodWithCallback The method with a callback.
* @returns {Function} The method that returns a promise.
*/
callbackToPromise: methodWithCallback => {
/* eslint no-invalid-this:0 */
return function(...args) {
return new Promise((fulfill, reject) => {
args.push((error, result) => {
if (error) {
reject(error);
return;
}
fulfill(result);
});
methodWithCallback.apply(this, args);
});
};
}
};