1.0.0 • Published 6 years ago
@lgslabs/bits-lazy-load v1.0.0
BITS Lazy Load
This module provides the ability to have a soft dependency on another module.
Use
const LazyLoad = require('@lgslabs/bits-lazy-load');
const MODULE_NAME = 'some-other-module';
class MyClass() {
constructor() {
this._boundOnLoaded = this._onLoaded.bind(this);
this._boundOnUnloaded = this._onUnloaded.bind(this);
this._lazyLoad = null;
}
load({messageCenter}) {
this._lazyLoad = new LazyLoad();
return Promise.resolve()
.then(() => this._lazyLoad.load({
messageCenter,
moduleName: MODULE_NAME,
onLoaded: this._boundOnLoaded,
onUnloaded: this._boundOnUnloaded,
}));
}
unload({messageCenter}) {
return Promise.resolve()
.then(() => this._lazyLoad.unload());
}
_onLoaded(messageCenter) {
// when the module is loaded, do something
}
_onUnloaded(messageCenter) {
// when the module is unloaded, do something
}
}
1.0.0
6 years ago