Created
July 12, 2016 06:17
-
-
Save avimar/1fa4f276d98fb3a5b1dbfdbd423c0e64 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//using a function-scope `data` variable to save the data | |
function getData(respondentId) { | |
var data={}; | |
return Respondent.findById(respondentId) | |
.then(respondent => { | |
data.respondent = respondent; | |
return Box.findById(respondent.box_id) | |
}) | |
.then(box => { | |
data.box = box | |
return User.findById(box.owned_by) | |
}) | |
.then(user => { | |
data.user = user; | |
return data;}) | |
} | |
//using bluebird-specific `spread`/implicit `all()` | |
function getData(respondentId) { | |
return Respondent.findById(respondentId) | |
.then(respondent => { | |
return [respondent,Box.findById(respondent.box_id)]; | |
}) | |
.spread(respondent, box => { | |
return [respondent,box, User.findById(box.owned_by)]; | |
}) | |
.spread(respondent, box, user=>({ user, respondent, box })); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment