Comparing version 0.1.0 to 1.0.0
@@ -49,3 +49,3 @@ var getArgs = require('typedef').getArguments; | ||
*/ | ||
Container.prototype.singleton = function(name, T) | ||
Container.prototype.shared = function(name, T) | ||
{ | ||
@@ -71,5 +71,11 @@ return this.register(name, T, true); | ||
{ | ||
var deps; | ||
var _this = this; | ||
// Use parameter names of the function to bring in more deps | ||
if (name instanceof Function) | ||
return this.makeFromConstructor(name); | ||
if (name instanceof Function) { | ||
var T = name; | ||
deps = _(getArgs(T)).map(function(d) { return _this.make(d); }); | ||
return callNew(T, deps); | ||
} | ||
@@ -87,8 +93,6 @@ // Nop if we are passing in something weird | ||
// Resolve all string deps into make deps | ||
var _this = this; | ||
var instance; | ||
if (!info.shared || !info.instance) { | ||
var deps = info.deps.map(function(d) { return _this.make(d); }); | ||
deps = _(info.deps).map(function(d) { return _this.make(d); }); | ||
instance = callNew(info.type, deps); | ||
@@ -116,14 +120,2 @@ | ||
/** | ||
* Create an object by resolving deps for a class not in the container (but | ||
* whose deps are) | ||
* @param {Function} T Constructor function. | ||
*/ | ||
Container.prototype.makeFromConstructor = function(T) | ||
{ | ||
var _this = this; | ||
var deps = getArgs(T).map(function(d) { return _this.make(d); }); | ||
return callNew(T, deps); | ||
}; | ||
/** | ||
* Resolve the name of a dep | ||
@@ -130,0 +122,0 @@ * @param {String} name The dep name. |
{ | ||
"name": "sack", | ||
"version": "0.1.0", | ||
"version": "1.0.0", | ||
"description": "Inversion-of-control container for all your dependency injection needs.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -81,3 +81,3 @@ var test = require('tape'); | ||
r.register('a', A); | ||
r.makeFromConstructor(T); | ||
r.make(T); | ||
@@ -91,3 +91,3 @@ }); | ||
function T() { t.ok(true, 'T ctor fired'); } | ||
r.singleton('t', T); | ||
r.shared('t', T); | ||
@@ -111,3 +111,3 @@ t.strictEqual(r.make('t'), r.make('t'), 'Same instance created'); | ||
r.register('a', A); | ||
r.singleton('t', T); | ||
r.shared('t', T); | ||
@@ -114,0 +114,0 @@ r.make('t'); |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
1
11817
227