Giter VIP home page Giter VIP logo

salyne's Introduction

salyne

Build Status

Salyne (saline) is a dependency injection library that is largely compatible with electrolyte but is lighter, simpler, and more flexible.

here is a quick example.

// ~/project/index.js  
var Salyne = require('salyne'),
  injector = new Salyne();

injector.load('./lib/foobar.js')

var foobar = injector.create('foobar');

console.log('testing', foobar.foo, foobar.bar);

// ~/project/lib/foobar.js
exports = module.exports = function() {
  this.foo = 5;
  this.bar = 10;
};

This will create a new instance of the foobar dependency. It got its name from the file name. But like I said earlier salyne is flexible. Here are some of the ways you can name your dependencies.

//salyne will grab from the function name if it's available
exports = module.exports = function Foobar() {
  // name will be 'Foobar'
};
// you can also pass a name at load time
injector.load('FooBar', './lib/foobar.js');
// name will be FooBar

I also said that this is a dependency injection library. Here are some ways you can define your dependencies inside your class.

// salyne will take just the argument names just like angular (but they have to be exact)
exports = module.exports = function (foo, bar, bang) {
};
// saylne will also take properties on the function (the params no longer have to be exact or even close)
exports - module.exports = function (foo, bar, bang) {

};
exports.requires = [ 'Foo', 'Baur', 'Zip']
//you can also do the following
exports['@requires'] = [ 'Foo', 'Baur', 'Zip']
exports.require = [ 'Foo', 'Baur', 'Zip']
exports['@require'] = [ 'Foo', 'Baur', 'Zip']

You can also create a singleton really easily!

var foo = 0;
exports = module.exports = function() {
  //foo will never change because you will always be given the same instance.
  this.foo = foo++;
};
exports.singleton = true;
//you can also do the following
exports['@singleton'] = true;

You can also bind constructors directly.

injector.bind('bar', function() {
  this.item = 'testing';
});
var bar = injector.create('bar');

These are also flexible.

injector.bind({ singleton : true }, function Bang() {
  this.bang = 'also testing';
});
var bang = injector.create('Bang');

salyne's People

Contributors

from-nibly avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.