Last active
October 10, 2017 13:01
-
-
Save dima716/a55b7ab5b5784c4c871c1394e00b926c 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
| const getJSON = data => data.json; | |
| this.shopapiservice.get_locations() | |
| .then(getJSON(response)) | |
| // не увидел где и для чего используется locations ? | |
| .then(() => this.shopapiservice.render_task(this.video_render_task_id)) | |
| .then(response => getJSON(response).videos[0].video_id) | |
| .then(video_id => this.shopapiservice.get_video(video_id)) | |
| .then(response => getJSON(response).picture) | |
| .then(video_thumbnail => this.shopapiservice.create_campaign( | |
| cmp.stripe_adaccount_id, | |
| video_id, | |
| video_thumbnail | |
| ) | |
| ) | |
| .then(getJSON(response)) | |
| .then(result => { | |
| this.localStorageService.set('campaign_id', result.adcampaignId); | |
| this.localStorageService.set('adset_id', result.adsets[0]); | |
| this.localStorageService.set('ad_id', result.ads[0]); | |
| this.router.navigate(['/dashboard']); | |
| }) | |
| .catch(errorHandler(error)) | |
| // То есть основной смысл в том, чтобы использовать цепочки промисов(chaining) | |
| // Идеально, если каждый then умещается в одну строчку | |
| // Таким образом у нас код выглядит более читаемо и лаконично и не "смещается вправо" | |
| // при каждом новом вложенном http вызове, не появляется т.к. называемый callback hell (http://callbackhell.com/) | |
| // Подробнее можно прочитать здесь - http://learn.javascript.ru/promise#цепочки-промисов | |
| // и здесь - https://javascript.info/promise-chaining#example-loadscript |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment