npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

promise-request-all

v2.1.0

Published

a function you can get all request response for http request by promise.all

Downloads

4

Readme

promise-request-all

安装


npm i promise-request-all | yarn add promise-request-all


介绍

  • 该项目用来一次性获得多个请求的结果值

  • 该项目 基于 promise.all 并且对单个 promise 的 error 进行了错误处理,(返回 error 并设置出错的 http request 的 data 值为 [] ),以防止 promise.all 特性导致的程序出错

  • 使用场景,可用于一次性的获取表单 select 下拉 options 的值

  • The usage scenario can be used to obtain the value of the select drop-down options of the form at one time

  • This project is used to get the result values of multiple requests at once.

说明

  1. 该项目基于 promise, 请确保当前环境支持解析 es5 (增加 babel-polyfill 处理)
  2. 该项目使用到了 组件级作用域 this
  3. 增加了单项请求的 errorFn 处理函数 默认传递 request error 参数
  4. 增加了单项请求的 successFn 处理函数 默认传递参数为解析后的 data 与 请求的原始 response
  5. 支持 successState / responseData 的深层写法 例如 a a.b a.b.c
  6. 该版本配置项 result 可选 (增加)

使用说明

import { promiseRequestAll } from 'promise-request-all'

  • 示例

import { getList, getType } from '@/api/*'

'getList' or 'getType' is a http request function return a Promise


  • default http Response body structure is as follows
{
    success:true,  // default value true for  responseConfig.successState
    data:[],       // default type  Array     responseConfig.responseData
    ...
    ...            // Other attributes
}

  • Component state or data , use this you can inject the results from http response body

    1.Example Vue2

    export default {
        data:{
            return {
                aOptions: [],
                bOptions: [],
                cOptions: [],
            }
        }
    }
 promiseRequestAll.bind(this)([
      { req: getList, params: { a: '' }, result: 'aOptions' },
      { req: getList, params: { b: '' }, result: 'bOptions' ,successFn:function(data,response){ }, errorFn:function(error){ }},
      { req: getType, result: 'cOptions' , responseConfig:{ successState:'state' , responseData:'response' } },     //you can change Key attributes by set responseConfig
      { req: getType, result: 'cOptions' , responseConfig:{ successState:'data.state' , responseData:'data.response' }, errorFn:function(error){ } }    //you can change Key attributes by set responseConfig

])

  • 你也可以通过 webpack provide 插件 全局注入该方法
 config.plugin('provide').use(webpack.ProvidePlugin, [{
      promiseRequestAll: [path.join(__dirname, './src/utils/common.js'),'promiseRequestAll'],
}])
  • 使用 provide 插件 eslint 需要相关配置,否则会报错
globals:{
    promiseRequestAll:true,
}