CodeReview 30102

http://codereview.stackexchange.com/questions/30102/can-this-promise-be-chained-more-cleanly

by Tomek

HTML

<script src="http://rsvpjs-builds.s3.amazonaws.com/rsvp-latest.js"></script>

JavaScript

var mockXML = {
    documentElement: "test",
    evaluate: function(){
        console.log("evaluating", arguments);
        return "abc123";
    }
}, XPathResult = {
    FIRST_ORDERED_NODE_TYPE: "test"
};

//code goes here
new RSVP.Promise(function (resolve) {
    if (TokenData) {
        resolve(TokenData);
    } else {
        LoadURIPromise(TokenURL).then(function (xmlDoc) {
            TokenData = xmlDoc.evaluate(
                '/root/theToken',
            xmlDoc.documentElement,
            null,
            XPathResult.FIRST_ORDERED_NODE_TYPE,
            null).singleNodeValue.textContent;
            resolve(TokenData);
        });
    }
}).then(function (token) {
    //Use Token here
    console.info(token);
});