reactive-di
Advanced tools
Comparing version 1.0.2 to 1.0.3
@@ -53,4 +53,4 @@ 'use strict'; | ||
var newDi /*: Container*/ = (0, _createContainer.createContainer)([(0, _configurations.factory)(A)]); | ||
(0, _powerAssert2.default)(_rec2._expr(_rec2._capt(_rec2._capt(_rec2._capt(newDi, 'arguments/0/left/callee/object').getResolver(_rec2._capt(A, 'arguments/0/left/arguments/0')), 'arguments/0/left') === _rec2._capt(_rec2._capt(newDi, 'arguments/0/right/callee/object').getResolver(_rec2._capt(A, 'arguments/0/right/arguments/0')), 'arguments/0/right'), 'arguments/0'), { | ||
content: 'assert(newDi.getResolver(A) === newDi.getResolver(A))', | ||
(0, _powerAssert2.default)(_rec2._expr(_rec2._capt(_rec2._capt(_rec2._capt(newDi, 'arguments/0/left/callee/object').getProvider(_rec2._capt(A, 'arguments/0/left/arguments/0')), 'arguments/0/left') === _rec2._capt(_rec2._capt(newDi, 'arguments/0/right/callee/object').getProvider(_rec2._capt(A, 'arguments/0/right/arguments/0')), 'arguments/0/right'), 'arguments/0'), { | ||
content: 'assert(newDi.getProvider(A) === newDi.getProvider(A))', | ||
filepath: 'src/core/__tests__/cacheTest.js', | ||
@@ -57,0 +57,0 @@ line: 38 |
'use strict'; | ||
exports.__esModule = true; | ||
exports.getProvider = getProvider; | ||
exports.createContainer = createContainer; | ||
@@ -14,12 +13,5 @@ | ||
Container, | ||
Provider, | ||
ContainerManager, | ||
CreateContainerManager | ||
} from 'reactive-di/i/coreInterfaces'*/ | ||
function getProvider(container /*: Container*/, dep /*: DependencyKey*/) /*: Provider*/ { | ||
var cache = ((container /*: any*/)._helper /*: any*/)._cache; | ||
return cache.get(dep); | ||
} | ||
function createContainer(config /*: Array<Annotation>*/, raw /*: Array<[DependencyKey, Array<Tag|DependencyKey>]>*/) /*: Container*/ { | ||
@@ -26,0 +18,0 @@ var isHot /*: ?boolean*/ = arguments.length <= 2 || arguments[2] === undefined ? false : arguments[2]; |
@@ -42,14 +42,14 @@ 'use strict'; | ||
di.getResolver(C); | ||
di.getResolver(B); | ||
var result = (0, _createContainer.getProvider)(di, B).getDependants().map(depName); | ||
di.getProvider(C); | ||
var result = di.getProvider(B).dependants.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\'])', | ||
filepath: 'src/core/__tests__/updaterTest.js', | ||
line: 39 | ||
line: 38 | ||
}), _rec2._expr(_rec2._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: 39 | ||
line: 38 | ||
})); | ||
@@ -73,4 +73,3 @@ }); | ||
di.getResolver(B); | ||
var result = (0, _createContainer.getProvider)(di, B).getDependants().map(depName); | ||
var result = di.getProvider(B).dependants.map(depName); | ||
@@ -80,7 +79,7 @@ _powerAssert2.default.deepEqual(_rec3._expr(_rec3._capt(result, 'arguments/0'), { | ||
filepath: 'src/core/__tests__/updaterTest.js', | ||
line: 59 | ||
line: 58 | ||
}), _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: 59 | ||
line: 58 | ||
})); | ||
@@ -103,13 +102,13 @@ }); | ||
var di /*: Container*/ = (0, _createContainer.createContainer)([(0, _configurations.factory)(A), (0, _configurations.factory)(C, A), (0, _configurations.factory)(B, C)], [], true); | ||
di.getResolver(B); | ||
var result = (0, _createContainer.getProvider)(di, B).getDependants().map(depName); | ||
var result = di.getProvider(B).dependants.map(depName); | ||
_powerAssert2.default.deepEqual(_rec5._expr(_rec5._capt(result, 'arguments/0'), { | ||
content: 'assert.deepEqual(result, [\'factory@B\', \'factory@C\', \'factory@A\'])', | ||
filepath: 'src/core/__tests__/updaterTest.js', | ||
line: 78 | ||
line: 77 | ||
}), _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: 78 | ||
line: 77 | ||
})); | ||
@@ -134,16 +133,16 @@ }); | ||
var di /*: Container*/ = (0, _createContainer.createContainer)([(0, _configurations.factory)(A), (0, _configurations.factory)(C, A), (0, _configurations.factory)(B, C)], [], true); | ||
di.getResolver(A); | ||
var dependencies = (0, _createContainer.getProvider)(di, A).getDependencies(); | ||
var dependencies = di.getProvider(A).dependencies; | ||
_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\'])', | ||
filepath: 'src/core/__tests__/updaterTest.js', | ||
line: 97 | ||
line: 96 | ||
}), _rec8._expr(_rec8._capt(['factory@A'], 'arguments/1'), { | ||
content: 'assert.deepEqual(dependencies.map(depName), [\'factory@A\'])', | ||
filepath: 'src/core/__tests__/updaterTest.js', | ||
line: 97 | ||
line: 96 | ||
})); | ||
di.getResolver(B); | ||
di.getProvider(B); | ||
@@ -153,7 +152,7 @@ _powerAssert2.default.deepEqual(_rec9._expr(_rec9._capt(_rec9._capt(dependencies, 'arguments/0/callee/object').map(_rec9._capt(depName, 'arguments/0/arguments/0')), 'arguments/0'), { | ||
filepath: 'src/core/__tests__/updaterTest.js', | ||
line: 103 | ||
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: 103 | ||
line: 102 | ||
})); | ||
@@ -160,0 +159,0 @@ }); |
@@ -5,8 +5,2 @@ 'use strict'; | ||
var _getFunctionName = require('../utils/getFunctionName'); | ||
var _getFunctionName2 = _interopRequireDefault(_getFunctionName); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
@@ -17,3 +11,2 @@ | ||
Annotation, | ||
Resolver, | ||
Container, | ||
@@ -29,36 +22,29 @@ Provider | ||
this.annotation = annotation; | ||
this._dependencies = [this]; | ||
this._dependants = [this]; | ||
var fnName /*: string*/ = (0, _getFunctionName2.default)(annotation.target); | ||
this.displayName = this.kind + '@' + fnName; | ||
this.tags = [this.kind].concat(annotation.tags || []); | ||
this.dependencies = [this]; | ||
this.dependants = [this]; | ||
this.isCached = false; | ||
this.isDisposed = false; | ||
this.displayName = (annotation /*: any*/).displayName; | ||
this.tags = (annotation /*: any*/).tags; | ||
} | ||
BaseProvider.prototype.createResolver = function createResolver(container /*: Container*/) { | ||
// eslint-disable-line | ||
throw new Error('Implement resolver'); | ||
BaseProvider.prototype.init = function init(container /*: Container*/) {}; // eslint-disable-line | ||
BaseProvider.prototype.dispose = function dispose() { | ||
this.isDisposed = true; | ||
}; | ||
BaseProvider.prototype.getDependencies = function getDependencies() { | ||
return this._dependencies; | ||
BaseProvider.prototype.get = function get() { | ||
return null; | ||
}; | ||
BaseProvider.prototype.addDependency = function addDependency(dependency /*: Provider*/) { | ||
BaseProvider.prototype.addDependency = function addDependency(dependency /*: P*/) { | ||
dependency.addDependant(this); | ||
this._dependencies.push(dependency); | ||
this.dependencies.push(dependency); | ||
}; | ||
/** | ||
* All dependants | ||
*/ | ||
BaseProvider.prototype.getDependants = function getDependants() { | ||
return this._dependants; | ||
BaseProvider.prototype.addDependant = function addDependant(dependant /*: P*/) { | ||
this.dependants.push(dependant); | ||
}; | ||
BaseProvider.prototype.addDependant = function addDependant(dependant /*: Provider*/) { | ||
this._dependants.push(dependant); | ||
}; | ||
return BaseProvider; | ||
@@ -65,0 +51,0 @@ }(); |
@@ -13,5 +13,5 @@ 'use strict'; | ||
var _normalizeConfiguration = require('./normalizeConfiguration'); | ||
var _AnnotationMap = require('./AnnotationMap'); | ||
var _normalizeConfiguration2 = _interopRequireDefault(_normalizeConfiguration); | ||
var _AnnotationMap2 = _interopRequireDefault(_AnnotationMap); | ||
@@ -22,6 +22,2 @@ var _SimpleMap = require('../utils/SimpleMap'); | ||
var _getFunctionName = require('../utils/getFunctionName'); | ||
var _getFunctionName2 = _interopRequireDefault(_getFunctionName); | ||
var _annotationDriver = require('./annotationDriver'); | ||
@@ -35,5 +31,5 @@ | ||
var _createDefaultContainer = require('./createDefaultContainer'); | ||
var _DiContainer = require('./DiContainer'); | ||
var _createDefaultContainer2 = _interopRequireDefault(_createDefaultContainer); | ||
var _DiContainer2 = _interopRequireDefault(_DiContainer); | ||
@@ -58,8 +54,4 @@ var _defaultPlugins = require('../plugins/defaultPlugins'); | ||
/*:: import type { | ||
Provider, | ||
Plugin, | ||
RelationUpdater, | ||
CreateContainer, | ||
ContainerProps, | ||
ContainerHelper, | ||
Container, | ||
@@ -73,14 +65,11 @@ ContainerManager | ||
var DefaultContainerManager = function () { | ||
function DefaultContainerManager(annotations /*: Map<DependencyKey, Annotation>*/, plugins /*: Map<string, Plugin>*/, updater /*: RelationUpdater*/, createContainer /*: CreateContainer*/) { | ||
function DefaultContainerManager(annotations /*: AnnotationMap*/, plugins /*: Map<string, Plugin>*/, updater /*: RelationUpdater*/) { | ||
_classCallCheck(this, DefaultContainerManager); | ||
this._createContainer = createContainer; | ||
this._annotations = annotations; | ||
this._cache = new _SimpleMap2.default(); | ||
this._plugins = plugins; | ||
this._updater = updater; | ||
this._containers = []; | ||
this._middlewares = new _SimpleMap2.default(); | ||
this._updater = updater; | ||
} | ||
@@ -93,57 +82,13 @@ | ||
/** | ||
* @see ContainerHelper interface | ||
*/ | ||
DefaultContainerManager.prototype.createContainer = function createContainer(parent /*: Container*/) { | ||
var container /*: Container*/ = void 0; | ||
var self = this; | ||
DefaultContainerManager.prototype.removeContainer = function removeContainer(container /*: Container*/) { | ||
this._containers = this._containers.filter(function (target) { | ||
return target !== container; | ||
}); | ||
}; | ||
/** | ||
* @see ContainerHelper interface | ||
*/ | ||
DefaultContainerManager.prototype.createProvider = function createProvider(annotatedDep /*: DependencyKey*/, isParent /*: boolean*/) { | ||
var provider /*: ?Provider*/ = this._cache.get(annotatedDep); | ||
if (provider) { | ||
return provider; | ||
function dispose() /*: void*/ { | ||
self._containers = self._containers.filter(function (target) { | ||
return target !== container; | ||
}); | ||
} | ||
var annotation /*: ?Annotation*/ = this._annotations.get(annotatedDep); | ||
if (!annotation) { | ||
if (!isParent) { | ||
annotation = _annotationDriver2.default.getAnnotation((annotatedDep /*: Dependency*/)); | ||
if (!annotation) { | ||
return null; | ||
} | ||
} else { | ||
return null; | ||
} | ||
} | ||
var plugin /*: ?Plugin*/ = this._plugins.get(annotation.kind); | ||
if (!plugin) { | ||
throw new Error('Provider not found for annotation ' + (0, _getFunctionName2.default)(annotation.target)); | ||
} | ||
provider = plugin.create(annotation); | ||
this._cache.set(annotatedDep, provider); | ||
return provider; | ||
}; | ||
DefaultContainerManager.prototype.createContainer = function createContainer(parent /*: Container*/) { | ||
var props /*: ContainerProps*/ = { | ||
helper: (this /*: ContainerHelper*/), | ||
middlewares: this._middlewares, | ||
updater: this._updater, | ||
parent: parent | ||
}; | ||
var container /*: Container*/ = this._createContainer(props); | ||
container = new _DiContainer2.default(dispose, this._middlewares, this._updater, this._plugins, this._annotations, parent); | ||
this._containers.push(container); | ||
@@ -155,15 +100,6 @@ | ||
DefaultContainerManager.prototype._delete = function _delete(oldDep /*: DependencyKey*/) { | ||
var cache = this._cache; | ||
var provider /*: ?Provider*/ = cache.get(oldDep); | ||
if (provider) { | ||
var containers = this._containers; | ||
var k = containers.length; | ||
var dependants = provider.getDependants(); | ||
for (var i = 0, l = dependants.length; i < l; i++) { | ||
var target = dependants[i].annotation.target; | ||
cache.delete(target); | ||
for (var j = 0; j < k; j++) { | ||
containers[j].delete(target); | ||
} | ||
} | ||
var containers = this._containers; | ||
var k = containers.length; | ||
for (var j = 0; j < k; j++) { | ||
containers[j].delete(oldDep); | ||
} | ||
@@ -231,3 +167,2 @@ }; | ||
var createUpdater /*:: ?: () => RelationUpdater*/ = arguments.length <= 1 || arguments[1] === undefined ? _createDummyRelationUpdater2.default : arguments[1]; | ||
var createContainer /*:: ?: CreateContainer*/ = arguments.length <= 2 || arguments[2] === undefined ? _createDefaultContainer2.default : arguments[2]; | ||
@@ -239,5 +174,5 @@ var plugins /*: Map<string, Plugin>*/ = (0, _createPluginsMap2.default)(pluginsConfig); | ||
return new DefaultContainerManager((0, _normalizeConfiguration2.default)(config), plugins, createUpdater(), createContainer); | ||
return new DefaultContainerManager(new _AnnotationMap2.default(config), plugins, createUpdater()); | ||
}; | ||
} | ||
//# sourceMappingURL=createManagerFactory.js.map |
@@ -17,3 +17,3 @@ 'use strict'; | ||
this.dependants = []; | ||
this.length = 0; | ||
} | ||
@@ -27,3 +27,3 @@ | ||
DummyRelationUpdater.prototype.inheritRelations = function inheritRelations(provider /*: Provider*/) {}; | ||
DummyRelationUpdater.prototype.addCached = function addCached(provider /*: Provider*/) {}; | ||
@@ -30,0 +30,0 @@ return DummyRelationUpdater; |
@@ -23,16 +23,21 @@ 'use strict'; | ||
this.dependants = []; | ||
this._dependants = []; | ||
this.length = 0; | ||
} | ||
HotRelationUpdater.prototype.begin = function begin(dependency /*: Provider*/) { | ||
var dependants = this.dependants; | ||
var deps = this._dependants; | ||
for (var i = 0, l = dependants.length; i < l; i++) { | ||
dependants[i].add(dependency); | ||
var l = this.length; | ||
for (var i = 0; i < l; i++) { | ||
deps[i].add(dependency); | ||
} | ||
dependants.push(new _SimpleSet2.default()); | ||
deps[l] = new _SimpleSet2.default(); | ||
this.length = l + 1; | ||
}; | ||
HotRelationUpdater.prototype.end = function end(dependency /*: Provider*/) { | ||
var dependantSet = this.dependants.pop(); | ||
var l = this.length - 1; | ||
this.length = l; | ||
var dependantSet = this._dependants[l]; | ||
function iterateMap(dependant /*: Provider*/) /*: void*/ { | ||
@@ -44,11 +49,12 @@ dependant.addDependency(dependency); | ||
HotRelationUpdater.prototype.inheritRelations = function inheritRelations(dependency /*: Provider*/) { | ||
var l /*: number*/ = this.dependants.length; | ||
var dependants /*: Array<Set<Provider>>*/ = this.dependants; | ||
var inheritDependants /*: Array<Provider>*/ = dependency.getDependants(); | ||
var k /*: number*/ = inheritDependants.length; | ||
HotRelationUpdater.prototype.addCached = function addCached(dependency /*: Provider*/) { | ||
var dependants = this._dependants; | ||
var deps /*: Array<Provider>*/ = dependency.dependants; | ||
var k /*: number*/ = deps.length; | ||
var l = this.length; | ||
for (var i = 0; i < l; i++) { | ||
var dependantSet /*: Set<Provider>*/ = dependants[i]; | ||
for (var j = 0; j < k; j++) { | ||
dependantSet.add(inheritDependants[j]); | ||
dependantSet.add(deps[j]); | ||
} | ||
@@ -55,0 +61,0 @@ } |
'use strict'; | ||
exports.__esModule = true; | ||
exports.defaultPlugins = exports.createManagerFactory = exports.BaseProvider = exports.SimpleMap = exports.createDummyRelationUpdater = exports.createHotRelationUpdater = exports.annotationDriver = undefined; | ||
exports.defaultPlugins = exports.createManagerFactory = exports.BaseProvider = exports.SimpleMap = exports.createDummyRelationUpdater = exports.createHotRelationUpdater = exports.annotationDriver = exports.fastCreateObject = exports.fastCall = undefined; | ||
@@ -34,4 +34,8 @@ var _BaseProvider = require('./core/BaseProvider'); | ||
var _fastCall = require('./utils/fastCall'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
exports.fastCall = _fastCall.fastCall; | ||
exports.fastCreateObject = _fastCall.fastCreateObject; | ||
exports.annotationDriver = _annotationDriver2.default; | ||
@@ -38,0 +42,0 @@ exports.createHotRelationUpdater = _createHotRelationUpdater2.default; |
'use strict'; | ||
exports.__esModule = true; | ||
var _BaseProvider2 = require('../../core/BaseProvider'); | ||
var _BaseProvider3 = _interopRequireDefault(_BaseProvider2); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
/*:: import type {AliasAnnotation} from 'reactive-di/i/pluginsInterfaces'*/ | ||
/*:: import type { | ||
Tag, | ||
Container, | ||
Provider, | ||
Resolver | ||
Provider | ||
} from 'reactive-di/i/coreInterfaces'*/ | ||
var AliasProvider = function (_BaseProvider) { | ||
_inherits(AliasProvider, _BaseProvider); | ||
function AliasProvider() { | ||
_classCallCheck(this, AliasProvider); | ||
return _possibleConstructorReturn(this, _BaseProvider.apply(this, arguments)); | ||
} | ||
AliasProvider.prototype.createResolver = function createResolver(container /*: Container*/) { | ||
return container.getResolver(this.annotation.alias); | ||
}; | ||
return AliasProvider; | ||
}(_BaseProvider3.default); | ||
exports.default = { | ||
kind: 'alias', | ||
create: function create(annotation /*: AliasAnnotation*/) { | ||
return new AliasProvider(annotation); | ||
create: function create(annotation /*: AliasAnnotation*/, container /*: Container*/) { | ||
return container.getProvider(annotation.alias); | ||
} | ||
}; | ||
//# sourceMappingURL=AliasPlugin.js.map |
@@ -5,8 +5,2 @@ 'use strict'; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; }; | ||
var _createProxy = require('../../utils/createProxy'); | ||
var _fastCall = require('../../utils/fastCall'); | ||
var _BaseProvider2 = require('../../core/BaseProvider'); | ||
@@ -18,2 +12,4 @@ | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
@@ -23,73 +19,35 @@ | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
/*:: import type {ClassAnnotation} from 'reactive-di/i/pluginsInterfaces'*/ | ||
/*:: import type { | ||
ArgumentHelper, | ||
Tag, | ||
Dependency, | ||
Resolver, | ||
Provider, | ||
Container, | ||
ResolveDepsResult | ||
Container | ||
} from 'reactive-di/i/coreInterfaces'*/ | ||
var ClassResolver = function () { | ||
function ClassResolver(provider /*: Provider*/, resolver /*: () => ResolveDepsResult*/, target /*: Dependency*/, displayName /*: string*/) { | ||
_classCallCheck(this, ClassResolver); | ||
var ClassProvider = function (_BaseProvider) { | ||
_inherits(ClassProvider, _BaseProvider); | ||
this.provider = provider; | ||
this._isCached = false; | ||
this._value = null; | ||
this._target = target; | ||
this._resolver = resolver; | ||
this.displayName = displayName; | ||
function ClassProvider() { | ||
_classCallCheck(this, ClassProvider); | ||
return _possibleConstructorReturn(this, _BaseProvider.apply(this, arguments)); | ||
} | ||
ClassResolver.prototype.reset = function reset() { | ||
this._isCached = false; | ||
ClassProvider.prototype.init = function init(container /*: Container*/) { | ||
this._helper = container.createArgumentHelper(this.annotation); | ||
this._target = this.annotation.target; | ||
}; | ||
ClassResolver.prototype.dispose = function dispose() {}; | ||
ClassResolver.prototype.resolve = function resolve() { | ||
if (this._isCached) { | ||
ClassProvider.prototype.get = function get() { | ||
if (this.isCached) { | ||
return this._value; | ||
} | ||
var _resolver = this._resolver(); | ||
this._value = this._helper.createObject(); | ||
this.isCached = true; | ||
var deps = _resolver.deps; | ||
var middlewares = _resolver.middlewares; | ||
var object /*: any*/ = void 0; | ||
object = (0, _fastCall.fastCreateObject)(this._target, deps); | ||
if (middlewares) { | ||
if ((typeof object === 'undefined' ? 'undefined' : _typeof(object)) !== 'object') { | ||
throw new Error('No object returns from ' + this.displayName); | ||
} | ||
object = (0, _createProxy.createObjectProxy)(object, middlewares); | ||
} | ||
this._value = object; | ||
this._isCached = true; | ||
return this._value; | ||
}; | ||
return ClassResolver; | ||
}(); | ||
var ClassProvider = function (_BaseProvider) { | ||
_inherits(ClassProvider, _BaseProvider); | ||
function ClassProvider() { | ||
_classCallCheck(this, ClassProvider); | ||
return _possibleConstructorReturn(this, _BaseProvider.apply(this, arguments)); | ||
} | ||
ClassProvider.prototype.createResolver = function createResolver(container /*: Container*/) { | ||
var annotation = this.annotation; | ||
return new ClassResolver(this, container.createDepResolver(annotation, this.tags), annotation.dep || (annotation.target /*: any*/), this.displayName); | ||
}; | ||
return ClassProvider; | ||
@@ -96,0 +54,0 @@ }(_BaseProvider3.default); |
@@ -5,4 +5,2 @@ 'use strict'; | ||
var _fastCall = require('../../utils/fastCall'); | ||
var _BaseProvider2 = require('../../core/BaseProvider'); | ||
@@ -14,2 +12,4 @@ | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
@@ -19,25 +19,22 @@ | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
/*:: import type {ComposeAnnotation} from 'reactive-di/i/pluginsInterfaces'*/ | ||
/*:: import type { | ||
Tag, | ||
Dependency, | ||
Container, | ||
Resolver, | ||
Provider, | ||
ResolveDepsResult | ||
ArgumentHelper, | ||
Provider | ||
} from 'reactive-di/i/coreInterfaces'*/ | ||
var ComposeResolver = function () { | ||
function ComposeResolver(provider /*: Provider*/, resolver /*: () => ResolveDepsResult*/, target /*: Dependency*/, displayName /*: string*/) { | ||
_classCallCheck(this, ComposeResolver); | ||
var ComposeProvider = function (_BaseProvider) { | ||
_inherits(ComposeProvider, _BaseProvider); | ||
this.provider = provider; | ||
this._value = function getValue() /*: any*/ { | ||
var _resolver = resolver(); | ||
function ComposeProvider() { | ||
_classCallCheck(this, ComposeProvider); | ||
var deps = _resolver.deps; | ||
var middlewares = _resolver.middlewares; | ||
return _possibleConstructorReturn(this, _BaseProvider.apply(this, arguments)); | ||
} | ||
ComposeProvider.prototype.init = function init(container /*: Container*/) { | ||
var helper /*: ArgumentHelper*/ = container.createArgumentHelper(this.annotation); | ||
this._value = function getValue() /*: any*/ { | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
@@ -47,41 +44,14 @@ args[_key] = arguments[_key]; | ||
var props = deps.concat(args); | ||
var result = (0, _fastCall.fastCall)(target, props); | ||
if (middlewares) { | ||
var middlewareProps = [result].concat(props); | ||
for (var i = 0, l = middlewares.length; i < l; i++) { | ||
(0, _fastCall.fastCall)(middlewares[i], middlewareProps); | ||
} | ||
} | ||
return result; | ||
return helper.invokeComposed(args); | ||
}; | ||
this.displayName = displayName; | ||
} | ||
}; | ||
ComposeResolver.prototype.dispose = function dispose() {}; | ||
ComposeProvider.prototype.addDependency = function addDependency(dependency /*: Provider*/) { | ||
this.dependencies.push(dependency); | ||
}; | ||
ComposeResolver.prototype.reset = function reset() {}; | ||
ComposeResolver.prototype.resolve = function resolve() { | ||
ComposeProvider.prototype.get = function get() { | ||
return this._value; | ||
}; | ||
return ComposeResolver; | ||
}(); | ||
var ComposeProvider = function (_BaseProvider) { | ||
_inherits(ComposeProvider, _BaseProvider); | ||
function ComposeProvider() { | ||
_classCallCheck(this, ComposeProvider); | ||
return _possibleConstructorReturn(this, _BaseProvider.apply(this, arguments)); | ||
} | ||
ComposeProvider.prototype.createResolver = function createResolver(container /*: Container*/) { | ||
var annotation = this.annotation; | ||
return new ComposeResolver(this, container.createDepResolver(this.annotation, this.tags), annotation.dep || (annotation.target /*: any*/), this.displayName); | ||
}; | ||
return ComposeProvider; | ||
@@ -88,0 +58,0 @@ }(_BaseProvider3.default); |
@@ -5,4 +5,2 @@ 'use strict'; | ||
var _fastCall = require('../../utils/fastCall'); | ||
var _BaseProvider2 = require('../../core/BaseProvider'); | ||
@@ -12,6 +10,6 @@ | ||
var _createProxy = require('../../utils/createProxy'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
@@ -21,10 +19,7 @@ | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
/*:: import type {FactoryAnnotation} from 'reactive-di/i/pluginsInterfaces'*/ | ||
/*:: import type { | ||
Tag, | ||
ArgumentHelper, | ||
Dependency, | ||
Resolver, | ||
ResolveDepsResult, | ||
Container, | ||
@@ -34,47 +29,2 @@ Provider | ||
var FactoryResolver = function () { | ||
function FactoryResolver(provider /*: Provider*/, resolver /*: () => ResolveDepsResult*/, target /*: Dependency*/, displayName /*: string*/) { | ||
_classCallCheck(this, FactoryResolver); | ||
this.provider = provider; | ||
this._isCached = false; | ||
this._value = null; | ||
this._target = target; | ||
this._resolver = resolver; | ||
this.displayName = displayName; | ||
} | ||
FactoryResolver.prototype.reset = function reset() { | ||
this._isCached = false; | ||
}; | ||
FactoryResolver.prototype.dispose = function dispose() {}; | ||
FactoryResolver.prototype.resolve = function resolve() { | ||
if (this._isCached) { | ||
return this._value; | ||
} | ||
var _resolver = this._resolver(); | ||
var deps = _resolver.deps; | ||
var middlewares = _resolver.middlewares; | ||
var fn /*: any*/ = void 0; | ||
fn = (0, _fastCall.fastCall)(this._target, deps); | ||
if (middlewares) { | ||
if (typeof fn !== 'function') { | ||
throw new Error('No callable returns from ' + this.displayName); | ||
} | ||
fn = (0, _createProxy.createFunctionProxy)(fn, middlewares); | ||
} | ||
this._value = fn; | ||
this._isCached = true; | ||
return this._value; | ||
}; | ||
return FactoryResolver; | ||
}(); | ||
var FactoryProvider = function (_BaseProvider) { | ||
@@ -89,6 +39,14 @@ _inherits(FactoryProvider, _BaseProvider); | ||
FactoryProvider.prototype.createResolver = function createResolver(container /*: Container*/) { | ||
var annotation = this.annotation; | ||
FactoryProvider.prototype.init = function init(container /*: Container*/) { | ||
this._helper = container.createArgumentHelper(this.annotation); | ||
}; | ||
return new FactoryResolver(this, container.createDepResolver(this.annotation, this.tags), annotation.dep || (annotation.target /*: any*/), this.displayName); | ||
FactoryProvider.prototype.get = function get() { | ||
if (this.isCached) { | ||
return this._value; | ||
} | ||
this._value = this._helper.invokeFunction(); | ||
this.isCached = true; | ||
return this._value; | ||
}; | ||
@@ -95,0 +53,0 @@ |
@@ -11,2 +11,4 @@ 'use strict'; | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
@@ -16,34 +18,7 @@ | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
/*:: import type {ValueAnnotation} from 'reactive-di/i/pluginsInterfaces'*/ | ||
/*:: import type { | ||
Tag, | ||
Resolver, | ||
Provider | ||
} from 'reactive-di/i/coreInterfaces'*/ | ||
var ValueResolver = function () { | ||
function ValueResolver(provider /*: Provider*/, value /*: any*/) { | ||
_classCallCheck(this, ValueResolver); | ||
this.provider = provider; | ||
this._value = value; | ||
} | ||
ValueResolver.prototype.setValue = function setValue(value /*: any*/) { | ||
this._value = value; | ||
}; | ||
ValueResolver.prototype.dispose = function dispose() {}; | ||
ValueResolver.prototype.reset = function reset() {}; | ||
ValueResolver.prototype.resolve = function resolve() { | ||
return this._value; | ||
}; | ||
return ValueResolver; | ||
}(); | ||
var ValueProvider = function (_BaseProvider) { | ||
@@ -58,7 +33,16 @@ _inherits(ValueProvider, _BaseProvider); | ||
ValueProvider.prototype.createResolver = function createResolver(container /*: Container*/) { | ||
ValueProvider.prototype.init = function init(container /*: Container*/) { | ||
// eslint-disable-line | ||
return new ValueResolver(this, this.annotation.value); | ||
this._value = this.annotation.value; | ||
}; | ||
ValueProvider.prototype.get = function get() { | ||
return this._value; | ||
}; | ||
ValueProvider.prototype.set = function set(value /*: any*/) { | ||
this._value = value; | ||
return true; | ||
}; | ||
return ValueProvider; | ||
@@ -65,0 +49,0 @@ }(_BaseProvider3.default); |
@@ -38,5 +38,5 @@ 'use strict'; | ||
for (var key in map) { | ||
// eslint-disable-line | ||
fn(map[key], (key /*: any*/)); | ||
var keys = Object.keys(map); | ||
for (var i = 0, l = keys.length; i < l; i++) { | ||
fn(map[keys[i]], (keys[i] /*: any*/)); | ||
} | ||
@@ -43,0 +43,0 @@ }; |
@@ -38,5 +38,5 @@ 'use strict'; | ||
for (var key in map) { | ||
// eslint-disable-line | ||
fn(map[key]); | ||
var keys = Object.keys(map); | ||
for (var i = 0, l = keys.length; i < l; i++) { | ||
fn(map[keys[i]]); | ||
} | ||
@@ -43,0 +43,0 @@ }; |
@@ -14,2 +14,3 @@ /* @flow */ | ||
kind: any; | ||
displayName?: string; | ||
tags?: Array<Tag>; | ||
@@ -19,7 +20,4 @@ target: DependencyKey; | ||
export type Resolver = { | ||
provider: Provider; | ||
resolve(): any; | ||
reset(): void; | ||
dispose(): void; | ||
export type DepAnnotation = Annotation & { | ||
deps: Array<DepItem>; | ||
} | ||
@@ -33,9 +31,32 @@ | ||
getDependencies(): Array<Provider>; | ||
/** | ||
* Read only dependencies | ||
*/ | ||
dependencies: Array<Provider>; | ||
/** | ||
* Read only dependants | ||
*/ | ||
dependants: Array<Provider>; | ||
/** | ||
* Provider.get read this property if false - recalculates get result. | ||
* Dependency provider can set isCached to false | ||
* | ||
* read/write | ||
*/ | ||
isCached: boolean; | ||
/** | ||
* Used for garbage collector, when disposing container | ||
*/ | ||
isDisposed: boolean; | ||
init(container: Container): void; | ||
dispose(): void; | ||
get(): any; | ||
addDependency(dependency: Provider): void; | ||
getDependants(): Array<Provider>; | ||
addDependant(dependant: Provider): void; | ||
createResolver(container: Container): Resolver; | ||
} | ||
@@ -45,36 +66,19 @@ | ||
kind: any; | ||
create(annotation: Ann): Provider; | ||
create(annotation: Ann, container: Container): Provider; | ||
} | ||
export type ResolveDepsResult<A> = { | ||
deps: Array<any>, | ||
middlewares: ?Array<A> | ||
export type ArgumentHelper = { | ||
invokeComposed(...args: Array<any>): any; | ||
invokeFunction(): any; | ||
createObject(): Object; | ||
} | ||
export type CreateResolverOptions = { | ||
deps: Array<DepItem>; | ||
target: DependencyKey; | ||
} | ||
export type Container = { | ||
createArgumentHelper(annotation: DepAnnotation): ArgumentHelper; | ||
get(annotatedDep: DependencyKey): any; | ||
getResolver(annotatedDep: DependencyKey): Resolver; | ||
getProvider(annotatedDep: DependencyKey): Provider; | ||
delete(annotatedDep: DependencyKey): void; | ||
dispose(): void; | ||
createDepResolver(rec: CreateResolverOptions, tags: Array<Tag>): () => ResolveDepsResult; | ||
} | ||
export type ContainerHelper = { | ||
createProvider(annotatedDep: DependencyKey, isParent: boolean): ?Provider; | ||
removeContainer(container: Container): void; | ||
} | ||
export type ContainerProps = { | ||
helper: ContainerHelper, | ||
updater: RelationUpdater, | ||
middlewares: Map<DependencyKey|Tag, Array<DependencyKey>>, | ||
parent: ?Container | ||
} | ||
export type CreateContainer = (props: ContainerProps) => Container; | ||
export type ContainerManager = { | ||
@@ -91,6 +95,6 @@ setMiddlewares( | ||
export type RelationUpdater = { | ||
dependants: Array<Set<Provider>>; | ||
begin(provider: Provider): void; | ||
end(provider: Provider): void; | ||
inheritRelations(provider: Provider): void; | ||
length: number; | ||
begin(dependant: Provider): void; | ||
end(dependant: Provider): void; | ||
addCached(dependency: Provider): void; | ||
} |
/* @flow */ | ||
import type { | ||
DepAnnotation, | ||
Annotation, | ||
Provider, | ||
Tag, | ||
DepItem, | ||
DependencyKey, | ||
Dependency | ||
DependencyKey | ||
} from 'reactive-di/i/coreInterfaces' | ||
export type ValueAnnotation = { | ||
kind: 'value'; | ||
target: DependencyKey; | ||
tags?: Array<Tag>; | ||
value: any; | ||
} | ||
export type AliasAnnotation = { | ||
export type AliasAnnotation = Annotation & { | ||
kind: 'alias'; | ||
target: DependencyKey; | ||
tags?: Array<Tag>; | ||
alias: DependencyKey; | ||
} | ||
export type AggregateAnnotation = { | ||
kind: 'aggregate'; | ||
target: DependencyKey; | ||
tags: Array<Tag>; | ||
} | ||
export type ComposeAnnotation = { | ||
export type ComposeAnnotation = DepAnnotation & { | ||
kind: 'compose'; | ||
target: DependencyKey; | ||
dep?: Dependency; | ||
tags?: Array<Tag>; | ||
deps: Array<DepItem>; | ||
} | ||
export type FactoryAnnotation = { | ||
export type FactoryAnnotation = DepAnnotation & { | ||
kind: 'factory'; | ||
target: DependencyKey; | ||
dep?: Dependency; | ||
tags?: Array<Tag>; | ||
deps: Array<DepItem>; | ||
} | ||
export type ClassAnnotation = { | ||
export type ClassAnnotation = DepAnnotation & { | ||
kind: 'klass'; | ||
target: DependencyKey; | ||
dep?: Dependency; | ||
tags?: Array<Tag>; | ||
deps: Array<DepItem>; | ||
} | ||
export type ValueAnnotation = Annotation & { | ||
kind: 'value'; | ||
value: any; | ||
} | ||
export type ValueProvider<Ann: Annotation> = Provider<Ann> | Provider<Ann> & { | ||
kind: 'value'; | ||
set(value: any): boolean; | ||
} |
@@ -53,6 +53,4 @@ /* @flow */ | ||
init(container: Container): void; | ||
createResolver(): Resolver; | ||
createResolver(container: Container): Resolver; | ||
} | ||
} |
{ | ||
"name": "reactive-di", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"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
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
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
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
209624
90
2217