Comparing version 0.5.7 to 0.5.8
@@ -13,39 +13,14 @@ declare module pang { | ||
class Domain { | ||
private started; | ||
private dependencies; | ||
constructor(); | ||
/** | ||
* sets up a factory on this domain | ||
*/ | ||
public factory(name: string, initializer: (...args: any[]) => any): Domain; | ||
/** | ||
* returns a single instance of this dependency | ||
*/ | ||
public singleton(name: string): any; | ||
/** | ||
* returns a transient / new instance of this dependency | ||
*/ | ||
public transient(name: string): any; | ||
/** | ||
* returns a dependency managed in this domain. | ||
*/ | ||
public dependency(name: string): Dependency; | ||
/** | ||
* starts the domain | ||
*/ | ||
public start(): void; | ||
/** | ||
* tests this object to ensure its a function | ||
*/ | ||
public get_dependency(name: string): Dependency; | ||
private isfunction(obj); | ||
/** | ||
* extracts the arguments from this function | ||
*/ | ||
private extractargs(func); | ||
} | ||
/** | ||
* returns a new domain | ||
*/ | ||
function domain(): Domain; | ||
} | ||
declare var module: any; |
104
index.js
@@ -36,3 +36,3 @@ /*-------------------------------------------------------------------------- | ||
var dependancies = this.names.map(function (name, index, list) { | ||
var dependency = _this.domain.dependency(name); | ||
var dependency = _this.domain.get_dependency(name); | ||
@@ -44,2 +44,3 @@ if (dependency) { | ||
} | ||
return null; | ||
@@ -59,9 +60,7 @@ }); | ||
function Domain() { | ||
this.started = false; | ||
this.dependencies = []; | ||
} | ||
/** | ||
* sets up a factory on this domain | ||
*/ | ||
//---------------------------------------------- | ||
// create a new dependency | ||
//---------------------------------------------- | ||
Domain.prototype.factory = function (name, initializer) { | ||
@@ -76,3 +75,3 @@ if (this.isfunction(initializer)) { | ||
this.dependencies.push(new Dependency(this, name, [], function () { | ||
this.dependencies.push(new pang.Dependency(this, name, [], function () { | ||
return initializer; | ||
@@ -84,20 +83,22 @@ }, false, null)); | ||
/** | ||
* returns a single instance of this dependency | ||
*/ | ||
//---------------------------------------------- | ||
// returns a single instance of this dependency | ||
//---------------------------------------------- | ||
Domain.prototype.singleton = function (name) { | ||
this.start(); | ||
var dependency = this.get_dependency(name); | ||
for (var i = 0; i < this.dependencies.length; i++) { | ||
if (this.dependencies[i].name == name) { | ||
return this.dependencies[i].instance; | ||
} | ||
var instance = null; | ||
if (dependency) { | ||
dependency.boot(); | ||
instance = dependency.instance; | ||
} | ||
return null; | ||
return instance; | ||
}; | ||
/** | ||
* returns a transient / new instance of this dependency | ||
*/ | ||
//---------------------------------------------- | ||
// returns a new instance of this dependency | ||
//---------------------------------------------- | ||
Domain.prototype.transient = function (name) { | ||
@@ -110,12 +111,10 @@ var domain = new pang.Domain(); | ||
for (var i = 0; i < domain.dependencies.length; i++) { | ||
if (domain.dependencies[i].name == name) { | ||
domain.dependencies[i].boot(); | ||
var dependency = domain.get_dependency(name); | ||
var instance = domain.dependencies[i].instance; | ||
var instance = null; | ||
domain.dependencies = []; | ||
if (dependency) { | ||
dependency.boot(); | ||
return instance; | ||
} | ||
instance = dependency.instance; | ||
} | ||
@@ -125,10 +124,19 @@ | ||
return null; | ||
return instance; | ||
}; | ||
/** | ||
* returns a dependency managed in this domain. | ||
*/ | ||
Domain.prototype.dependency = function (name) { | ||
//---------------------------------------------- | ||
// starts all dependencies | ||
//---------------------------------------------- | ||
Domain.prototype.start = function () { | ||
for (var i = 0; i < this.dependencies.length; i++) { | ||
this.dependencies[i].boot(); | ||
} | ||
}; | ||
//---------------------------------------------- | ||
// returns a single instance of this dependency | ||
//---------------------------------------------- | ||
Domain.prototype.get_dependency = function (name) { | ||
for (var i = 0; i < this.dependencies.length; i++) { | ||
if (this.dependencies[i].name == name) { | ||
@@ -142,18 +150,5 @@ return this.dependencies[i]; | ||
/** | ||
* starts the domain | ||
*/ | ||
Domain.prototype.start = function () { | ||
if (!this.started) { | ||
this.started = true; | ||
for (var i = 0; i < this.dependencies.length; i++) { | ||
this.dependencies[i].boot(); | ||
} | ||
} | ||
}; | ||
/** | ||
* tests this object to ensure its a function | ||
*/ | ||
//---------------------------------------------- | ||
// tests for a function | ||
//---------------------------------------------- | ||
Domain.prototype.isfunction = function (obj) { | ||
@@ -165,5 +160,5 @@ var getType = {}; | ||
/** | ||
* extracts the arguments from this function | ||
*/ | ||
//---------------------------------------------- | ||
// extracts parameter names from a function | ||
//---------------------------------------------- | ||
Domain.prototype.extractargs = function (func) { | ||
@@ -177,2 +172,3 @@ var match = /\(([^)]+)/.exec(func.toString()); | ||
} | ||
return []; | ||
@@ -184,7 +180,7 @@ }; | ||
/** | ||
* returns a new domain | ||
*/ | ||
//---------------------------------------------- | ||
// returns a new domain | ||
//---------------------------------------------- | ||
function domain() { | ||
return new Domain(); | ||
return new pang.Domain(); | ||
} | ||
@@ -191,0 +187,0 @@ pang.domain = domain; |
{ | ||
"name": "pang", | ||
"version": "0.5.7", | ||
"version": "0.5.8", | ||
"description": "A simple dependency injection library for node", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10212
171