Created
April 26, 2017 17:07
-
-
Save daslicht/066d49689b3534465d7d22f312d4fffa to your computer and use it in GitHub Desktop.
Observables vs Promises
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
/** | |
* Promises | |
*/ | |
let selectedProduct = this.client.api( 'product', 'get', {id: product_id} ); | |
let metadata = this.client.listMetafieldByProduct( product_id ); | |
Promise.all([ selectedProduct , metadata ]) | |
.then(( result) => { | |
console.log('result:', result); | |
}) | |
/** | |
* Observables | |
*/ | |
let selectedProduct = Observable.forkJoin( | |
this.client.api( 'product', 'get', {id: product_id} ), | |
this.client.listMetafieldByProduct( product_id ), | |
); | |
selectedProduct.subscribe( (result) =>{ | |
console.log('result:', result); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment