2.0.4 • Published 6 years ago

ioc-core v2.0.4

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

ioc-core

Simple inversion of control core component for NodeJs.

Injects components dependencies and config into other components.

Installation

npm install ioc-core

Usage

## Core boostrap

var core = require('ioc-core');

// Config definition
core.config = {
    // This map contains a list of components to load
    ioc: {
        componentName: "/path/to/ComponentClass.js",
        otherComponent: "/path/to/OtherComponent.js",
        myComponent: "/path/to/MyComponent.js",
    },

    // This config will be available in all components in core.config
    foo: "bar",
    foo2: "bar2"
};

// Load one component and its dependencies
core.load("myComponent").then(function(myComponent) {
    // Here you can use myComponent.
});

// Load multiple components
core.load("myComponent", "otherComponent").spread(function(myComponent, otherComponent) {
    // Here you can use myComponent and otherComponent.
});

// ...or using an array :
core.load(["myComponent", "otherComponent"]).spread(function(myComponent, otherComponent) {
    // Here you can use myComponent and otherComponent.
});

## Components

Every component should respect one of the following formats :

function MyComponent(componentName, otherComponent) {
    // Component code
}
2.0.4

6 years ago

2.0.3

8 years ago

2.0.2

8 years ago

2.0.1

8 years ago

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago