new Loader( [baseUrl] [, concurrency])
Parameters:
Name | Type | Argument | Default | Description |
---|---|---|---|---|
baseUrl |
string |
<optional> |
'' | The base url for all resources loaded by this loader. |
concurrency |
number |
<optional> |
10 | The number of resources to load concurrently. |
- Source:
Members
-
_afterMiddleware :Array.<function()>
-
The middleware to run after loading each resource.
Type:
- Array.<function()>
- Source:
-
_beforeMiddleware :Array.<function()>
-
The middleware to run before loading each resource.
Type:
- Array.<function()>
- Source:
-
baseUrl :string
-
The base url for all resources loaded by this loader.
Type:
- string
- Source:
-
defaultQueryString
-
A querystring to append to every URL added to the loader.
This should be a valid query string without the question-mark (
?
). The loader will
also not escape values for you. Make sure to escape your parameters withencodeURIComponent
before assigning this property.- Source:
Example
```js const loader = new Loader(); loader.defaultQueryString = 'user=me&password=secret'; // This will request 'image.png?user=me&password=secret' loader.add('image.png').load(); loader.reset(); // This will request 'image.png?v=1&user=me&password=secret' loader.add('iamge.png?v=1').load(); ```
-
loading :boolean
-
Loading state of the loader, true if it is currently loading resources.
Type:
- boolean
- Source:
-
onComplete :Signal
-
Dispatched when the queued resources all load.
The callback looks like Loader.OnCompleteSignal.
Type:
- Signal
- Source:
-
onError :Signal
-
Dispatched once per errored resource.
The callback looks like Loader.OnErrorSignal.
Type:
- Signal
- Source:
-
onLoad :Signal
-
Dispatched once per loaded resource.
The callback looks like Loader.OnLoadSignal.
Type:
- Signal
- Source:
-
onProgress :Signal
-
Dispatched once per loaded or errored resource.
The callback looks like Loader.OnProgressSignal.
Type:
- Signal
- Source:
-
onStart :Signal
-
Dispatched when the loader begins to process the queue.
The callback looks like Loader.OnStartSignal.
Type:
- Signal
- Source:
-
progress :number
-
The progress percent of the loader going through the queue.
Type:
- number
- Source:
-
resources :object.<string, Resource>
-
All the resources for this loader keyed by name.
Type:
- object.<string, Resource>
- Source:
Methods
-
after(fn)
-
Sets up a middleware function that will run after the
resource is loaded.Parameters:
Name Type Description fn
function The middleware function to register.
- Source:
Returns:
Returns itself.
- Type
- Loader
-
before(fn)
-
Sets up a middleware function that will run before the
resource is loaded.Parameters:
Name Type Description fn
function The middleware function to register.
- Source:
Returns:
Returns itself.
- Type
- Loader
Type Definitions
-
OnCompleteSignal(loader)
-
When the loader completes loading resources it dispatches this callback.
Parameters:
Name Type Description loader
Loader The loader that has finished loading resources.
- Source:
-
OnErrorSignal(loader, resource)
-
When an error occurrs the loader and resource are disaptched.
Parameters:
Name Type Description loader
Loader The loader the error happened in.
resource
Resource The resource that caused the error.
- Source:
-
OnLoadSignal(loader, resource)
-
When a load completes the loader and resource are disaptched.
Parameters:
Name Type Description loader
Loader The loader that laoded the resource.
resource
Resource The resource that has completed loading.
- Source:
-
OnProgressSignal(loader, resource)
-
When the progress changes the loader and resource are disaptched.
Parameters:
Name Type Description loader
Loader The loader the progress is advancing on.
resource
Resource The resource that has completed or failed to cause the progress to advance.
- Source:
-
OnStartSignal(loader)
-
When the loader starts loading resources it dispatches this callback.
Parameters:
Name Type Description loader
Loader The loader that has started loading resources.
- Source: