0.1.0 • Published 7 years ago

whs-module-loader v0.1.0

Weekly downloads
4
License
MIT
Repository
github
Last release
7 years ago

whs-module-loader - Loading progress for components, textures, ...

Usage

constructor(expecting = [])

expecting - Array of keys [String] that will be added to .expecting

.expect(key) and .resolve(key) - Use for callbacks

const loader = new LoaderModule();

const app = new WHS.App([
  // ...
])''

loader.expect('sphere1');

const sphere = new WHS.Sphere({
  // ...
});

sphere.addTo(app).then(() => loader.resolve('sphere1'));

.promise(key, promise) - Use for promises

No .expect() required!

loader.promise('sphere1', sphere.addTo(app));

.getProgress() - Get loading progress

Returns value from 0 to 1, where 1 means completed.

Can be transformed into percents simply muliplying by 100:

console.log(`Current percent is: ${loader.getProgress() * 100}`);

Events

.on('step', [Callback])

loader.on('step', key => {
  console.log(key);
});

.on('complete', [Callback])

loader.on('complete', () => {
  alert('completed!');
});

Fires when .resolve() was called and .expecting is empty.

Attributes

.expecting

console.log(loader.expecting);
// Array of keys that aren't resolved yet.

This attribute represents an Array of keys [String] values that are not resolved yet.

.resolved

console.log(loader.resolved);
// Array of keys that have been resolved.

Array of resolved keys.