Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Loader

Manages the state and loading of multiple resources to load.

preferred

Hierarchy

  • Loader

Index

Type aliases

Static MiddlewareFn

MiddlewareFn: (resource: Resource, next: () => void) => void

Type declaration

    • (resource: Resource, next: () => void): void
    • Parameters

      • resource: Resource
      • next: () => void
          • (): void
          • Returns void

      Returns void

Static OnCompleteSignal

OnCompleteSignal: (loader: Loader, resources: ResourceMap) => void

Type declaration

Static OnErrorSignal

OnErrorSignal: (errMessage: string, loader: Loader, resource: Resource) => void

Type declaration

    • Parameters

      Returns void

Static OnLoadSignal

OnLoadSignal: (loader: Loader, resource: Resource) => void

Type declaration

Static OnProgressSignal

OnProgressSignal: (loader: Loader, resource: Resource) => void

Type declaration

Static OnStartSignal

OnStartSignal: (loader: Loader) => void

Type declaration

    • Parameters

      Returns void

Static ResourceMap

ResourceMap: Partial<Record<string, Resource>>

Static UrlResolverFn

UrlResolverFn: (url: string, parsed: ReturnType<typeof parseUri>) => string

Type declaration

    • (url: string, parsed: ReturnType<typeof parseUri>): string
    • Parameters

      • url: string
      • parsed: ReturnType<typeof parseUri>

      Returns string

Constructors

constructor

  • new Loader(baseUrl?: string, concurrency?: number): Loader
  • Parameters

    • Default value baseUrl: string = ""

      The base url for all resources loaded by this loader.

    • Default value concurrency: number = 10

      The number of resources to load concurrently.

    Returns Loader

Properties

defaultQueryString

defaultQueryString: string = ""

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 with encodeURIComponent before assigning this property.

example

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

loading: boolean = false

Loading state of the loader, true if it is currently loading resources.

onComplete

onComplete: Signal<OnCompleteSignal> = new Signal<Loader.OnCompleteSignal>()

Dispatched when the queued resources all load.

onError

onError: Signal<OnErrorSignal> = new Signal<Loader.OnErrorSignal>()

Dispatched once per errored resource.

onLoad

onLoad: Signal<OnLoadSignal> = new Signal<Loader.OnLoadSignal>()

Dispatched once per loaded resource.

onProgress

onProgress: Signal<OnProgressSignal> = new Signal<Loader.OnProgressSignal>()

Dispatched once per loaded or errored resource.

onStart

onStart: Signal<OnStartSignal> = new Signal<Loader.OnStartSignal>()

Dispatched when the loader begins to process the queue.

progress

progress: number = 0

The progress percent of the loader going through the queue.

resources

resources: ResourceMap

All the resources for this loader keyed by name, or URL if no name was given.

Static DefaultMiddlewarePriority

DefaultMiddlewarePriority: 50 = 50

The default middleware priority (50).

Accessors

baseUrl

  • get baseUrl(): string
  • set baseUrl(url: string): void
  • The base url for all resources loaded by this loader. Any trailing slashes are trimmed off.

    Returns string

  • The base url for all resources loaded by this loader. Any trailing slashes are trimmed off.

    Parameters

    • url: string

    Returns void

concurrency

  • get concurrency(): number
  • set concurrency(concurrency: number): void
  • The number of resources to load concurrently.

    Returns number

  • The number of resources to load concurrently.

    Parameters

    • concurrency: number

    Returns void

Methods

add

  • add(url: string): this
  • add(name: string, url: string): this
  • add(options: IAddOptions): this
  • add(resources: (string | IAddOptions)[]): this
  • Adds a resource (or multiple resources) to the loader queue.

    This function can take a wide variety of different parameters. The only thing that is always required the url to load. All the following will work:

    loader
        // name & url param syntax
        .add('http://...')
        .add('key', 'http://...')
    
        // object syntax
        .add({
            name: 'key3',
            url: 'http://...',
            onComplete: function () {},
        })
    
        // you can also pass an array of objects or urls or both
        .add([
            { name: 'key4', url: 'http://...', onComplete: function () {} },
            { url: 'http://...', onComplete: function () {} },
            'http://...'
        ])

    Parameters

    • url: string

    Returns this

  • Parameters

    • name: string
    • url: string

    Returns this

  • Parameters

    Returns this

  • Parameters

    Returns this

addUrlResolver

  • Add a function that can be used to modify the url just prior to baseUrl and defaultQueryString being applied.

    Parameters

    Returns this

load

reset

  • reset(): this
  • Resets the queue of the loader to prepare for a new load.

    Returns this

use

  • Sets up a middleware function that will run after the resource is loaded.

    You can optionally specify a priority for this middleware which will determine the order middleware functions are run. A lower priority value will make the function run earlier. That is, priority 30 is run before priority 50.

    Parameters

    • fn: MiddlewareFn
    • Default value priority: number = Loader.DefaultMiddlewarePriority

    Returns this

Static use

  • Sets up a middleware function that will run after the resource is loaded.

    You can optionally specify a priority for this middleware which will determine the order middleware functions are run. A lower priority value will make the function run earlier. That is, priority 30 is run before priority 50.

    Parameters

    • fn: MiddlewareFn
    • Default value priority: number = Loader.DefaultMiddlewarePriority

    Returns typeof Loader

Generated using TypeDoc