# @butsandcats/ajax-queue

> Front end ajax queue and request handler

Latest version **0.0.5** (published 2018-12-18) · ISC license · 0 weekly downloads

## Install

```sh
npm install @butsandcats/ajax-queue
pnpm add @butsandcats/ajax-queue
yarn add @butsandcats/ajax-queue
bun add @butsandcats/ajax-queue
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.5 |
| Published | 2018-12-18 |
| First published | 2018-08-01 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 12.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | DotDev |
| Maintainers | butsandcats |
| Keywords | Ajax, Queue |

## Links

- npm: https://www.npmjs.com/package/@butsandcats/ajax-queue
- npm.io page: https://npm.io/package/@butsandcats/ajax-queue

## Alternatives

- [cron](https://npm.io/package/cron.md) — 4.9M weekly downloads
- [@vercel/queue](https://npm.io/package/@vercel/queue.md) — 731.6K weekly downloads
- [create-sonicjs](https://npm.io/package/create-sonicjs.md) — 1.6K weekly downloads
- [@exellix/jobs-api](https://npm.io/package/@exellix/jobs-api.md) — 941 weekly downloads
- [@forwardimpact/libskill](https://npm.io/package/@forwardimpact/libskill.md) — 575 weekly downloads

## Recent versions

- 0.0.5 (latest) — 2018-12-18
- 0.0.4 — 2018-08-27
- 0.0.3 — 2018-08-03
- 0.0.2 — 2018-08-02
- 0.0.1 — 2018-08-02
- 0.0.0 — 2018-08-01

## README

# Q - Ajax queue

## Usage
```
const queue = new Q([config]);
queue.add([request]);
```

## `config` - object

The config object is **not** required

Name                      | Description                                                             | Type     | Default  
--------------------------|-------------------------------------------------------------------------|----------|--------------------------------------
success                   | The callback for all successful ajax requests processed by this queue   | function | Dispatch a `Q:requestCompleted` event
error                     | The callback for all unsuccessful ajax requests processed by this queue | function | Dispatch a `Q:requestFailed` event
completedAllRequestsEvent | The event type that will be dispatched once all requests have finished  | string   | `Q:requestsCompleted`
completedRequestEvent     | The event type that will be dispatched after each request is finished   | string   | `Q:requestCompleted`
failedRequestEvent        | The event type that will be dispatched after a request has failed       | string   | `Q:requestFailed`
requestStartedEvent       | The event type that will be dispatched after each request has started   | string   | `Q:requestStarted`
errorEvent                | The event type that will be dispatched after Q has thrown an error      | string   | `Q:error`

## Methods

### `add`
#### Description
Adds a request to the currently running queue, this will cause the queue to process each item, one at a time until all requests have been resolved.
#### Example
```
  const queue = new Q()

  // Build the ajax request
  const request = {
    url: '/cart/add.js',
    data: item,
    success: options.success,
    error: options.error
  }

  // Add the request to the ajax request queue
  this.queue.add(request)
  })
```

#### `request` - object
Name    | Description                                                          | Required   | Type     | Default  
--------------------------|----------------------------------------------------------------------|------------|----------|--------------------------
success | The callback for a successful response, overwrites the queue default. | `false` | function | Dispatch a `Q:requestCompleted` event
error   | The callback for an unsuccessful response, overwrites the queue default. | `false` | function | Dispatch a `Q:requestFailed` event
url     | The url that the request will be sent to | `true` | string | `null`
method  | The method that will be used to make the request  | `false` | string | `GET`  
data    | Any data that you wish to send to the request  | `false` | any | `null`
dataType[*](#dataType)  | The type of data that we expect to recieve from the request | `false` | string | `''`  

##### dataType

[Read more here](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/responseType)

Options:
`''`, `'arraybuffer'`, `'blob'`, `'document'`, `'json'`, `'text'`

---
_Source: https://npm.io/package/@butsandcats/ajax-queue · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
