Created
July 5, 2015 10:23
-
-
Save maritz/8ed6e650212a536c7b46 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
var someResourcePromise = sometingAsync.get('someResource'); // this returns a promise which when resolved will return an object { more: { id: 123 } } | |
var doSomethingAsyncWithResult = function (id) { | |
return somethingAsync.get('moreResources', id); | |
} | |
someResourcePromise.then(doSomethingAsyncWithResult); // of course doenst work becuase the actual id would be in id.more.id | |
// is there some way in Q instead of then() to basically extract a property from a previous fulfillment? | |
// maybe like | |
someResourcePromise.thenExtract(dosomethingAsyncWithResult, "id.more.id"); | |
// the idea is that the doSomethingAsyncWithResult should be unaware of the structure of the someResourcePromise fulfillment structure | |
// sure, i could define an actual function inside then() and extract the property and then call somethingAsncy.get('modeResources') | |
// but that creates lots of little extra functions that could be abstracted away |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment