0.1.1 • Published 8 years ago
esrol-initializer v0.1.1
esrol-initializer
An Initializer Class used for adding and initializing components. Priority must exist between them.
Part of Esrol
Installation
$ npm install --save esrol-initializer
Usage
'use strict';
let Initializer = require('../lib/initializer');
let initializer = new Initializer();
let foo = {
priority: 1,
component: function() {
console.log('foo component is resolved');
}
};
let promise = new Promise((resolve, reject) => {
// some async stuff
setTimeout(() => {
resolve();
}, 500);
});
promise.then(() => {
console.log('promisified component is resolved');
});
let promisifiedComponent = {
priority: 2,
component: function() {
console.log('promisified component is instantiated');
return promise;
}
};
let bar = {
priority: 3,
component: function() {
console.log('bar component is resolved');
}
};
let onResolvedComponents = function() {
console.log('all components are resolved');
};
initializer.setCallback(onResolvedComponents);
initializer.registerComponent(promisifiedComponent);
initializer.registerComponent(foo);
initializer.registerComponent(bar);
initializer.instantiateComponents();
Methods
Returns: boolean - true - on success Throws:
- error error - if parameter is not a function
Param | Type | Description |
---|---|---|
fn | function | the callback function that needs to be executed when all components are resolved |
registerComponent(component) ⇒ boolean
Register a new component object. Re-sort (re-prioritize) components with the new one.
Returns: boolean - true - on success Throws:
- error error - if component object isn't as expected
Param | Type | Description |
---|---|---|
component | object | holds two properties - { priority: 1, component: function() {} } |
instantiateComponents()
Instantiate all components.
Contriubtion
Any contribution will be highly appreciated. Just make sure that:
- Your code works.
- You have 100% successful tests coverage.
- You have comments in your code.
- Follows eslint config. Exceptions are possible where that make sense.
Tests
To run the test suite, first install the dependencies, then run npm test
:
$ npm install
$ npm test