不要怂,就是干,撸起袖子干!

Commit 37c176a3 by Felix Becker Committed by Mick Hansen

ES6 refactor of promise.js (#6081)

let, const, arrow functions, export default
1 parent 93146f73
Showing with 8 additions and 6 deletions
'use strict';
var Promise = require('bluebird')
, shimmer = require('shimmer');
const Promise = require('bluebird');
const shimmer = require('shimmer');
// functionName: The Promise function that should be shimmed
// fnArgs: The arguments index that should be CLS enabled (typically all callbacks). Offset from last if negative
function shimCLS(object, functionName, fnArgs){
shimmer.wrap(object, functionName, function(fn) {
shimmer.wrap(object, functionName, fn => {
return function () {
if (Promise.Sequelize && Promise.Sequelize.cls) {
var ns = Promise.Sequelize.cls;
for(var x=0; x<fnArgs.length; x++) {
var argIndex = fnArgs[x] < 0 ? arguments.length + fnArgs[x] : fnArgs[x];
const ns = Promise.Sequelize.cls;
for(let x = 0; x < fnArgs.length; x++) {
const argIndex = fnArgs[x] < 0 ? arguments.length + fnArgs[x] : fnArgs[x];
if ( argIndex < arguments.length && typeof arguments[argIndex] === 'function' ) {
arguments[argIndex] = ns.bind( arguments[argIndex] );
}
......@@ -51,3 +51,5 @@ shimCLS(Promise.prototype, 'tap', [0]);
shimCLS(Promise.prototype, 'done', [0, 1]);
module.exports = Promise;
module.exports.Promise = Promise;
module.exports.default = Promise;
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!