Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

esrol-initializer

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

esrol-initializer

An Initializer Class used for adding and initializing components. Priority must exist between them.

  • 0.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
9
Maintainers
1
Weekly downloads
 
Created
Source

NPM version Build Status Test coverage

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

setCallback(fn)boolean

Set a callback which will be called when all components are resolved.

registerComponent(component)boolean

Register a new component object. Re-sort (re-prioritize) components with the new one.

instantiateComponents()

Instantiate all components.

## setCallback(fn) ⇒ boolean Set a callback which will be called when all components are resolved.

Returns: boolean - true - on success Throws:

  • error error - if parameter is not a function
ParamTypeDescription
fnfunctionthe 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
ParamTypeDescription
componentobjectholds two properties - { priority: 1, component: function() {} }

instantiateComponents()

Instantiate all components.

Contriubtion

Any contribution will be highly appreciated. Just make sure that:

  1. Your code works.
  2. You have 100% successful tests coverage.
  3. You have comments in your code.
  4. 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

License

MIT

Keywords

FAQs

Package last updated on 28 Dec 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc