Comparing version 0.3.0-beta-1 to 0.3.0-beta-10
@@ -15,3 +15,5 @@ #!/usr/bin/env node | ||
di = fromConfig(conf); | ||
di = fromConfig({ | ||
config: conf | ||
}); | ||
@@ -18,0 +20,0 @@ annotate(di, process.stdout); |
@@ -1,2 +0,2 @@ | ||
// Generated by CoffeeScript 1.8.0 | ||
// Generated by CoffeeScript 1.9.3 | ||
module.exports = function(container) { | ||
@@ -7,3 +7,3 @@ var modules, noValues; | ||
} | ||
modules = container._registrations; | ||
modules = container.getRegistrations(); | ||
noValues = function(i) { | ||
@@ -10,0 +10,0 @@ return modules[i].type !== 'value'; |
@@ -1,2 +0,2 @@ | ||
// Generated by CoffeeScript 1.8.0 | ||
// Generated by CoffeeScript 1.9.3 | ||
var Container, ModuleNotFound, construct, getArguments, runFactory, throwNotFound; | ||
@@ -66,3 +66,3 @@ | ||
if (registeredAt === 'local') { | ||
if (this._instances[name] == null) { | ||
if (!this._isInstantiated(name)) { | ||
this._instantiate(name); | ||
@@ -76,15 +76,17 @@ } | ||
Container.prototype._isInstantiated = function(name) { | ||
return Object.keys(this._instances).indexOf(name) !== -1; | ||
}; | ||
Container.prototype._registeredAt = function(name) { | ||
var i, p, parentIndex, _i, _len, _ref; | ||
var i, j, len, p, parentIndex, ref; | ||
if (this._registrations[name] != null) { | ||
return 'local'; | ||
} else { | ||
i = 0; | ||
_ref = this._parents; | ||
for (_i = 0, _len = _ref.length; _i < _len; _i++) { | ||
p = _ref[_i]; | ||
if (p._registeredAt(name) === 'local') { | ||
ref = this._parents; | ||
for (i = j = 0, len = ref.length; j < len; i = ++j) { | ||
p = ref[i]; | ||
if (p._registeredAt(name) != null) { | ||
parentIndex = i; | ||
} | ||
i++; | ||
} | ||
@@ -99,2 +101,26 @@ return parentIndex; | ||
Container.prototype.getRegistrations = function() { | ||
var all, p; | ||
if (this._parents.length === 0) { | ||
return this._registrations; | ||
} | ||
all = (function() { | ||
var j, len, ref, results; | ||
ref = this._parents; | ||
results = []; | ||
for (j = 0, len = ref.length; j < len; j++) { | ||
p = ref[j]; | ||
results.push(p.getRegistrations()); | ||
} | ||
return results; | ||
}).call(this); | ||
all.push(this._registrations); | ||
return all.reduce(function(acc, item) { | ||
Object.keys(item).forEach(function(key) { | ||
return acc[key] = item[key]; | ||
}); | ||
return acc; | ||
}, {}); | ||
}; | ||
Container.prototype.getArguments = function(name) { | ||
@@ -109,6 +135,6 @@ if (this._modules[name] != null) { | ||
Container.prototype.loadAll = function() { | ||
var p, _i, _len, _ref; | ||
_ref = this._parents; | ||
for (_i = 0, _len = _ref.length; _i < _len; _i++) { | ||
p = _ref[_i]; | ||
var j, len, p, ref; | ||
ref = this._parents; | ||
for (j = 0, len = ref.length; j < len; j++) { | ||
p = ref[j]; | ||
p.loadAll(); | ||
@@ -118,3 +144,3 @@ } | ||
return function(name) { | ||
if (_this._instances[name] == null) { | ||
if (!_this._isInstantiated(name)) { | ||
return _this._instantiate(name); | ||
@@ -126,2 +152,19 @@ } | ||
Container.prototype.shutdown = function() { | ||
var j, len, p, ref, results; | ||
Object.keys(this._instances).forEach((function(_this) { | ||
return function(key) { | ||
var ref; | ||
return (ref = _this._instances[key]) != null ? typeof ref.__amendShutdown === "function" ? ref.__amendShutdown() : void 0 : void 0; | ||
}; | ||
})(this)); | ||
ref = this._parents; | ||
results = []; | ||
for (j = 0, len = ref.length; j < len; j++) { | ||
p = ref[j]; | ||
results.push(p.shutdown()); | ||
} | ||
return results; | ||
}; | ||
Container.prototype._register = function(type, name, value) { | ||
@@ -155,3 +198,7 @@ return this._registrations[name] = { | ||
if (registeredAt === 'local') { | ||
return _this._instances[depName] || _this._instantiate(depName, name); | ||
if (_this._isInstantiated(depName)) { | ||
return _this._instances[depName]; | ||
} else { | ||
return _this._instantiate(depName, name); | ||
} | ||
} else if (registeredAt != null) { | ||
@@ -158,0 +205,0 @@ return _this._parents[registeredAt].get(depName); |
@@ -1,2 +0,2 @@ | ||
// Generated by CoffeeScript 1.8.0 | ||
// Generated by CoffeeScript 1.9.3 | ||
var ARGUMENT_NAMES, STRIP_COMMENTS; | ||
@@ -3,0 +3,0 @@ |
@@ -1,3 +0,3 @@ | ||
// Generated by CoffeeScript 1.8.0 | ||
var Container, evaluateType, getFullPath, getPath, isRelative; | ||
// Generated by CoffeeScript 1.9.3 | ||
var Container, clearCache, evaluateType, getFullPath, getPath, isRelative; | ||
@@ -41,10 +41,23 @@ Container = require('./container'); | ||
clearCache = function(modules, basePath) { | ||
return Object.keys(modules).forEach(function(key) { | ||
var fullPath, moduleConfig, path; | ||
moduleConfig = modules[key]; | ||
path = getPath(moduleConfig); | ||
fullPath = getFullPath(path, basePath); | ||
return delete require.cache[require.resolve(fullPath)]; | ||
}); | ||
}; | ||
module.exports = function(options) { | ||
var basePath, config, di, modules, opts, parent; | ||
config = options.config, basePath = options.basePath, opts = options.opts, parent = options.parent; | ||
var basePath, config, di, modules, opts, parents; | ||
config = options.config, basePath = options.basePath, opts = options.opts, parents = options.parents; | ||
if (config == null) { | ||
throw new TypeError('No configuration was provided for loadConfig'); | ||
} | ||
di = new Container(opts, parent); | ||
di = new Container(opts, parents); | ||
modules = config.modules || {}; | ||
if ((options != null ? options.clearCache : void 0) === true) { | ||
clearCache(modules, basePath); | ||
} | ||
Object.keys(modules).forEach(function(key) { | ||
@@ -51,0 +64,0 @@ var e, fullPath, module, moduleConfig, path, type; |
@@ -1,11 +0,11 @@ | ||
// Generated by CoffeeScript 1.8.0 | ||
// Generated by CoffeeScript 1.9.3 | ||
var ModuleNotFound, | ||
__hasProp = {}.hasOwnProperty, | ||
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; | ||
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, | ||
hasProp = {}.hasOwnProperty; | ||
module.exports = ModuleNotFound = (function(_super) { | ||
__extends(ModuleNotFound, _super); | ||
module.exports = ModuleNotFound = (function(superClass) { | ||
extend(ModuleNotFound, superClass); | ||
function ModuleNotFound(module, caller) { | ||
this.module = module; | ||
function ModuleNotFound(module1, caller) { | ||
this.module = module1; | ||
this.caller = caller; | ||
@@ -12,0 +12,0 @@ this.message = 'Could not find any module with name ' + module; |
{ | ||
"name": "amend", | ||
"version": "0.3.0-beta-1", | ||
"version": "0.3.0-beta-10", | ||
"description": "Dependency injection module and IoC container.", | ||
@@ -14,6 +14,6 @@ "main": "index.js", | ||
"devDependencies": { | ||
"chai": "^1.9.1", | ||
"coffee-script": "^1.8.0", | ||
"mocha": "^1.20.1", | ||
"mocha-gwt": "^0.1.4" | ||
"chai": "^3.2.0", | ||
"coffee-script": "^1.9.0", | ||
"mocha": "^2.0.0", | ||
"mocha-gwt": "^0.2.0" | ||
}, | ||
@@ -30,3 +30,4 @@ "scripts": { | ||
"browserify.js", | ||
"index.js" | ||
"index.js", | ||
"tools.js" | ||
], | ||
@@ -33,0 +34,0 @@ "keywords": [ |
# amend | ||
[![Build Status](https://travis-ci.org/TheLudd/amend.svg)](https://travis-ci.org/TheLudd/amend) | ||
[![npm version](https://badge.fury.io/js/amend.svg)](http://badge.fury.io/js/amend) | ||
Amend is a dependency-injection framework for use in node and in the browser. Amend aims to have no impact on the code you write and to minimize configuration as much as possible. | ||
@@ -13,4 +17,5 @@ | ||
# Current state | ||
Amend is in alpha mode. The dependency injector works but the project is not fully tested for the full development cycle, i.e work in development mode, packge and deploy to production. This is expected to be done in december 2014 since amend will be developed and used together with a production ready project by then. | ||
Amend is in beta mode and has been quite stable for a while. It has been battle tested in a enterprise web application project under development where several modules are put together both front and back end. Version 0.3.0 will have some minor changes to the API along with a few new features. After that not many changes are expected and version 1.0.0 should be released during the spring or early summer of 2015. | ||
# environments | ||
@@ -21,3 +26,3 @@ * Works in node | ||
# introduction | ||
Instead of forcing you to use code specific to this library when creating your components, amend lets you write components using the regular ```require``` and ```module.exports``` function and variable. Depenencies between the components are wired up through a configuration object. This means that unlike many other di frameworks, no variables specific for amend are introduced in your code. | ||
Instead of forcing you to use code specific to this library when creating your components, amend lets you write components using the regular ```require``` and ```module.exports``` function and variable. Depenencies between the components are wired up through a configuration object. This means that unlike many other di frameworks, no variables specific for amend are introduced in your code. | ||
@@ -81,3 +86,3 @@ The configuration is a normal javascript object that maps names of components to their path for require. A module can be one of these three types: | ||
## container.get(name) | ||
## container.get(name) | ||
Returns the component with the specified name. If the component is a factory or a class it will be initialized on the first call to get. On subsquent calls the initialized component will be returned. | ||
@@ -84,0 +89,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
24110
16
359
165
4