Skip to content

Instantly share code, notes, and snippets.

@daslicht
Created April 26, 2017 17:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daslicht/066d49689b3534465d7d22f312d4fffa to your computer and use it in GitHub Desktop.
Save daslicht/066d49689b3534465d7d22f312d4fffa to your computer and use it in GitHub Desktop.
Observables vs Promises
/**
* 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