Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pang

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pang - npm Package Compare versions

Comparing version 0.5.3 to 0.5.4

51

index.js

@@ -32,3 +32,3 @@ /*--------------------------------------------------------------------------

}
Dependency.prototype.initialize = function () {
Dependency.prototype.boot = function () {
var _this = this;

@@ -40,3 +40,3 @@ if (!this.initialized) {

if (dependency) {
dependency.initialize();
dependency.boot();

@@ -60,2 +60,4 @@ return dependency.instance;

function Domain() {
this.started = false;
this.dependencies = [];

@@ -81,5 +83,7 @@ }

/**
* returns the instance associated with this name
* returns a single instance of this dependency
*/
Domain.prototype.get = function (name) {
Domain.prototype.singleton = function (name) {
this.start();
for (var i = 0; i < this.dependencies.length; i++) {

@@ -95,4 +99,33 @@ if (this.dependencies[i].name == name) {

/**
* returns the dependency type on this domain
* returns a transient / new instance of this dependency
*/
Domain.prototype.transient = function (name) {
var domain = new pang.Domain();
for (var i = 0; i < this.dependencies.length; i++) {
var dependency = new Dependency(domain, this.dependencies[i].name, this.dependencies[i].names, this.dependencies[i].initializer, false, null);
domain.dependencies.push(dependency);
}
for (var i = 0; i < domain.dependencies.length; i++) {
if (domain.dependencies[i].name == name) {
domain.dependencies[i].boot();
var instance = domain.dependencies[i].instance;
domain.dependencies = [];
return instance;
}
}
domain.dependencies = [];
return null;
};
/**
* returns a dependency managed in this domain.
*/
Domain.prototype.dependency = function (name) {

@@ -112,4 +145,8 @@ for (var i = 0; i < this.dependencies.length; i++) {

Domain.prototype.start = function () {
for (var i = 0; i < this.dependencies.length; i++) {
this.dependencies[i].initialize();
if (!this.started) {
this.started = true;
for (var i = 0; i < this.dependencies.length; i++) {
this.dependencies[i].boot();
}
}

@@ -116,0 +153,0 @@ };

2

package.json
{
"name": "pang",
"version": "0.5.3",
"version": "0.5.4",
"description": "A simple dependency injection library for node",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -9,4 +9,3 @@ # pang

The following example illustates setting up a pang kernel. Configuration, Repository and Server are
all application types, they are ommited for clarify.
The following example illustates setting up a pang domain/kernel.

@@ -19,6 +18,3 @@ ```javascript

//---------------------------------------
// no injection
//---------------------------------------
domain.factory('configuration', function(){
domain.factory('configuration', function() {

@@ -28,5 +24,2 @@ return new Configuration()

//---------------------------------------
// configuration injected on repository
//---------------------------------------
domain.factory('repository', function(configuration) {

@@ -37,5 +30,2 @@

//--------------------------------------------------
// configuration and repository injected on server
//--------------------------------------------------
domain.factory('server', function(configuration, repository) {

@@ -46,10 +36,18 @@

domain.start()
### domain.start()
//--------------------------------------------------
// get a instance from the domain
//--------------------------------------------------
Boots all instances in this domain and caches within the domain.
var server = domain.get('server')
domain.start()
```
### domain.singleton()
Returns a singleton instance from the domain. Will automatically start() the domain if not already started.
var instance = domain.singleton('server')
### domain.transient()
Returns a transient (new) instance from the domain.
var instance = domain.transient('server')
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc