+1
-1
| { | ||
| "name": "singular", | ||
| "version": "4.2.0-beta1", | ||
| "version": "4.2.1-beta1", | ||
| "description": "Application dependency injection manager", | ||
@@ -5,0 +5,0 @@ "dependencies": { |
+13
-0
| function Factory (layout) { | ||
| this.deps = Object.assign({}, this.constructor.deps) | ||
| layout = Object.assign({}, layout) | ||
| if (! layout) { | ||
@@ -8,2 +10,3 @@ layout = layoutFromDeps(this.deps) | ||
| var deps = this.deps | ||
| Object.getOwnPropertyNames(layout) | ||
@@ -14,3 +17,13 @@ .forEach(function(name) { | ||
| } | ||
| else if (layout[name] === true) { | ||
| layout[name] = name | ||
| } | ||
| }) | ||
| Object.getOwnPropertyNames(deps) | ||
| .forEach(function(name) { | ||
| if (! layout.hasOwnProperty(name)) { | ||
| layout[name] = name | ||
| } | ||
| }) | ||
| } | ||
@@ -17,0 +30,0 @@ |
+49
-11
| const assert = require('assert') | ||
| const Singular = require('../') | ||
| const {Factory} = Singular | ||
| function createUnit({layout = {}, deps, defaults = {}, start, stop = () => {}, value} = {}) { | ||
@@ -403,17 +405,53 @@ if (! start) { | ||
| describe('Singular.Factory.from()', () => { | ||
| it('should create functional unit factory', () => { | ||
| const factory = Singular.Factory.from({ | ||
| start: () => 'factory works', | ||
| describe('Singular.Factory', function() { | ||
| describe('Factory#Factory()', () => { | ||
| it('Should complete layout', () => { | ||
| function TestFactory() { | ||
| Factory.apply(this, arguments) | ||
| } | ||
| TestFactory.deps = { | ||
| a: true, | ||
| } | ||
| Object.setPrototypeOf(TestFactory.prototype, Factory.prototype) | ||
| const unit = new TestFactory() | ||
| assert.equal(unit.layout.a, 'a', 'layout.a is a') | ||
| }) | ||
| const singular = new Singular({ | ||
| units: { | ||
| test: new factory(), | ||
| }, | ||
| it('Should substitute names to layout', () => { | ||
| function TestFactory() { | ||
| Factory.apply(this, arguments) | ||
| } | ||
| TestFactory.deps = { | ||
| a: true, | ||
| } | ||
| Object.setPrototypeOf(TestFactory.prototype, Factory.prototype) | ||
| const unit = new TestFactory({a: true}) | ||
| assert.equal(unit.layout.a, 'a', 'layout.a is a') | ||
| }) | ||
| }) | ||
| return singular.start(1) | ||
| .then(({scope}) => { | ||
| assert.equal(scope.test, 'factory works', 'unit is initialized') | ||
| describe('from()', () => { | ||
| it('should create functional unit factory', () => { | ||
| const factory = Factory.from({ | ||
| start: () => 'factory works', | ||
| }) | ||
| const singular = new Singular({ | ||
| units: { | ||
| test: new factory(), | ||
| }, | ||
| }) | ||
| return singular.start(1) | ||
| .then(({scope}) => { | ||
| assert.equal(scope.test, 'factory works', 'unit is initialized') | ||
| }) | ||
| }) | ||
@@ -420,0 +458,0 @@ }) |
25323
4.79%810
4.79%