0.0.8 • Published 6 years ago

baptiste v0.0.8

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

Baptiste

dependency injection electrolyte-driven module builder

Injection Example

components/a.js

exports = module.exports = function(){
  return {
    foo : "bar"
  }
}
exports['@singleton'] = false;

components/b.js

exports = module.exports = function(a){
  return {
    a: a
  }
}
exports['@require'] = ['a'];
exports['@singleton'] = true;

index.js

const path = require('path');
const baptiste = require('../index.js');

var mdl = baptiste.buildModule({
  paths: [
    path.join(__dirname, 'components')
  ],
  components : ['a', 'b'],
  entry: 'b'
})

mdl.create({ a : {foo2: "bar2"}}).then(function(b){
  // b.a.foo2 is "bar2"
  // do your stuff here
});

Extend Example

Extension is useful if you want to use components from a first module (in real-life the module will be npm-git-package) into another module.

components2/c.js

module.exports = function (a) {
	return {
		a
	};
};
exports = module.exports;
exports['@require'] = ['a'];
exports['@singleton'] = true;

index.js

const path = require('path');
const baptiste = require('baptiste');

const mdla = baptiste.buildModule({
	paths: [
		path.join(__dirname, 'components')
	],
	components: ['a', 'b'],
	entry: 'b'
});

const mdlb = baptiste.buildModule({
	paths: [
		path.join(__dirname, 'components2')
	],
	components: ['c'],
  required: ['a'],
	entry: 'c'
});

mdla.extend(mdlb).create().then(c => {
  // c.a.foo === "bar"
  // now c has been instanciated with a
});
0.0.8

6 years ago

0.0.7

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago