How to use the axios.spread function in axios

To help you get started, weโ€™ve selected a few axios examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github egovernments / egov-services / web / react-pgr-web / src / api / api.js View on Github external
getAll: (arrayOfRequest) => {
        return instance.all(arrayOfRequest).then(axios.spread(function(acct, perms) {
            // Both requests are now complete
        }));
    }
};
github swgloomy / generator-reactFrameWork / app / templates / app / public / js / insertFaceApi / httpRequest.js View on Github external
let httpUrlPostAll = (urlList, successCallback, errorCallback) => {
    let list = urlList.map(item => {
            return Post(item.url, item.dataObject)
        }),
        resultData = new Array(urlList.length)

    axios.all(list).then(axios.spread((...resultData) => {
        resultData = resultData.map(item => item.data)
        successCallback ? successCallback(resultData) : console.log('ๆŽฅๅฃๆ•ฐๆฎ่ฏทๆฑ‚ๆˆๅŠŸ,ไฝ†ๆœชๅค„็†')
    })).catch((err) => {
        console.log(err)
        resultData = urlList.map(item => {
            return simulationData[item.url]
        })
        errorCallback ? errorCallback(isError ? err : resultData) : successCallback ? successCallback(isSimulationData ? resultData : errorData) : console.log('ๆŽฅๅฃ่ฏทๆฑ‚ๅคฑ่ดฅ')
    })
}
github chaokunyang / amanda / src / main / js / admin / modules / article / ArticleCategoryEdit.js View on Github external
componentDidMount() {
        Axios.all([this.getPath()]).then(Axios.spread(function (path) {
            this.setState({path: path.data});
        }.bind(this)));
    }
github StamusNetworks / scirius / hunt / src / containers / SignaturesPage / SignaturesPage.js View on Github external
fetchData(rulesStat, filters) {
        const stringFilters = this.buildFilter(filters);
        const hash = md5(`${rulesStat.pagination.page}|${rulesStat.pagination.perPage}|${this.props.from_date}|${rulesStat.sort.id}|${rulesStat.sort.asc}|${stringFilters}`);
        if (typeof this.cache[hash] !== 'undefined') {
            this.processRulesData(this.cache[hash].RuleRes, this.cache[hash].SrcRes, this.cache[hash].filters);
            return;
        }

        this.setState({ loading: true });
        axios.all([
            axios.get(`${config.API_URL + config.RULE_PATH}?${this.buildListUrlParams(rulesStat)}&from_date=${this.props.from_date}&highlight=true${stringFilters}`),
            axios.get(`${config.API_URL + config.SOURCE_PATH}?page_size=100`),
        ])
        .then(axios.spread((RuleRes, SrcRes) => {
            if (this.state.updateCache) {
                this.cachePage = rulesStat.pagination.page;
            } else {
                this.setState({ updateCache: true });
            }

            this.cache[hash] = { RuleRes, SrcRes, filters };
            this.processRulesData(RuleRes, SrcRes, filters);
        })).catch((e) => {
            this.setState({ net_error: e, loading: false });
        });
    }
github leocristofani / microfrontends-in-practice / artists / client / src / artists_container.js View on Github external
componentDidMount() {
    axios.all([
      axios.get(`${process.env.REACT_APP_LOCAL_API_URL}/genres`),
      axios.get(`${process.env.REACT_APP_LOCAL_API_URL}/artists`)
    ]).then(axios.spread((genres, artists) => {
      this.setState({
        genres: genres.data,
        artists: artists.data,
        selectedGenre: 'Pop/Rock'
      })
    }));
  }
  onSelectGenre = (selectedGenre) => {
github Vizzuality / gfw / app / javascript / components / widgets / land-cover / intact-tree-cover / index.js View on Github external
getData: params =>
    axios
      .all([
        getExtent({ ...params, forestType: '' }),
        getExtent({ ...params }),
        getExtent({ ...params, forestType: 'plantations' })
      ])
      .then(
        axios.spread((gadm28Response, iflResponse, plantationsResponse) => {
          const gadmExtent = gadm28Response.data && gadm28Response.data.data;
          const iflExtent = iflResponse.data && iflResponse.data.data;
          let totalArea = 0;
          let totalExtent = 0;
          let extent = 0;
          let plantations = 0;
          let data = {};
          const plantationsData =
            plantationsResponse.data && plantationsResponse.data.data;
          plantations = plantationsData.length ? plantationsData[0].extent : 0;
          if (iflExtent.length && gadmExtent.length) {
            totalArea = gadmExtent[0].total_area;
            totalExtent = gadmExtent[0].extent;
            extent = iflExtent[0].extent;
            data = {
              totalArea,
github Vizzuality / gfw / app / javascript / components / widgets / widgets / forest-change / tree-cover-gain / actions.js View on Github external
export default ({ params }) => {
  const { adm0, adm1, adm2, ...rest } = params || {};
  const parentLocation = {
    adm0: adm0 && !adm1 ? null : adm0,
    adm1: adm1 && !adm2 ? null : adm1,
    adm2: null
  };
  return axios.all([getGainGrouped({ ...rest, ...parentLocation })]).then(
    axios.spread(gainResponse => {
      let groupKey = 'iso';
      if (adm1) groupKey = 'adm1';
      if (adm2) groupKey = 'adm2';
      const gainData = gainResponse.data.data;
      let mappedData = [];
      if (gainData && gainData.length) {
        mappedData = gainData.map(item => {
          const gain = item.gain || 0;
          const extent = item.extent || 0;
          return {
            id:
              groupKey !== 'iso'
                ? parseInt(item[groupKey], 10)
                : item[groupKey],
            gain,
            extent,
github Vizzuality / gfw / app / javascript / components / widgets-v2 / widgets / forest-change / tree-loss-ranked / actions.js View on Github external
export default ({ params }) =>
  axios.all([fetchLossRanked(params), fetchExtentRanked(params)]).then(
    axios.spread((lossResponse, extentResponse) => {
      const { data } = lossResponse.data;
      let mappedData = [];
      if (data && data.length) {
        mappedData = data.map(item => {
          const loss = item.loss || 0;
          return {
            ...item,
            loss
          };
        });
      }
      return {
        loss: mappedData,
        extent: extentResponse.data.data
      };
    })
github Vizzuality / gfw / app / javascript / components / widgets-v2 / widgets / land-cover / tree-cover / actions.js View on Github external
export default ({ params }) =>
  axios
    .all([
      getExtent(params),
      getExtent({ ...params, forestType: null, landCategory: null }),
      getExtent({ ...params, forestType: 'plantations' })
    ])
    .then(
      axios.spread((response, adminResponse, plantationsResponse) => {
        const extent = response.data && response.data.data;
        const adminExtent = adminResponse.data && adminResponse.data.data;
        let totalArea = 0;
        let totalCover = 0;
        let cover = 0;
        let plantations = 0;
        let data = {};
        if (extent && extent.length) {
          totalArea = adminExtent[0].total_area;
          cover = extent[0].value;
          totalCover = adminExtent[0].value;
          data = {
            totalArea,
            totalCover,
            cover,
            plantations