reactive-di
Advanced tools
Comparing version 1.0.7 to 1.0.8
@@ -26,3 +26,3 @@ 'use strict'; | ||
describe('HotRelationUpdaterTest', function () { | ||
it('should cache dependency deps', function () { | ||
it('should add dependency', function () { | ||
var _rec = new _powerAssertRecorder(), | ||
@@ -34,27 +34,22 @@ _rec2 = new _powerAssertRecorder(); | ||
}; | ||
var B = function B(c /*: number*/) { | ||
return 2 + c; | ||
var B = function B(a /*: number*/) { | ||
return 2 + a; | ||
}; | ||
var C = function C(a /*: number*/) { | ||
return 3 + a; | ||
}; | ||
var di /*: Container*/ = (0, _createContainer.createContainer)([(0, _configurations.factory)(A), (0, _configurations.factory)(C, A), (0, _configurations.factory)(B, C)], [], true); | ||
var di /*: Container*/ = (0, _createContainer.createContainer)([(0, _configurations.factory)(A), (0, _configurations.factory)(B, A)], [], true); | ||
di.getProvider(C); | ||
var result = di.getProvider(B).dependants.items.map(depName); | ||
var result = di.getProvider(B).dependencies.map(depName); | ||
// console.log(result, di.getProvider(B).displayName) | ||
_powerAssert2.default.deepEqual(_rec._expr(_rec._capt(result, 'arguments/0'), { | ||
content: 'assert.deepEqual(result, [\'factory@B\', \'factory@C\', \'factory@A\'])', | ||
content: 'assert.deepEqual(result, [\'factory@B\', \'factory@A\'])', | ||
filepath: 'src/core/__tests__/updaterTest.js', | ||
line: 38 | ||
}), _rec2._expr(_rec2._capt(['factory@B', 'factory@C', 'factory@A'], 'arguments/1'), { | ||
content: 'assert.deepEqual(result, [\'factory@B\', \'factory@C\', \'factory@A\'])', | ||
line: 33 | ||
}), _rec2._expr(_rec2._capt(['factory@B', 'factory@A'], 'arguments/1'), { | ||
content: 'assert.deepEqual(result, [\'factory@B\', \'factory@A\'])', | ||
filepath: 'src/core/__tests__/updaterTest.js', | ||
line: 38 | ||
line: 33 | ||
})); | ||
}); | ||
it('should wrap deps', function () { | ||
it('should cache dependency deps', function () { | ||
var _rec3 = new _powerAssertRecorder(), | ||
@@ -66,4 +61,4 @@ _rec4 = new _powerAssertRecorder(); | ||
}; | ||
var B = function B(c /*: number*/, a /*: number*/) { | ||
return 2 + c + a; | ||
var B = function B(c /*: number*/) { | ||
return 2 + c; | ||
}; | ||
@@ -73,18 +68,21 @@ var C = function C(a /*: number*/) { | ||
}; | ||
var di /*: Container*/ = (0, _createContainer.createContainer)([(0, _configurations.factory)(A), (0, _configurations.factory)(C, A), (0, _configurations.factory)(B, C, A)], [], true); | ||
var result = di.getProvider(B).dependants.items.map(depName); | ||
var di /*: Container*/ = (0, _createContainer.createContainer)([(0, _configurations.factory)(A), (0, _configurations.factory)(C, A), (0, _configurations.factory)(B, C)], [], true); | ||
di.getProvider(C); | ||
var result = di.getProvider(B).dependencies.map(depName); | ||
// console.log(result, di.getProvider(B).displayName) | ||
_powerAssert2.default.deepEqual(_rec3._expr(_rec3._capt(result, 'arguments/0'), { | ||
content: 'assert.deepEqual(result, [\'factory@B\', \'factory@C\', \'factory@A\'])', | ||
filepath: 'src/core/__tests__/updaterTest.js', | ||
line: 58 | ||
line: 54 | ||
}), _rec4._expr(_rec4._capt(['factory@B', 'factory@C', 'factory@A'], 'arguments/1'), { | ||
content: 'assert.deepEqual(result, [\'factory@B\', \'factory@C\', \'factory@A\'])', | ||
filepath: 'src/core/__tests__/updaterTest.js', | ||
line: 58 | ||
line: 54 | ||
})); | ||
}); | ||
it('should add dependants in A, B->C, C->A: A, B->C&A, C->A', function () { | ||
it('should wrap deps', function () { | ||
var _rec5 = new _powerAssertRecorder(), | ||
@@ -96,4 +94,4 @@ _rec6 = new _powerAssertRecorder(); | ||
}; | ||
var B = function B(c /*: number*/) { | ||
return 2 + c; | ||
var B = function B(c /*: number*/, a /*: number*/) { | ||
return 2 + c + a; | ||
}; | ||
@@ -103,5 +101,5 @@ var C = function C(a /*: number*/) { | ||
}; | ||
var di /*: Container*/ = (0, _createContainer.createContainer)([(0, _configurations.factory)(A), (0, _configurations.factory)(C, A), (0, _configurations.factory)(B, C)], [], true); | ||
var di /*: Container*/ = (0, _createContainer.createContainer)([(0, _configurations.factory)(A), (0, _configurations.factory)(C, A), (0, _configurations.factory)(B, C, A)], [], true); | ||
var result = di.getProvider(B).dependants.items.map(depName); | ||
var result = di.getProvider(B).dependencies.map(depName); | ||
@@ -111,15 +109,13 @@ _powerAssert2.default.deepEqual(_rec5._expr(_rec5._capt(result, 'arguments/0'), { | ||
filepath: 'src/core/__tests__/updaterTest.js', | ||
line: 77 | ||
line: 74 | ||
}), _rec6._expr(_rec6._capt(['factory@B', 'factory@C', 'factory@A'], 'arguments/1'), { | ||
content: 'assert.deepEqual(result, [\'factory@B\', \'factory@C\', \'factory@A\'])', | ||
filepath: 'src/core/__tests__/updaterTest.js', | ||
line: 77 | ||
line: 74 | ||
})); | ||
}); | ||
it('should resolve dependencies after dependants in A, B->C, C->A: A, B->C&A, C->A', function () { | ||
it('should add dependencies in A, B->C, C->A: A, B->C&A, C->A', function () { | ||
var _rec7 = new _powerAssertRecorder(), | ||
_rec8 = new _powerAssertRecorder(), | ||
_rec9 = new _powerAssertRecorder(), | ||
_rec10 = new _powerAssertRecorder(); | ||
_rec8 = new _powerAssertRecorder(); | ||
@@ -137,27 +133,15 @@ var A = function A() { | ||
var dependencies = di.getProvider(A).dependencies; | ||
var result = di.getProvider(B).dependencies.map(depName); | ||
_powerAssert2.default.deepEqual(_rec7._expr(_rec7._capt(_rec7._capt(dependencies, 'arguments/0/callee/object').map(_rec7._capt(depName, 'arguments/0/arguments/0')), 'arguments/0'), { | ||
content: 'assert.deepEqual(dependencies.map(depName), [\'factory@A\'])', | ||
_powerAssert2.default.deepEqual(_rec7._expr(_rec7._capt(result, 'arguments/0'), { | ||
content: 'assert.deepEqual(result, [\'factory@B\', \'factory@C\', \'factory@A\'])', | ||
filepath: 'src/core/__tests__/updaterTest.js', | ||
line: 96 | ||
}), _rec8._expr(_rec8._capt(['factory@A'], 'arguments/1'), { | ||
content: 'assert.deepEqual(dependencies.map(depName), [\'factory@A\'])', | ||
line: 93 | ||
}), _rec8._expr(_rec8._capt(['factory@B', 'factory@C', 'factory@A'], 'arguments/1'), { | ||
content: 'assert.deepEqual(result, [\'factory@B\', \'factory@C\', \'factory@A\'])', | ||
filepath: 'src/core/__tests__/updaterTest.js', | ||
line: 96 | ||
line: 93 | ||
})); | ||
di.getProvider(B); | ||
_powerAssert2.default.deepEqual(_rec9._expr(_rec9._capt(_rec9._capt(dependencies, 'arguments/0/callee/object').map(_rec9._capt(depName, 'arguments/0/arguments/0')), 'arguments/0'), { | ||
content: 'assert.deepEqual(dependencies.map(depName), [\'factory@A\', \'factory@C\', \'factory@B\'])', | ||
filepath: 'src/core/__tests__/updaterTest.js', | ||
line: 102 | ||
}), _rec10._expr(_rec10._capt(['factory@A', 'factory@C', 'factory@B'], 'arguments/1'), { | ||
content: 'assert.deepEqual(dependencies.map(depName), [\'factory@A\', \'factory@C\', \'factory@B\'])', | ||
filepath: 'src/core/__tests__/updaterTest.js', | ||
line: 102 | ||
})); | ||
}); | ||
}); | ||
//# sourceMappingURL=updaterTest.js.map |
@@ -5,5 +5,5 @@ 'use strict'; | ||
var _DisposableCollection = require('../utils/DisposableCollection'); | ||
var _getFunctionName = require('../utils/getFunctionName'); | ||
var _DisposableCollection2 = _interopRequireDefault(_DisposableCollection); | ||
var _getFunctionName2 = _interopRequireDefault(_getFunctionName); | ||
@@ -18,4 +18,3 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
Container, | ||
Provider, | ||
Collection | ||
Provider | ||
} from 'reactive-di/i/coreInterfaces'*/ | ||
@@ -27,10 +26,10 @@ | ||
this.annotation = annotation; | ||
this.kind = annotation.kind; | ||
this.annotation = annotation; | ||
this.dependencies = [this]; | ||
this.dependants = new _DisposableCollection2.default([this]); | ||
this.dependencies = [((this /*: any*/) /*: P*/)]; | ||
this.isCached = false; | ||
this.isDisposed = false; | ||
this.displayName = (annotation /*: any*/).displayName; | ||
this.tags = (annotation /*: any*/).tags; | ||
this.value = (null /*: any*/); | ||
this.displayName = annotation.displayName || annotation.kind + '@' + (0, _getFunctionName2.default)(annotation.target); | ||
this.tags = annotation.tags || []; | ||
} | ||
@@ -44,13 +43,17 @@ | ||
BaseProvider.prototype.update = function update() {}; | ||
BaseProvider.prototype.update = function update() { | ||
this.isCached = true; | ||
}; | ||
BaseProvider.prototype.addDependency = function addDependency(dependency /*: P*/) { | ||
var deps = this.dependencies; | ||
var l = deps.length; | ||
deps[l] = dependency; | ||
deps.length = l + 1; | ||
dependency.addDependant(this); | ||
this.dependencies.push(dependency); | ||
}; | ||
BaseProvider.prototype.addDependant = function addDependant(dependant /*: P*/) { | ||
this.dependants.add(dependant); | ||
}; | ||
BaseProvider.prototype.addDependant = function addDependant(dependant /*: P*/) {}; // eslint-disable-line | ||
return BaseProvider; | ||
@@ -57,0 +60,0 @@ }(); |
@@ -38,9 +38,10 @@ 'use strict'; | ||
HotRelationUpdater.prototype.end = function end(dependency /*: Provider*/) { | ||
HotRelationUpdater.prototype.end = function end(dependant /*: Provider*/) { | ||
var l = this.length - 1; | ||
this.length = l; | ||
var dependantSet = this._dependants[l]; | ||
function iterateMap(dependant /*: Provider*/) /*: void*/ { | ||
function iterateMap(dependency /*: Provider*/) /*: void*/ { | ||
dependant.addDependency(dependency); | ||
} | ||
dependantSet.forEach(iterateMap); | ||
@@ -52,3 +53,3 @@ }; | ||
var deps /*: Array<Provider>*/ = dependency.dependants.items; | ||
var deps /*: Array<Provider>*/ = dependency.dependencies; | ||
var k /*: number*/ = deps.length; | ||
@@ -55,0 +56,0 @@ var l = this.length; |
@@ -9,2 +9,6 @@ 'use strict'; | ||
var _DisposableCollection = require('../../utils/DisposableCollection'); | ||
var _DisposableCollection2 = _interopRequireDefault(_DisposableCollection); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -23,2 +27,3 @@ | ||
/*:: import type { | ||
Collection, | ||
Provider | ||
@@ -30,13 +35,12 @@ } from 'reactive-di/i/coreInterfaces'*/ | ||
function ValueProvider /*:: <V>*/() { | ||
function ValueProvider /*:: <V>*/(annotation /*: ValueAnnotation<V>*/) { | ||
_classCallCheck(this, ValueProvider); | ||
return _possibleConstructorReturn(this, _BaseProvider.apply(this, arguments)); | ||
var _this = _possibleConstructorReturn(this, _BaseProvider.call(this, annotation)); | ||
_this.value = annotation.value; | ||
_this._dependants = new _DisposableCollection2.default(); | ||
return _this; | ||
} | ||
ValueProvider.prototype.init = function init(container /*: Container*/) { | ||
// eslint-disable-line | ||
this.value = this.annotation.value; | ||
}; | ||
ValueProvider.prototype.set = function set(value /*: V*/) { | ||
@@ -48,2 +52,13 @@ this.value = value; | ||
ValueProvider.prototype.reset = function reset() { | ||
var deps = this._dependants.items; | ||
for (var i = 0, l = deps.length; i < l; i++) { | ||
deps[i].isCached = false; | ||
} | ||
}; | ||
ValueProvider.prototype.addDependant = function addDependant(dependant /*: Provider*/) { | ||
this._dependants.add(dependant); | ||
}; | ||
return ValueProvider; | ||
@@ -50,0 +65,0 @@ }(_BaseProvider3.default); |
@@ -32,3 +32,3 @@ /* @flow */ | ||
export type Provider<V, Ann: Annotation, P: Provider> = Disposable & { | ||
export type Provider<V, Ann: Annotation, P> = { | ||
kind: any; | ||
@@ -42,10 +42,5 @@ displayName: string; | ||
*/ | ||
dependencies: Array<Provider|P>; | ||
dependencies: Array<P>; | ||
/** | ||
* Read only dependants | ||
*/ | ||
dependants: Collection<Provider|P>; | ||
/** | ||
* Provider.get read this property if false - recalculates get result. | ||
@@ -52,0 +47,0 @@ * Dependency provider can set isCached to false |
{ | ||
"name": "reactive-di", | ||
"version": "1.0.7", | ||
"version": "1.0.8", | ||
"description": "Reactive dependency injection", | ||
@@ -5,0 +5,0 @@ "publishConfig": { |
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
Sorry, the diff of this file is not supported yet
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
215268
2283