/utils/xhr
Export the xhr method to mapp.utils{}.
- Source
Methods
(inner) checkThrottle(throttleKey)
Function to abort a previous request if it's to be throttled
| Name | Type | Description |
|---|---|---|
throttleKey | string | The throttle group key |
- Source
(inner) getThrottleKey(params) → {string|null}
| Name | Type | Description |
|---|---|---|
params | Object | The object containing the parameters. |
| Name | Type | Attributes | Description |
|---|---|---|---|
params.throttle | boolean | | <optional> | Whether the response should be throttled and added to the throttle Map under a group name. |
- Source
The throttle group key
- Type:
- string |
null
(inner) setThrottle(throttleKey, xhr)
Function to add throttle controller for throttle group
| Name | Type | Description |
|---|---|---|
throttleKey | string | The throttle group key |
xhr | Object | XMLHttpRequest |
- Source
(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.
| Name | Type | Description |
|---|---|---|
params | Object | The object containing the parameters. |
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
params.url | string | The request URL. | ||
params.method | string | <optional> | GET | The request method. |
params.responseType | string | <optional> | json | The XHR responseType. |
params.requestHeader | Object | <optional> | {'Content-Type': 'application/json'} | The XHR requestHeader. |
params.body | string | <optional> | A stringified request body for a 'POST' request. | |
params.resolveTarget | boolean | <optional> | Whether the target instead of target.response should be resolved. | |
params.cache | boolean | <optional> | Whether the response should be cached in a Map(). | |
params.throttle | boolean | | <optional> | Whether the response should be throttled and added to the throttle Map under a group name. |
- Source
A promise that resolves with the XHR.
- Type:
- Promise