在量角器中简化嵌套承诺

Bow*_*er2 4 javascript nested promise angularjs protractor

我的画布尺寸和位置未知.我想基于量角器中画布的尺寸和位置来模拟单击特定坐标.

以下工作,但相当繁琐:

 var canvas = element(by.id("canvas")); 

 canvas.getCssValue("left").then(function (left) {

            canvas.getCssValue("top").then(function (top) {

                canvas.getCssValue("width").then(function(oldWidth) {

                        canvas.getCssValue("height").then(function (oldHeight) {

                        // some code that uses left, top, oldWidth and oldHeight together

                                })
                            })

                        })
                    }
                )
            })
        })
Run Code Online (Sandbox Code Playgroud)

是否有更优雅的方式一次性使用所有这些承诺?我真的想做类似以下的事情:

var width = canvas.getCssValue("width");
var height = canvas.getCssValue("height");

var left = canvas.getCssValue("left");
var top = canvas.getCssValue("top");

//code that uses these variables. 
Run Code Online (Sandbox Code Playgroud)

但当然,如果违背承诺的性质.谢谢你的帮助.

Esa*_*ija 5

function spreader(fn) {
    return function(arr) {
        return fn.apply(this, arr);
    }
}

var width = canvas.getCssValue("width");
var height = canvas.getCssValue("height");

var left = canvas.getCssValue("left");
var top = canvas.getCssValue("top");

protractor.promise.all(width, height, left, top)
    .then(spreader(function(width, height, left, top) {
    // Use width, height, left, top as values
}));
Run Code Online (Sandbox Code Playgroud)