reactive-di
Advanced tools
Comparing version 1.0.0 to 1.0.1
'use strict'; | ||
var _powerAssertRecorder = function () { function PowerAssertRecorder() { this.captured = []; } PowerAssertRecorder.prototype._capt = function _capt(value, espath) { this.captured.push({ value: value, espath: espath }); return value; }; PowerAssertRecorder.prototype._expr = function _expr(value, source) { return { powerAssertContext: { value: value, events: this.captured }, source: source }; }; return PowerAssertRecorder; }(); | ||
/* eslint-env mocha */ | ||
@@ -20,2 +19,4 @@ var _sinon = require('sinon'); | ||
/* eslint-env mocha */ | ||
/*:: import type { | ||
@@ -42,7 +43,7 @@ Container | ||
filepath: 'src/core/__tests__/cacheTest.js', | ||
line: 31 | ||
line: 30 | ||
})); | ||
}); | ||
it('should cache providers', function () { | ||
it('should cache resolvers', function () { | ||
var _rec2 = new _powerAssertRecorder(); | ||
@@ -54,20 +55,6 @@ | ||
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').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', | ||
line: 39 | ||
})); | ||
}); | ||
it('should cache resolvers', function () { | ||
var _rec3 = new _powerAssertRecorder(); | ||
var A = function A() { | ||
return 1; | ||
}; | ||
var newDi /*: Container*/ = (0, _createContainer.createContainer)([(0, _configurations.factory)(A)]); | ||
(0, _powerAssert2.default)(_rec3._expr(_rec3._capt(_rec3._capt(_rec3._capt(newDi, 'arguments/0/left/callee/object').getResolver(_rec3._capt(A, 'arguments/0/left/arguments/0')), 'arguments/0/left') === _rec3._capt(_rec3._capt(newDi, 'arguments/0/right/callee/object').getResolver(_rec3._capt(A, 'arguments/0/right/arguments/0')), 'arguments/0/right'), 'arguments/0'), { | ||
(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))', | ||
filepath: 'src/core/__tests__/cacheTest.js', | ||
line: 47 | ||
line: 38 | ||
})); | ||
@@ -74,0 +61,0 @@ }); |
'use strict'; | ||
exports.__esModule = true; | ||
exports.getProvider = getProvider; | ||
exports.createContainer = createContainer; | ||
@@ -13,10 +14,17 @@ | ||
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*/ { | ||
var isHot /*: ?boolean*/ = arguments.length <= 2 || arguments[2] === undefined ? false : arguments[2]; | ||
var createContainerManager /*: CreateContainerManager*/ = (0, _index.createConfigResolver)(_index.defaultPlugins, isHot ? _index.createHotRelationUpdater : _index.createDummyRelationUpdater); | ||
var cm /*: ContainerManager*/ = createContainerManager(config).setMiddlewares(raw); | ||
var createContainterManager /*: CreateContainerManager*/ = (0, _index.createManagerFactory)(_index.defaultPlugins, isHot ? _index.createHotRelationUpdater : _index.createDummyRelationUpdater); | ||
var cm /*: ContainerManager*/ = createContainterManager(config).setMiddlewares(raw); | ||
@@ -23,0 +31,0 @@ return cm.createContainer(); |
@@ -42,14 +42,14 @@ 'use strict'; | ||
di.getProvider(C); | ||
di.getResolver(C); | ||
di.getResolver(B); | ||
var result = (0, _createContainer.getProvider)(di, B).getDependants().map(depName); | ||
var result = di.getProvider(B).getDependants().map(depName); | ||
_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: 38 | ||
line: 39 | ||
}), _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: 38 | ||
line: 39 | ||
})); | ||
@@ -73,3 +73,4 @@ }); | ||
var result = di.getProvider(B).getDependants().map(depName); | ||
di.getResolver(B); | ||
var result = (0, _createContainer.getProvider)(di, B).getDependants().map(depName); | ||
@@ -79,7 +80,7 @@ _powerAssert2.default.deepEqual(_rec3._expr(_rec3._capt(result, 'arguments/0'), { | ||
filepath: 'src/core/__tests__/updaterTest.js', | ||
line: 57 | ||
line: 59 | ||
}), _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: 57 | ||
line: 59 | ||
})); | ||
@@ -102,13 +103,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).getDependants().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: 76 | ||
line: 78 | ||
}), _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: 76 | ||
line: 78 | ||
})); | ||
@@ -133,16 +134,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).getDependencies(); | ||
_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: 95 | ||
line: 97 | ||
}), _rec8._expr(_rec8._capt(['factory@A'], 'arguments/1'), { | ||
content: 'assert.deepEqual(dependencies.map(depName), [\'factory@A\'])', | ||
filepath: 'src/core/__tests__/updaterTest.js', | ||
line: 95 | ||
line: 97 | ||
})); | ||
di.getProvider(B).getDependants().map(depName); | ||
di.getResolver(B); | ||
@@ -152,7 +153,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: 101 | ||
line: 103 | ||
}), _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: 101 | ||
line: 103 | ||
})); | ||
@@ -159,0 +160,0 @@ }); |
@@ -34,5 +34,4 @@ 'use strict'; | ||
BaseProvider.prototype.init = function init(Container /*: Container*/) {}; // eslint-disable-line | ||
BaseProvider.prototype.createResolver = function createResolver() { | ||
BaseProvider.prototype.createResolver = function createResolver(container /*: Container*/) { | ||
// eslint-disable-line | ||
throw new Error('Implement resolver'); | ||
@@ -60,3 +59,2 @@ }; | ||
BaseProvider.prototype.addDependant = function addDependant(dependant /*: Provider*/) { | ||
// console.log('add', this.displayName dependant.displayName) | ||
this._dependants.push(dependant); | ||
@@ -63,0 +61,0 @@ }; |
@@ -31,60 +31,66 @@ 'use strict'; | ||
/*:: import type { | ||
ContainerHelper, | ||
Container, | ||
RelationUpdater, | ||
Provider, | ||
Resolver, | ||
ResolveDepsResult, | ||
CreateResolverOptions, | ||
ProviderManager | ||
CreateResolverOptions | ||
} from 'reactive-di/i/coreInterfaces'*/ | ||
var DiContainer = function () { | ||
function DiContainer(providerManager /*: ProviderManager*/, middlewares /*: Map<DependencyKey|Tag, Array<DependencyKey>>*/) { | ||
var parent /*: ?Container*/ = arguments.length <= 2 || arguments[2] === undefined ? null : arguments[2]; | ||
_classCallCheck(this, DiContainer); | ||
function disposeResolver(resolver /*: Resolver*/) /*: void*/ { | ||
resolver.dispose(); | ||
} | ||
this._cache = new _SimpleMap2.default(); | ||
this._providerManager = providerManager; | ||
this._parent = parent || null; | ||
var DefaultContainer = function () { | ||
function DefaultContainer(containerHelper /*: ContainerHelper*/) { | ||
var parent /*: ?Container*/ = arguments.length <= 1 || arguments[1] === undefined ? null : arguments[1]; | ||
var helper = new _ResolveHelper2.default(middlewares, this); | ||
_classCallCheck(this, DefaultContainer); | ||
this.createDepResolver = (0, _createDepResolverCreator2.default)(helper); | ||
this._updater = containerHelper.updater; | ||
this._dependants = this._updater.dependants; | ||
providerManager.addCacheHandler(this._cache); | ||
this._helper = containerHelper; | ||
this.parent = parent || null; | ||
this._privateCache = new _SimpleMap2.default(); | ||
this._resolverCache = new _SimpleMap2.default(); | ||
this.createDepResolver = (0, _createDepResolverCreator2.default)(new _ResolveHelper2.default(containerHelper.middlewares, this)); | ||
} | ||
DiContainer.prototype.finalize = function finalize() { | ||
this._providerManager.removeCacheHandler(this._cache); | ||
DefaultContainer.prototype.delete = function _delete(annotatedDep /*: DependencyKey*/) { | ||
this._resolverCache.delete(annotatedDep); | ||
var resolver /*: ?Resolver*/ = this._privateCache.get(annotatedDep); | ||
if (resolver) { | ||
resolver.dispose(); | ||
} | ||
this._privateCache.delete(annotatedDep); | ||
}; | ||
DiContainer.prototype.get = function get(annotatedDep /*: DependencyKey*/) { | ||
return this.getResolver(annotatedDep).resolve(); | ||
DefaultContainer.prototype.dispose = function dispose() { | ||
this._privateCache.forEach(disposeResolver); | ||
this._helper.removeContainer(this); | ||
}; | ||
DiContainer.prototype.getProvider = function getProvider(annotatedDep /*: DependencyKey*/) { | ||
var provider /*: ?Provider*/ = this._providerManager.getProvider(annotatedDep, (this /*: Container*/)); | ||
if (!provider) { | ||
if (!this._parent) { | ||
throw new Error('Can\'t find annotation for ' + (0, _getFunctionName2.default)(annotatedDep)); | ||
} | ||
provider = this._parent.getProvider(annotatedDep); | ||
} | ||
return provider; | ||
DefaultContainer.prototype.get = function get(annotatedDep /*: DependencyKey*/) { | ||
return this.getResolver(annotatedDep).resolve(); | ||
}; | ||
DiContainer.prototype.getResolver = function getResolver(annotatedDep /*: DependencyKey*/) { | ||
var resolver /*: ?Resolver*/ = this._cache.get(annotatedDep); | ||
DefaultContainer.prototype.getResolver = function getResolver(annotatedDep /*: DependencyKey*/) { | ||
var resolver /*: ?Resolver*/ = this._resolverCache.get(annotatedDep); | ||
if (!resolver) { | ||
var provider /*: ?Provider*/ = this._providerManager.getProvider(annotatedDep, (this /*: Container*/)); | ||
if (!provider) { | ||
if (!this._parent) { | ||
resolver = this._helper.createResolver(annotatedDep, (this /*: Container*/)); | ||
if (resolver) { | ||
this._privateCache.set(annotatedDep, resolver); | ||
} else { | ||
if (!this.parent) { | ||
throw new Error('Can\'t find annotation for ' + (0, _getFunctionName2.default)(annotatedDep)); | ||
} | ||
resolver = this._parent.getResolver(annotatedDep); | ||
} else { | ||
resolver = provider.createResolver(); | ||
resolver = this.parent.getResolver(annotatedDep); | ||
} | ||
this._cache.set(annotatedDep, resolver); | ||
this._resolverCache.set(annotatedDep, resolver); | ||
} else if (this._dependants.length) { | ||
this._updater.inheritRelations(resolver.provider); | ||
} | ||
@@ -95,8 +101,8 @@ | ||
return DiContainer; | ||
return DefaultContainer; | ||
}(); | ||
function createDefaultContainer(providerManager /*: ProviderManager*/, middlewares /*: Map<DependencyKey|Tag, Array<DependencyKey>>*/, parent /*: ?Container*/) /*: Container*/ { | ||
return new DiContainer(providerManager, middlewares, parent); | ||
function createDefaultContainer(helper /*: ContainerHelper*/, parent /*: ?Container*/) /*: Container*/ { | ||
return new DefaultContainer(helper, parent); | ||
} | ||
//# sourceMappingURL=createDefaultContainer.js.map |
@@ -48,19 +48,19 @@ 'use strict'; | ||
var depNames /*: ?Array<string>*/ = null; | ||
var depNames /*: ?Array<string>*/ = void 0; | ||
var resolvedDeps /*: Array<Resolver>*/ = []; | ||
if (deps.length) { | ||
if (_typeof(deps[0]) === 'object' && deps.length === 1) { | ||
depNames = []; | ||
var argsObject /*: ArgsObject*/ = (deps[0] /*: any*/); | ||
for (var key in argsObject) { | ||
// eslint-disable-line | ||
resolvedDeps.push(container.getResolver(argsObject[key])); | ||
depNames.push(key); | ||
} | ||
} else { | ||
for (var i = 0, l = deps.length; i < l; i++) { | ||
var dep /*: Resolver*/ = container.getResolver(((deps /*: any*/) /*: Array<DependencyKey>*/)[i]); | ||
resolvedDeps.push(dep); | ||
} | ||
var l /*: number*/ = deps.length; | ||
if (l === 1 && _typeof(deps[0]) === 'object') { | ||
depNames = []; | ||
var argsObject /*: ArgsObject*/ = (deps[0] /*: any*/); | ||
for (var key in argsObject) { | ||
// eslint-disable-line | ||
resolvedDeps.push(container.getResolver(argsObject[key])); | ||
depNames.push(key); | ||
} | ||
} else { | ||
depNames = null; | ||
for (var i = 0; i < l; i++) { | ||
var dep /*: Resolver*/ = container.getResolver(((deps /*: any*/) /*: Array<DependencyKey>*/)[i]); | ||
resolvedDeps.push(dep); | ||
} | ||
} | ||
@@ -67,0 +67,0 @@ |
@@ -16,2 +16,4 @@ 'use strict'; | ||
_classCallCheck(this, DummyRelationUpdater); | ||
this.dependants = []; | ||
} | ||
@@ -18,0 +20,0 @@ |
@@ -23,7 +23,7 @@ 'use strict'; | ||
this._dependants = []; | ||
this.dependants = []; | ||
} | ||
HotRelationUpdater.prototype.begin = function begin(dependency /*: Provider*/) { | ||
var dependants = this._dependants; | ||
var dependants = this.dependants; | ||
@@ -37,3 +37,3 @@ for (var i = 0, l = dependants.length; i < l; i++) { | ||
HotRelationUpdater.prototype.end = function end(dependency /*: Provider*/) { | ||
var dependantSet = this._dependants.pop(); | ||
var dependantSet = this.dependants.pop(); | ||
function iterateMap(dependant /*: Provider*/) /*: void*/ { | ||
@@ -46,7 +46,7 @@ dependant.addDependency(dependency); | ||
HotRelationUpdater.prototype.inheritRelations = function inheritRelations(dependency /*: Provider*/) { | ||
var l /*: number*/ = this._dependants.length; | ||
var l /*: number*/ = this.dependants.length; | ||
if (!l) { | ||
return; | ||
} | ||
var dependants /*: Array<Set<Provider>>*/ = this._dependants; | ||
var dependants /*: Array<Set<Provider>>*/ = this.dependants; | ||
var inheritDependants /*: Array<Provider>*/ = dependency.getDependants(); | ||
@@ -53,0 +53,0 @@ var k /*: number*/ = inheritDependants.length; |
'use strict'; | ||
exports.__esModule = true; | ||
exports.defaultPlugins = exports.createConfigResolver = exports.createDefaultContainer = 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 = undefined; | ||
@@ -10,5 +10,5 @@ var _BaseProvider = require('./core/BaseProvider'); | ||
var _createConfigResolver = require('./core/createConfigResolver'); | ||
var _createManagerFactory = require('./core/createManagerFactory'); | ||
var _createConfigResolver2 = _interopRequireDefault(_createConfigResolver); | ||
var _createManagerFactory2 = _interopRequireDefault(_createManagerFactory); | ||
@@ -35,6 +35,2 @@ var _defaultPlugins = require('./plugins/defaultPlugins'); | ||
var _createDefaultContainer = require('./core/createDefaultContainer'); | ||
var _createDefaultContainer2 = _interopRequireDefault(_createDefaultContainer); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -47,5 +43,4 @@ | ||
exports.BaseProvider = _BaseProvider2.default; | ||
exports.createDefaultContainer = _createDefaultContainer2.default; | ||
exports.createConfigResolver = _createConfigResolver2.default; | ||
exports.createManagerFactory = _createManagerFactory2.default; | ||
exports.defaultPlugins = _defaultPlugins2.default; | ||
//# sourceMappingURL=index.js.map |
@@ -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,4 +18,2 @@ | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
/*:: import type {AliasAnnotation} from 'reactive-di/i/pluginsInterfaces'*/ | ||
@@ -27,20 +27,2 @@ /*:: import type { | ||
var AliasResolver = function () { | ||
function AliasResolver(resolver /*: Resolver*/) { | ||
_classCallCheck(this, AliasResolver); | ||
this._resolver = resolver; | ||
} | ||
AliasResolver.prototype.reset = function reset() { | ||
this._resolver.reset(); | ||
}; | ||
AliasResolver.prototype.resolve = function resolve() { | ||
return this._resolver.resolve(); | ||
}; | ||
return AliasResolver; | ||
}(); | ||
var AliasProvider = function (_BaseProvider) { | ||
@@ -55,10 +37,6 @@ _inherits(AliasProvider, _BaseProvider); | ||
AliasProvider.prototype.init = function init(container /*: Container*/) { | ||
this._resolver = container.getResolver(this.annotation.alias); | ||
AliasProvider.prototype.createResolver = function createResolver(container /*: Container*/) { | ||
return container.getResolver(this.annotation.alias); | ||
}; | ||
AliasProvider.prototype.createResolver = function createResolver() { | ||
return new AliasResolver(this._resolver); | ||
}; | ||
return AliasProvider; | ||
@@ -65,0 +43,0 @@ }(_BaseProvider3.default); |
@@ -34,5 +34,6 @@ 'use strict'; | ||
var ClassResolver = function () { | ||
function ClassResolver(resolver /*: () => ResolveDepsResult*/, target /*: Dependency*/, displayName /*: string*/) { | ||
function ClassResolver(provider /*: Provider*/, resolver /*: () => ResolveDepsResult*/, target /*: Dependency*/, displayName /*: string*/) { | ||
_classCallCheck(this, ClassResolver); | ||
this.provider = provider; | ||
this._isCached = false; | ||
@@ -49,2 +50,4 @@ this._value = null; | ||
ClassResolver.prototype.dispose = function dispose() {}; | ||
ClassResolver.prototype.resolve = function resolve() { | ||
@@ -86,10 +89,5 @@ if (this._isCached) { | ||
ClassProvider.prototype.init = function init(acc /*: Container*/) { | ||
this._resolver = acc.createDepResolver(this.annotation, this.tags); | ||
}; | ||
ClassProvider.prototype.createResolver = function createResolver() { | ||
ClassProvider.prototype.createResolver = function createResolver(container /*: Container*/) { | ||
var annotation = this.annotation; | ||
return new ClassResolver(this._resolver, annotation.dep || (annotation.target /*: any*/), this.displayName); | ||
return new ClassResolver(this, container.createDepResolver(annotation, this.tags), annotation.dep || (annotation.target /*: any*/), this.displayName); | ||
}; | ||
@@ -96,0 +94,0 @@ |
@@ -30,5 +30,6 @@ 'use strict'; | ||
var ComposeResolver = function () { | ||
function ComposeResolver(resolver /*: () => ResolveDepsResult*/, target /*: Dependency*/, displayName /*: string*/) { | ||
function ComposeResolver(provider /*: Provider*/, resolver /*: () => ResolveDepsResult*/, target /*: Dependency*/, displayName /*: string*/) { | ||
_classCallCheck(this, ComposeResolver); | ||
this.provider = provider; | ||
this._value = function getValue() /*: any*/ { | ||
@@ -57,2 +58,4 @@ var _resolver = resolver(); | ||
ComposeResolver.prototype.dispose = function dispose() {}; | ||
ComposeResolver.prototype.reset = function reset() {}; | ||
@@ -76,10 +79,6 @@ | ||
ComposeProvider.prototype.init = function init(acc /*: Container*/) { | ||
this._resolver = acc.createDepResolver(this.annotation, this.tags); | ||
}; | ||
ComposeProvider.prototype.createResolver = function createResolver() { | ||
ComposeProvider.prototype.createResolver = function createResolver(container /*: Container*/) { | ||
var annotation = this.annotation; | ||
return new ComposeResolver(this._resolver, annotation.dep || (annotation.target /*: any*/), this.displayName); | ||
return new ComposeResolver(this, container.createDepResolver(this.annotation, this.tags), annotation.dep || (annotation.target /*: any*/), this.displayName); | ||
}; | ||
@@ -86,0 +85,0 @@ |
@@ -32,5 +32,6 @@ 'use strict'; | ||
var FactoryResolver = function () { | ||
function FactoryResolver(resolver /*: () => ResolveDepsResult*/, target /*: Dependency*/, displayName /*: string*/) { | ||
function FactoryResolver(provider /*: Provider*/, resolver /*: () => ResolveDepsResult*/, target /*: Dependency*/, displayName /*: string*/) { | ||
_classCallCheck(this, FactoryResolver); | ||
this.provider = provider; | ||
this._isCached = false; | ||
@@ -47,2 +48,4 @@ this._value = null; | ||
FactoryResolver.prototype.dispose = function dispose() {}; | ||
FactoryResolver.prototype.resolve = function resolve() { | ||
@@ -84,10 +87,6 @@ if (this._isCached) { | ||
FactoryProvider.prototype.init = function init(acc /*: Container*/) { | ||
this._resolver = acc.createDepResolver(this.annotation, this.tags); | ||
}; | ||
FactoryProvider.prototype.createResolver = function createResolver() { | ||
FactoryProvider.prototype.createResolver = function createResolver(container /*: Container*/) { | ||
var annotation = this.annotation; | ||
return new FactoryResolver(this._resolver, annotation.dep || (annotation.target /*: any*/), this.displayName); | ||
return new FactoryResolver(this, container.createDepResolver(this.annotation, this.tags), annotation.dep || (annotation.target /*: any*/), this.displayName); | ||
}; | ||
@@ -94,0 +93,0 @@ |
@@ -25,5 +25,6 @@ 'use strict'; | ||
var ValueResolver = function () { | ||
function ValueResolver(value /*: any*/) { | ||
function ValueResolver(provider /*: Provider*/, value /*: any*/) { | ||
_classCallCheck(this, ValueResolver); | ||
this.provider = provider; | ||
this._value = value; | ||
@@ -36,2 +37,4 @@ } | ||
ValueResolver.prototype.dispose = function dispose() {}; | ||
ValueResolver.prototype.reset = function reset() {}; | ||
@@ -55,4 +58,5 @@ | ||
ValueProvider.prototype.createResolver = function createResolver() { | ||
return new ValueResolver(this.annotation.value); | ||
ValueProvider.prototype.createResolver = function createResolver(container /*: Container*/) { | ||
// eslint-disable-line | ||
return new ValueResolver(this, this.annotation.value); | ||
}; | ||
@@ -59,0 +63,0 @@ |
@@ -19,4 +19,6 @@ /* @flow */ | ||
export type Resolver = { | ||
provider: Provider; | ||
resolve(): any; | ||
reset(): void; | ||
dispose(): void; | ||
} | ||
@@ -36,5 +38,3 @@ | ||
init(container: Container): void; | ||
createResolver(): Resolver; | ||
createResolver(container: Container): Resolver; | ||
} | ||
@@ -58,17 +58,15 @@ | ||
export type Container = { | ||
parent: ?Container; | ||
get(annotatedDep: DependencyKey): any; | ||
finalize(): void; | ||
getProvider(annotatedDep: DependencyKey): Provider; | ||
getResolver(annotatedDep: DependencyKey): Resolver; | ||
delete(annotatedDep: DependencyKey): void; | ||
dispose(): void; | ||
createDepResolver(rec: CreateResolverOptions, tags: Array<Tag>): () => ResolveDepsResult; | ||
} | ||
export type CreateContainerManager = (config?: Array<Annotation>) => ContainerManager; | ||
export type CreateContainer = ( | ||
helper: ContainerHelper, | ||
parent: ?Container | ||
) => Container; | ||
export type CreateConfigResolver = ( | ||
pluginsConfig?: Array<Plugin>, | ||
createUpdater?: () => RelationUpdater, | ||
createContainer?: CreateContainer | ||
) => CreateContainerManager; | ||
export type ContainerManager = { | ||
@@ -79,6 +77,9 @@ setMiddlewares( | ||
createContainer(parent?: Container): Container; | ||
replace(annotatedDep: DependencyKey, annotation?: Annotation): void; | ||
replace(oldDep: DependencyKey, newDep?: DependencyKey|Annotation): void; | ||
} | ||
export type CreateContainerManager = (config?: Array<Annotation>) => ContainerManager; | ||
export type RelationUpdater = { | ||
dependants: Array<Set<Provider>>; | ||
begin(provider: Provider): void; | ||
@@ -89,12 +90,7 @@ end(provider: Provider): void; | ||
export type ProviderManager = { | ||
addCacheHandler(cache: Map<DependencyKey, Resolver>): void; | ||
removeCacheHandler(cache: Map<DependencyKey, Resolver>): void; | ||
getProvider(annotatedDep: DependencyKey, Container: Container): ?Provider; | ||
export type ContainerHelper = { | ||
updater: RelationUpdater; | ||
middlewares: Map<DependencyKey|Tag, Array<DependencyKey>>; | ||
removeContainer(container: Container): void; | ||
createResolver(annotatedDep: DependencyKey, container: Container): ?Resolver; | ||
} | ||
export type CreateContainer = ( | ||
providerManager: ProviderManager, | ||
middlewares: Map<DependencyKey|Tag, Array<DependencyKey>>, | ||
parent: ?Container | ||
) => Container; |
{ | ||
"name": "reactive-di", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"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
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
222615
0
2337