/utils/xhr

Export the xhr method to mapp.utils{}.

Methods

(inner) checkThrottle(throttleKey)

Function to abort a previous request if it's to be throttled

Parameters:
NameTypeDescription
throttleKeystring

The throttle group key

(inner) getThrottleKey(params) → {string|null}

Parameters:
NameTypeDescription
paramsObject

The object containing the parameters.

Properties
NameTypeAttributesDescription
params.throttleboolean | string<optional>

Whether the response should be throttled and added to the throttle Map under a group name.

Returns:

The throttle group key

Type: 
string | null

(inner) setThrottle(throttleKey, xhr)

Function to add throttle controller for throttle group

Parameters:
NameTypeDescription
throttleKeystring

The throttle group key

xhrObject

XMLHttpRequest

(inner) xhr(params) → {Promise}

The params object/string for the xhr utility method is required.

The params are assumed to the request URL if provided as a string argument.

The request params and response are stored in a Map() if the cache flag is set in the params object argument.

If the throttle flag is set we will abort requests that have not been resolved yet if there is an incoming request that is part of the same group This flag is optional and will only be set in scenarios where requests could happen in quick succession but are not necessary.

The method is assumed to be 'POST' if a params.body is provided.

Parameters:
NameTypeDescription
paramsObject

The object containing the parameters.

Properties
NameTypeAttributesDefaultDescription
params.urlstring

The request URL.

params.methodstring<optional>
GET

The request method.

params.responseTypestring<optional>
json

The XHR responseType.

params.requestHeaderObject<optional>
{'Content-Type': 'application/json'}

The XHR requestHeader.

params.bodystring<optional>

A stringified request body for a 'POST' request.

params.resolveTargetboolean<optional>

Whether the target instead of target.response should be resolved.

params.cacheboolean<optional>

Whether the response should be cached in a Map().

params.throttleboolean | string<optional>

Whether the response should be throttled and added to the throttle Map under a group name.

Returns:

A promise that resolves with the XHR.

Type: 
Promise