Home Reference Source
import AssetSystem from 'oxygen-core/systems/AssetSystem'
public class | source

AssetSystem

Extends:

System → AssetSystem

Assets database and loader.

Example:

const system = new AssetSystem('assets/', { cache: 'no-store' }, AssetSystem.fetchArrayView);

Static Method Summary

Static Public Methods
public static

fetch(args: *): Promise

Default browser fetch mechanism.

public static

fetchArrayView(view: ArrayBufferView, path: string, options: *, fallbackEngine: Function): Promise

Custom fetch mechanism that loads data from array view.

public static

makeFetchEngineWeb(address: string, fallbackEngine: Function): Function

Web fetch mechanism generator that loads data from specified address.

Constructor Summary

Public Constructor
public

constructor(pathPrefix: string | null, fetchOptions: * | null, fetchEngine: Function | null)

Constructor.

Member Summary

Public Members
public get
public get
public set
public get
public get

Method Summary

Public Methods
public

Destructor (dispose internal resources and clear assets database).

public

get(path: string): Asset | null

Get asset by it's full path.

public

load(path: string): Promise

Load asset from given path.

public

async loadAll(paths: Array<string>): Promise

Load list of assets possibly all at the same time (asynchronously).

public

async loadAllWithFetchEngine(paths: Array<string>, fetchEngine: Function): Promise

Load list of assets possibly all at the same time (asynchronously) with specified fetch engine.

public

async loadSequence(paths: Array<string>): Promise

Load list of assets in sequence (one by one).

public

async loadSequenceWithFetchEngine(paths: Array<string>, fetchEngine: Function): Promise

Load list of assets in sequence (one by one) with specified fetch engine.

public

async loadWithFetchEngine(path: string, fetchEngine: Function): Promise

Load asset from given path with specified fetch engine.

public
public

registerProtocol(protocol: string, assetConstructor: Function)

Register assets loader under given protocol.

public

unload(path: string)

Unload asset by path and remove from database.

public

Unload all assets from paths list.

public

Unregister given assets loader protocol.

Inherited Summary

From class System
public static get
public static get

systems: *

public static

Dispose and remove all registered systems.

public static

get(typename: string): System | null

Returns system instance of given type name.

public static

register(typename: string, system: System): System

Register new system instance under given name.

public static

unregister(typename: string): System

Unregister given system.

public

Destructor (disposes all internal resources).

public

Event called after system gets registered.

public

Event called before system gets unregistered.

Static Public Methods

public static fetch(args: *): Promise source

Default browser fetch mechanism.

Params:

NameTypeAttributeDescription
args *

Fetch engine parameters.

Return:

Promise

Promise that fetches file.

public static fetchArrayView(view: ArrayBufferView, path: string, options: *, fallbackEngine: Function): Promise source

Custom fetch mechanism that loads data from array view.

Params:

NameTypeAttributeDescription
view ArrayBufferView

Data array buffer view.

path string

Asset path.

options *

Fetch engine options.

fallbackEngine Function

Fallback fetch engine.

Return:

Promise

Promise that fetches file from array view.

public static makeFetchEngineWeb(address: string, fallbackEngine: Function): Function source

Web fetch mechanism generator that loads data from specified address.

Params:

NameTypeAttributeDescription
address string

Assets hosting address.

fallbackEngine Function

Fallback fetch engine.

Return:

Function

Function that fetches file from web.

Public Constructors

public constructor(pathPrefix: string | null, fetchOptions: * | null, fetchEngine: Function | null) source

Constructor.

Params:

NameTypeAttributeDescription
pathPrefix string | null

Path prefix used for every requested asset or null no path prefix.

fetchOptions * | null

Custom fetch options or null if default will be used.

fetchEngine Function | null

Custom fetch engine or null if default will be used.

Public Members

public get events: Events source

Override:

System#events

public get fetchEngine: Function source

public set fetchEngine: Function source

public get fetchOptions: * source

public get pathPrefix: string source

Public Methods

