Manual Reference Source Test
import CustomLoader from 'beloader/src/loaders/CustomLoader.js'
public class | version 1.0.0 | since 1.0.0 | source

CustomLoader

Extends:

AbstractEventManagerAbstractLoader → CustomLoader

Custom loader let user provide a custom callback as a loader instance

The callback must be provided through options.loader and must return a promise. It can also throw events if needed.

It will always be called whenever options.async is set to true or false. Only calling QueueItem will be exposed in the latter promise. For bringing back data, you can use event or add a custom property to the QueueItem. You can access item via the parent property of the loader.

Example:

 var loader = new Beloader();
 var myLoader = function() {
  return new Promise(function(resolve, reject) {
    // Do things
    this.parent.response = things;
    if(OK) resolve();
    else reject('error on things'); // Will be available in item.error
  }.bind(this));
 }

 loader.fetch('custom', {loader: myLoader})
  .promise
  .then(
    function(item) { item.response // yields "things" value },
    function(item) { console.log(item.error) // display "error on things" }
  );

Constructor Summary

Public Constructor
public

constructor(parent: QueueItem, options: DotObjectArray)

version 1.0.0 since 1.0.0

Member Summary

Public Members
public get
version 1.0.0 since 1.0.0

Inherited Summary

From class AbstractEventManager
private

Callback's list by eventName

since 1.0.0
public

fire(eventName: string, target: Beloader | QueueItem | Loader | Plugin, data: object | array | number | string)

Fire an event

version 1.0.0 since 1.0.0
public

on(eventName: string, callback: Function)

Register events callbacks after instance creation

version 1.0.0 since 1.0.0
private

Dispatch an event

version 1.0.0 since 1.0.0
From class AbstractLoader
public get

Loader promise

version 1.0.0 since 1.0.0
public

Loader options

since 1.0.0
public

Requesting parent item

since 1.0.0
private

Map plugins

since 1.0.0
public abstract

The async method relies on fetching content with an XHR request and inserting it inline in the document, wrapped in right HTML container if needed

version 1.0.0 since 1.0.0
public abstract

The sync method mostly relies on adding an HTMLElement to the DOM to load asset.

version 1.0.0 since 1.0.0

Public Constructors

public constructor(parent: QueueItem, options: DotObjectArray) version 1.0.0 since 1.0.0 source

Constructor

Override:

AbstractLoader#constructor

Params:

NameTypeAttributeDescription
parent QueueItem

Calling QueueItem

options DotObjectArray

Loader options

Public Members

public get promise: Promise version 1.0.0 since 1.0.0 source

Loader promise

Override:

AbstractLoader#promise