import Loader from '@mobilizing/library/js/Mobilizing/core/util/Loader.js'
Loader
A loader class that manage the loading of datas from url. This is mainly used internally to manage the preLoad method in users script. Users should usually use this class methods to load datas and obtain the result encapsulated in a LoadRequest object.
Static Method Summary
Static Public Methods | ||
public static | Loads data from a URL. | |
public static | loadArrayBuffer(url: String, callback: Function) Loads an arraybuffer from a URL. | |
public static | Loads a blob from a URL. | |
public static | Loads an image from a URL. | |
public static | Loads a JavaScript object, parsed from a JSON string from a URL. | |
public static | loadScript(url: String, callback: Function) Loads a script from a URL. | |
public static | Loads a text from a URL. |
Constructor Summary
Public Constructor | ||
public | constructor(params: Object) |
Member Summary
Public Members | ||
public | events: * | |
public | onComplete: * | |
public | onError: * | |
public | onLoad: * |
Method Summary
Public Methods | ||
public | Consume (executes) all the requests | |
public | load(url: String, onStart: Function, onLoad: Function, onError: Function, responseType: String, processData: Function): LoadRequest Load a data from the URL given in parameters. | |
public | loadArrayBuffer(params: Object): LoadRequest Loads an ArrayBuffer from a URL. | |
public | Loads a blob from a URL. | |
public | Load an image from the URL given in parameters. | |
public | Loads a JavaScript object, parsed from a JSON string from a URL. | |
public | loadScript(objectPattern: {"url": *, "onStart": *, "onLoad": *, "onError": *}): * | |
public | Loads a text from a URL. | |
public | Load a video from the URL given in parameters. |
Private Methods | ||
private | Helper method to update the status and trigger the complete event |
Static Public Methods
public static load(url: String, callback: Function, responseType: String, processData: Function): * source
Loads data from a URL. This static method must be provided a callback method.
Params:
Name | Type | Attribute | Description |
url | String | the URL to load data from | |
callback | Function | callback function that the user wants to call on load completion | |
callback.result | Mixed | The load result if successful | |
callback.error | String | The load error if unsuccessful | |
responseType | String |
| The type of the respons to return from the Ajax call |
processData | Function |
| function definning what to do with the data coming from the promise |
Return:
* |
public static loadArrayBuffer(url: String, callback: Function) source
Loads an arraybuffer from a URL. This static method must be provided a callback method.
public static loadBlob(url: String, callback: Function) source
Loads a blob from a URL. This static method must be provided a callback method.
public static loadImage(url: String, callback: Function) source
Loads an image from a URL. This static method must be provided a callback method.
public static loadJSON(url: String, callback: Function) source
Loads a JavaScript object, parsed from a JSON string from a URL. This static method must be provided a callback method.
public static loadScript(url: String, callback: Function) source
Loads a script from a URL. This static method must be provided a callback method.
Public Constructors
Public Members
public events: * source
public onComplete: * source
public onError: * source
public onLoad: * source
Private Members
private _requests: *[] source
private _status: * source
Public Methods
public consumeAll() source
Consume (executes) all the requests
public load(url: String, onStart: Function, onLoad: Function, onError: Function, responseType: String, processData: Function): LoadRequest source
Load a data from the URL given in parameters. ResponseType is the default one of an Ajax object, that is String.
Params:
Name | Type | Attribute | Description |
url | String | the URL to load data from | |
onStart | Function |
| A function to be called when the loading starts |
onLoad | Function |
| A function to be called when the loading finishes |
onError | Function |
| A function to be called when the loading fails |
responseType | String |
| The type of the respons to return from the Ajax call |
processData | Function | function definning what to do with the data coming from the promise |
Return:
LoadRequest | the LoadRequest object is incomplete at call and will be filled by the inner promise manager, when fulfilled. |
public loadArrayBuffer(params: Object): LoadRequest source
Loads an ArrayBuffer from a URL.
Params:
Name | Type | Attribute | Description |
params | Object | Parameters object to pass to the load function. |
Return:
LoadRequest | a LoadRequest who's value is incomplete at first and will be filled once the Ajax request is fulfilled |
public loadBlob(params: Object): LoadRequest source
Loads a blob from a URL.
Params:
Name | Type | Attribute | Description |
params | Object | Parameters object to pass to the load function. |
Return:
LoadRequest | a LoadRequest who's value is incomplete at first and will be filled once the Ajax request is fulfilled |
public loadImage(url: String, onStart: Function, onLoad: Function, onError: Function): LoadRequest source
Load an image from the URL given in parameters. The Image Object is given as the returned LoadRequest's value.
Params:
Name | Type | Attribute | Description |
url | String | the URL to load data from | |
onStart | Function |
| A function to be called when the loading starts |
onLoad | Function |
| A function to be called when the loading finishes |
onError | Function |
| A function to be called when the loading fails |
Return:
LoadRequest | a LoadRequest who's value is incomplete at first and will be filled once the Ajax request is fulfilled |
public loadJSON(params: Object): LoadRequest source
Loads a JavaScript object, parsed from a JSON string from a URL.
Params:
Name | Type | Attribute | Description |
params | Object | Parameters object to pass to the load function. |
Return:
LoadRequest | a LoadRequest who's value is incomplete at first and will be filled once the Ajax request is fulfilled |
public loadScript(objectPattern: {"url": *, "onStart": *, "onLoad": *, "onError": *}): * source
Params:
Name | Type | Attribute | Description |
objectPattern | {"url": *, "onStart": *, "onLoad": *, "onError": *} |
|
Return:
* |
public loadText(params: Object): LoadRequest source
Loads a text from a URL.
Params:
Name | Type | Attribute | Description |
params | Object | Parameters object to pass to the load function. |
Return:
LoadRequest | a LoadRequest who's value is incomplete at first and will be filled once the Ajax request is fulfilled |
public loadVideo(url: String, onStart: Function, onLoad: Function, onError: Function): LoadRequest source
Load a video from the URL given in parameters. The Video Object is given as the returned LoadRequest's value.
Params:
Name | Type | Attribute | Description |
url | String | the URL to load data from | |
onStart | Function |
| A function to be called when the loading starts |
onLoad | Function |
| A function to be called when the loading finishes |
onError | Function |
| A function to be called when the loading fails |
Return:
LoadRequest | a LoadRequest who's value is incomplete at first and will be filled once the request is fulfilled |
Private Methods
private doComplete() source
Helper method to update the status and trigger the complete event