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

poll-api

v2.0.6

Published

poll api

Downloads

2

Readme

English | 中文

poll-api

Poll API is a library that helps developers manage Api polling requests

Function

  • Asynchronous callback function
  • Support immediate polling or specified interval time or number of polling request API

Install & Usage

  1. Install the poll-api
  # Using npm
  npm install poll-api -S
  # Using yarn
  yarn add poll-api -S
  1. Import poll-api and use
  import PollApiManager from 'poll-api'
  // Register global request API configuration, support chain calling
  PollApiManager.registerRequestConfig('test', {
    url: 'https://api.jisuapi.com/area/province'
  }).registerRequestConfig('test1', {
    url: 'https://api.jisuapi.com/area/province'
  })
  // Create a polling instance
  const pollApiInstance = PollApiManager.createInstance()
  // Enable a polling API request
  const requestTask = $pollApi.poll('test', {
    fn
  })

PollApiManager instance method

registerRequestConfig

Parameter information for global registration polling requests

Parameters

  • requestType (RequestType) Key for global configuration request configuration information
  • requestConfig (RequestConfig) Configuration information for API requests

createInstance

Create a pollApi instance

Parameters

None

deletePollApiInstance

Delete the specified pollApi instance and clear all queues and request tasks under the current instance

Parameters

  • instance (PollApi) PollApi instance

clear

Clear all pollApi instances and all queues and request tasks under all instances

Parameters

None

PollApi instance method

poll

Create an API polling instance and start polling. If the request configuration information for the current requestType is not registered globally, it will be automatically registered

Parameters

  • requestType (RequestType) Key for global configuration request configuration information
  • data (PollApiOnData) API requested data
  • fn (RequestConfigFn) Obtain the configuration information requested by the API. If not transmitted, the configuration information of the corresponding key will be configured globally by default
  • pollConfigFn (PollConfigFn) Obtain polling configuration information, if not transmitted, default configuration will be used

deleteRequestTask

Close the specified request task

Parameters

  • requestTask (RequestTask) RequestTask Instance

deleteRequestQueue

Close the specified task queue and all request tasks under the current queue

Parameters

  • requestType (RequestType) Key for global configuration request configuration information

clear

Close all queues and request tasks under the current pollApi instance, but do not clear the current pollApi instance

Parameters

None

RequestTask instance method

updateData

update request data

stopPollApi

Stop polling for the current request task

Parameters

None

bootstrap

Start Polling Request Current Request Task

Parameters

None

delete

Clear current request task

Parameters

None

Type declaration

  declare type RequestType = string | symbol

  declare type EventType = string | symbol

  declare interface Fn<T = any, R = T> {
    (...arg: T[]): R
  }

  declare type Nullable<T> = T | null

  declare interface EventOptions {}

  declare interface PollConfig {
    pollCount: number // If the number of rounds is -1, it is considered to be a continuous round robin
    pollInterval: number // Polling interval unit: seconds
    immediate: boolean // Do you want to trigger polling immediately
  }

  declare interface PollApiOnData {
    eventType?: EventType
    fn: Fn
    data?: Nullable<any>
  }

  interface CreateRequestTaskParams {
    data: PollApiOnData
    requestConfig: RequestConfig
    pollConfig: PollConfig
  }

  import type { AxiosRequestConfig, AxiosInstance } from 'axios'
  interface RequestConfig extends AxiosRequestConfig {
    resDataTransform?: Fn,
    axiosInstance: AxiosInstance
  }

  export type RequestConfigFn = (
    requestConfig: Nullable<RequestConfig>
  ) => Nullable<RequestConfig>
  export type PollConfigFn = (pollConfig: PollConfig) => PollConfig