Last active
December 3, 2015 23:35
-
-
Save w3cj/84c193aca1fe4a6916c8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| getUserData().then(function (userData) { | |
| return getUserMessages(userData.id).then(function(userMessages){ | |
| return { userData: userData, userMessages: userMessages } | |
| }); | |
| }).then(function (result) { | |
| return getUserLocation(result.userData.id).then(function(userLocation){ | |
| result.userLocation = userLocation; | |
| return result; | |
| }); | |
| }).then(function(result){ | |
| renderData(result.userData, result.userMessages, result.userLocation) | |
| }); | |
| function getUserData () { | |
| return new Promise(function(resolve, reject){ | |
| var data = {name: "Danny", Age: 26, id: 1211} | |
| //setTimeout roughly simulates an HTTP request. | |
| setTimeout(function () { | |
| resolve(data) | |
| }, 0); | |
| }) | |
| } | |
| function getUserMessages (userId) { | |
| return new Promise(function(resolve, reject){ | |
| var data = [{text: 'hello'}, {text: 'Do you like music?'}, {text: 'Numbers are cool.'}] | |
| //setTimeout roughly simulates an HTTP request. | |
| setTimeout(function () { | |
| resolve(data) | |
| }, 0) | |
| }); | |
| } | |
| function getUserLocation (userId) { | |
| return new Promise(function(resolve, reject){ | |
| var data = {state: 'CO', city: 'Denver'} | |
| //setTimeout roughly simulates an HTTP request. | |
| setTimeout(function () { | |
| resolve(data) | |
| }, 0) | |
| }); | |
| } | |
| function renderData (user, messages, location) { | |
| console.log(user, messages, location) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment