es6-promise

Parse Nested JSON Using Axios and Async/Await

安稳与你 提交于 2020-01-25 01:01:07
问题 I am trying to fetch data from an api which should return a json object with an array of recipes. I am using React hooks on the front end and Axios to perform the request. The hook runs but I get an error while trying to access the json array from the response. Here's the sample api response: { count: 30, recipes: [objects, ... 29] } and my code to get the recipe response: const fetchRecipes = async () => { try { const recipeData = await Axios.get(api); console.log(recipeData); const recipes

Catch axios requests in different files / functions

前提是你 提交于 2020-01-24 22:55:12
问题 I use HTTP requests to get data for my Vue.js application. I have one file called Api.js with the base axios instance: export default () => { return axios.create({ baseURL: apiURL, headers: { Authorization: `JWT ${store.state.token}` } }) } than I have a file called service.js , which contains the functions for the different endpoints: export default { status() { return Api().get('status/') } } In the .vue file I call the method like that. created() { Service.status() .then(response => { //

Angular2 Jsonp call with promise

浪子不回头ぞ 提交于 2020-01-24 12:42:04
问题 At the moment I'm looking into Angular2-alpha45. In cause of a CORS-Problem I have to make a JSONP-Call. The problem is, that the call takes some time and i don't know how to wrap the answer into a promise. I can wrap a regular http.get into a promise, but because of CORS this isn't a solution for my needs. Working http.get example: import {Jsonp, Http} from 'angular2/http'; // works this.getPromise().then(result => { console.dir(result) }); getPromise(): Promise<Array> { return this.http

Angular2 Jsonp call with promise

╄→гoц情女王★ 提交于 2020-01-24 12:40:16
问题 At the moment I'm looking into Angular2-alpha45. In cause of a CORS-Problem I have to make a JSONP-Call. The problem is, that the call takes some time and i don't know how to wrap the answer into a promise. I can wrap a regular http.get into a promise, but because of CORS this isn't a solution for my needs. Working http.get example: import {Jsonp, Http} from 'angular2/http'; // works this.getPromise().then(result => { console.dir(result) }); getPromise(): Promise<Array> { return this.http

JavaScript Promises: Executing Promises Sequentially

◇◆丶佛笑我妖孽 提交于 2020-01-23 07:49:46
问题 In an attempt to understand promises more clearly, i have been reading up a few very interesting articles on the same. I came across the following code which works perfectly for executing promises sequentially. But i am not able to understand how it works. function doFirstThing(){ return new Promise(function(resolve,reject){ setTimeout(()=>{ resolve(1); },1000) }) } function doSecondThing(res){ return new Promise(function(resolve,reject){ setTimeout(()=>{ resolve(res + 1); },1000) }) }

JavaScript Promises: Executing Promises Sequentially

浪尽此生 提交于 2020-01-23 07:48:35
问题 In an attempt to understand promises more clearly, i have been reading up a few very interesting articles on the same. I came across the following code which works perfectly for executing promises sequentially. But i am not able to understand how it works. function doFirstThing(){ return new Promise(function(resolve,reject){ setTimeout(()=>{ resolve(1); },1000) }) } function doSecondThing(res){ return new Promise(function(resolve,reject){ setTimeout(()=>{ resolve(res + 1); },1000) }) }

Axios get request gets all the data, unless I set state in the .then method in which case the data is erratic

╄→гoц情女王★ 提交于 2020-01-16 19:45:31
问题 So I'm having an issue in my React code. I have a parent component that renders a child component, which is a container with a few banner images. In the parent component (let's call it Parent ), I make an axios GET request to my API to fetch the data I need to pass as props to Child . I make this call inside the Parent 's componentDidMount() , which also houses some more separate axios calls. axios.get(`${config.host.api}/banners`).then(res => { let offban = res.data.trend; console.log(offban

Is this the correct way of returning a ES6 promise in firebase cloud functions?

[亡魂溺海] 提交于 2020-01-16 16:26:30
问题 I have a cloud function similar to this: exports.verifyEmail = functions.https.onCall((data, context) => { // data contains session_id (doc id where otp is stored) and otp return new Promise((resolve, reject) => { admin.firestore().collection('verification').doc(data.session_id).get().then(doc => { if(data.otp === doc.data().otp){ return resolve() } else { return reject({message: 'OTP did not match'}) } }).catch(err => { return reject({message: err.message}) }) }) }) I read this method on a

Is this the correct way of returning a ES6 promise in firebase cloud functions?

随声附和 提交于 2020-01-16 16:26:02
问题 I have a cloud function similar to this: exports.verifyEmail = functions.https.onCall((data, context) => { // data contains session_id (doc id where otp is stored) and otp return new Promise((resolve, reject) => { admin.firestore().collection('verification').doc(data.session_id).get().then(doc => { if(data.otp === doc.data().otp){ return resolve() } else { return reject({message: 'OTP did not match'}) } }).catch(err => { return reject({message: err.message}) }) }) }) I read this method on a

Get data from a Promise

天涯浪子 提交于 2020-01-16 16:24:48
问题 I'm working with Tabletop.js to get data from my Google Spreadsheet. In the function, I've invoked a Promise. The only problem is I can't get the data(which is an Array) out of the function. I have the following code: function getData() { return new Promise((resolve) => { Tabletop.init({key: publicSpreadsheetUrl, callback: showInfo, simpleSheet: true}) resolve('Done'); }) } let arrayWithData = []; function showInfo (data, tabletop) { console.log('showInfo active'); arrayWithData.push(...data)