2.0.6 • Published 9 months ago

poll-api v2.0.6

Weekly downloads
-
License
MIT
Repository
-
Last release
9 months ago

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
2.0.3

9 months ago

2.0.2

9 months ago

2.0.5

9 months ago

2.0.4

9 months ago

2.0.6

9 months ago

2.0.1

9 months ago

2.0.0

9 months ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago