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

@masongzhi/api-queue

v1.0.0

Published

用于应对vue或react开发时,A组件使用a接口,B组件使用b接口,同时b接口需要a接口先执行,然后把数据储存到store。

Downloads

1

Readme

api-queue

用于应对vue或react开发时,A组件使用a接口,B组件使用b接口,同时b接口需要a接口先执行,然后把数据储存到store。

image

这样的好处在于,俩个组件间有依赖需求的接口不需要重复调用,也不需要做复杂的数据交互,只需要在执行前加上await apiQueue('xxx')即可。

USAGE

npm install api-queue

以vue做示范

// A组件
import api from '@/services';
import { mapActions } from 'vuex';

export default {
    methods: {
        ...mapActions(['setAData']),
        async getData() {
            const data = await api.a();
            this.setAData(data);
        }
    },
    created() {
        this.getData();
    }
}
// B组件
import api from '@/services';
import { mapState } from 'vuex';
import apiQueue from 'apiQueue';

export default {
    computed: mapState(['aData']),
    methods: {
        ...mapActions(['setAData']),
        async getData() {
            await apiQueue.wait('a');
            await api.b({
                data: this.aData
            });
        }
    },
    created() {
        this.getData();
    }
}
// store
import Vue from 'vue';
import Vuex from 'vuex';
import api from '@services';

Vue.use(Vuex);

const state = {
    aData: {}
}

const actions = {
    async setAData({ commit }, data) {
        commit('SET_A_DATA', data);
    },
}

const mutations = {
  SET_A_DATA(s, val) {
    s.aData = val;
  }
}

export default new Vuex.Store({
  state,
  actions,
  mutations
});
// services
import xhr, { get, post } from 'XHR-AXIOS';
import apiQueue from 'apiQueue';

const delayPost = (url, data) => {
    const apiName = url.split('/').pop();
    apiQueue.push(apiName);
    return post(url, data).then(d => d, (e) => {
        queue.finish(apiName);
        return Promise.reject(e);
    });
};

const delayGet = (url, data) => {
  const apiName = url.split('/').pop();
  apiQueue.push(apiName);
  return get(url, data).then(d => d, (e) => {
    queue.finish(apiName);
    return Promise.reject(e);
  });
};

export default {
  a: data => delayGet('/a', data),
  b: data => delayPost('/b', data)
};