public dispose() source

Destructor (dispose internal resources and clear assets database).

Override:

System#dispose

Example:

system.dispose();
system = null;

public get(path: string): Asset | null source

Get asset by it's full path.

Override:

System#get

Params:

NameTypeAttributeDescription
path string

Asset path (with protocol).

Return:

Asset | null

Asset instance if found or null otherwise.

Example:

const config = system.get('json://config.json');

public load(path: string): Promise source

Load asset from given path.

Params:

NameTypeAttributeDescription
path string

Asset path (with protocol).

Return:

Promise

Promise of fetch engine loader.

Example:

system.load('json://config.json').then(asset => console.log(asset.data));

public async loadAll(paths: Array<string>): Promise source

Load list of assets possibly all at the same time (asynchronously).

Params:

NameTypeAttributeDescription
paths Array<string>

Array of assets paths.

Return:

Promise

Promise of fetch engine loader.

Example:

const list = [ 'json://config.json', 'text://hello.txt' ];
system.loadAll(list).then(assets => console.log(assets.map(a => a.data)));

public async loadAllWithFetchEngine(paths: Array<string>, fetchEngine: Function): Promise source

Load list of assets possibly all at the same time (asynchronously) with specified fetch engine.

Params:

NameTypeAttributeDescription
paths Array<string>

Array of assets paths.

fetchEngine Function

Fetch engine used to fetch assets.

Return:

Promise

Promise of fetch engine loader.

Example:

const list = [ 'json://config.json', 'text://hello.txt' ];
system.loadAllWithFetchEngine(list, AssetSystem.fetch).then(assets => console.log(assets.map(a => a.data)));

public async loadSequence(paths: Array<string>): Promise source

Load list of assets in sequence (one by one).

Params:

NameTypeAttributeDescription
paths Array<string>

Array of assets paths.

Return:

Promise

Promise of fetch engine loader.

Example:

const list = [ 'json://config.json', 'text://hello.txt' ];
system.loadSequence(list).then(assets => console.log(assets.map(a => a.data)));

public async loadSequenceWithFetchEngine(paths: Array<string>, fetchEngine: Function): Promise source

Load list of assets in sequence (one by one) with specified fetch engine.

Params:

NameTypeAttributeDescription
paths Array<string>

Array of assets paths.

fetchEngine Function

Fetch engine used to fetch assets.

Return:

Promise

Promise of fetch engine loader.

Example:

const list = [ 'json://config.json', 'text://hello.txt' ];
system.loadSequenceWithFetchEngine(list, AssetSystem.fetch).then(assets => console.log(assets.map(a => a.data)));

public async loadWithFetchEngine(path: string, fetchEngine: Function): Promise source

Load asset from given path with specified fetch engine.

Params:

NameTypeAttributeDescription
path string

Asset path (with protocol).

fetchEngine Function

Fetch engine used to fetch asset.

Return:

Promise

Promise of fetch engine loader.

Example:

system.loadWithFetchEngine('json://config.json', AssetSystem.fetch).then(asset => console.log(asset.data));

public onUnregister() source

Event called before system gets unregistered.

Override:

System#onUnregister

public registerProtocol(protocol: string, assetConstructor: Function) source

Register assets loader under given protocol.

Params:

NameTypeAttributeDescription
protocol string

Assets loader protocol name.

assetConstructor Function

Asset factory.

Example:

system.registerProtocol('json', JSONAsset.factory);

public unload(path: string) source

Unload asset by path and remove from database.

Params:

NameTypeAttributeDescription
path string

Asset path (with protocol).

Example:

system.unload('json://config.json');

public unloadAll(paths: Array<string>) source

Unload all assets from paths list.

Params:

NameTypeAttributeDescription
paths Array<string>

Array of assets paths.

public unregisterProtocol(protocol: string) source

Unregister given assets loader protocol.

Params:

NameTypeAttributeDescription
protocol string

Assets loader protocol name.

Example:

system.unregisterProtocol('json');