whs.js/modules/whs-module-loader
Alexander Buzin ab4304c160 Add docs
Former-commit-id: fa834762d67b5e271f7f0bc591f8c194ce612981
2017-04-07 20:39:41 +03:00
..
2017-04-07 20:19:43 +03:00
2017-04-07 20:19:43 +03:00
2017-04-07 20:19:43 +03:00
2017-04-07 20:19:43 +03:00
2017-04-07 20:19:43 +03:00
2017-04-07 20:39:41 +03:00
2017-04-07 20:19:43 +03:00

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.