0.0.5 • Published 5 years ago

@butsandcats/ajax-queue v0.0.5

Weekly downloads
7
License
ISC
Repository
-
Last release
5 years ago

Q - Ajax queue

Usage

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

config - object

The config object is not required

NameDescriptionTypeDefault
successThe callback for all successful ajax requests processed by this queuefunctionDispatch a Q:requestCompleted event
errorThe callback for all unsuccessful ajax requests processed by this queuefunctionDispatch a Q:requestFailed event
completedAllRequestsEventThe event type that will be dispatched once all requests have finishedstringQ:requestsCompleted
completedRequestEventThe event type that will be dispatched after each request is finishedstringQ:requestCompleted
failedRequestEventThe event type that will be dispatched after a request has failedstringQ:requestFailed
requestStartedEventThe event type that will be dispatched after each request has startedstringQ:requestStarted
errorEventThe event type that will be dispatched after Q has thrown an errorstringQ: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

NameDescriptionRequiredTypeDefault
successThe callback for a successful response, overwrites the queue default.falsefunctionDispatch a Q:requestCompleted event
errorThe callback for an unsuccessful response, overwrites the queue default.falsefunctionDispatch a Q:requestFailed event
urlThe url that the request will be sent totruestringnull
methodThe method that will be used to make the requestfalsestringGET
dataAny data that you wish to send to the requestfalseanynull
dataType*The type of data that we expect to recieve from the requestfalsestring''
dataType

Read more here

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