reactive-di
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -31,2 +31,3 @@ 'use strict'; | ||
/*:: import type { | ||
ContainerProps, | ||
ContainerHelper, | ||
@@ -47,16 +48,14 @@ Container, | ||
var DefaultContainer = function () { | ||
function DefaultContainer(containerHelper /*: ContainerHelper*/) { | ||
var parent /*: ?Container*/ = arguments.length <= 1 || arguments[1] === undefined ? null : arguments[1]; | ||
function DefaultContainer(props /*: ContainerProps*/) { | ||
_classCallCheck(this, DefaultContainer); | ||
this._updater = containerHelper.updater; | ||
this._updater = props.updater; | ||
this._dependants = this._updater.dependants; | ||
this._helper = containerHelper; | ||
this.parent = parent || null; | ||
this._helper = props.helper; | ||
this._parent = props.parent || null; | ||
this._privateCache = new _SimpleMap2.default(); | ||
this._resolverCache = new _SimpleMap2.default(); | ||
this.createDepResolver = (0, _createDepResolverCreator2.default)(new _ResolveHelper2.default(containerHelper.middlewares, this)); | ||
this.createDepResolver = (0, _createDepResolverCreator2.default)(new _ResolveHelper2.default(props.middlewares, this)); | ||
} | ||
@@ -85,10 +84,13 @@ | ||
if (!resolver) { | ||
resolver = this._helper.createResolver(annotatedDep, (this /*: Container*/)); | ||
if (resolver) { | ||
var provider /*: ?Provider*/ = this._helper.createProvider(annotatedDep, !!this._parent); | ||
if (provider) { | ||
this._updater.begin(provider); | ||
resolver = provider.createResolver((this /*: Container*/)); | ||
this._updater.end(provider); | ||
this._privateCache.set(annotatedDep, resolver); | ||
} else { | ||
if (!this.parent) { | ||
if (!this._parent) { | ||
throw new Error('Can\'t find annotation for ' + (0, _getFunctionName2.default)(annotatedDep)); | ||
} | ||
resolver = this.parent.getResolver(annotatedDep); | ||
resolver = this._parent.getResolver(annotatedDep); | ||
} | ||
@@ -106,5 +108,5 @@ this._resolverCache.set(annotatedDep, resolver); | ||
function createDefaultContainer(helper /*: ContainerHelper*/, parent /*: ?Container*/) /*: Container*/ { | ||
return new DefaultContainer(helper, parent); | ||
function createDefaultContainer(props /*: ContainerProps*/) /*: Container*/ { | ||
return new DefaultContainer(props); | ||
} | ||
//# sourceMappingURL=createDefaultContainer.js.map |
@@ -55,3 +55,2 @@ 'use strict'; | ||
/*:: import type { | ||
Resolver, | ||
Provider, | ||
@@ -61,24 +60,38 @@ Plugin, | ||
CreateContainer, | ||
ContainerProps, | ||
ContainerHelper, | ||
Container, | ||
ContainerManager, | ||
ContainerHelper | ||
ContainerManager | ||
} from 'reactive-di/i/coreInterfaces'*/ | ||
// implements ContainerHelper | ||
// implements ContainerManager, ContainerHelper | ||
var DefaultContainerHelper = function () { | ||
function DefaultContainerHelper(annotations /*: Map<DependencyKey, Annotation>*/, plugins /*: Map<string, Plugin>*/, updater /*: RelationUpdater*/, cache /*: Map<DependencyKey, Provider>*/) { | ||
_classCallCheck(this, DefaultContainerHelper); | ||
var DefaultContainerManager = function () { | ||
function DefaultContainerManager(annotations /*: Map<DependencyKey, Annotation>*/, plugins /*: Map<string, Plugin>*/, updater /*: RelationUpdater*/, createContainer /*: CreateContainer*/) { | ||
_classCallCheck(this, DefaultContainerManager); | ||
this._createContainer = createContainer; | ||
this._annotations = annotations; | ||
this._cache = new _SimpleMap2.default(); | ||
this._plugins = plugins; | ||
this.updater = updater; | ||
this._cache = cache; | ||
this.containers = []; | ||
this.middlewares = new _SimpleMap2.default(); | ||
this._containers = []; | ||
this._middlewares = new _SimpleMap2.default(); | ||
this._updater = updater; | ||
} | ||
DefaultContainerHelper.prototype.removeContainer = function removeContainer(container /*: Container*/) { | ||
this.containers = this.containers.filter(function (target) { | ||
DefaultContainerManager.prototype.setMiddlewares = function setMiddlewares(raw /*: Array<[DependencyKey, Array<Tag|DependencyKey>]>*/) { | ||
this._middlewares = (0, _normalizeMiddlewares2.default)(raw || []); | ||
return this; | ||
}; | ||
/** | ||
* @see ContainerHelper interface | ||
*/ | ||
DefaultContainerManager.prototype.removeContainer = function removeContainer(container /*: Container*/) { | ||
this._containers = this._containers.filter(function (target) { | ||
return target !== container; | ||
@@ -88,7 +101,12 @@ }); | ||
DefaultContainerHelper.prototype.createResolver = function createResolver(annotatedDep /*: DependencyKey*/, container /*: Container*/) { | ||
/** | ||
* @see ContainerHelper interface | ||
*/ | ||
DefaultContainerManager.prototype.createProvider = function createProvider(annotatedDep /*: DependencyKey*/, isParent /*: boolean*/) { | ||
var provider /*: ?Provider*/ = this._cache.get(annotatedDep); | ||
if (provider) { | ||
return provider.createResolver(container); | ||
return provider; | ||
} | ||
@@ -98,3 +116,3 @@ | ||
if (!annotation) { | ||
if (!container.parent) { | ||
if (!isParent) { | ||
annotation = _annotationDriver2.default.getAnnotation((annotatedDep /*: Dependency*/)); | ||
@@ -116,35 +134,17 @@ if (!annotation) { | ||
this._cache.set(annotatedDep, provider); | ||
this.updater.begin(provider); | ||
var resolver /*: Resolver*/ = provider.createResolver(container); | ||
this.updater.end(provider); | ||
return resolver; | ||
return provider; | ||
}; | ||
return DefaultContainerHelper; | ||
}(); | ||
DefaultContainerManager.prototype.createContainer = function createContainer(parent /*: Container*/) { | ||
var props /*: ContainerProps*/ = { | ||
helper: (this /*: ContainerHelper*/), | ||
middlewares: this._middlewares, | ||
updater: this._updater, | ||
parent: parent | ||
}; | ||
// implements ContainerManager | ||
var container /*: Container*/ = this._createContainer(props); | ||
this._containers.push(container); | ||
var DefaultContainerManager = function () { | ||
function DefaultContainerManager(annotations /*: Map<DependencyKey, Annotation>*/, plugins /*: Map<string, Plugin>*/, updater /*: RelationUpdater*/, createContainer /*: CreateContainer*/) { | ||
_classCallCheck(this, DefaultContainerManager); | ||
this._annotations = annotations; | ||
this._cache = new _SimpleMap2.default(); | ||
this._createContainer = createContainer; | ||
this._helper = new DefaultContainerHelper(this._annotations, plugins, updater, this._cache); | ||
} | ||
DefaultContainerManager.prototype.setMiddlewares = function setMiddlewares(raw /*: Array<[DependencyKey, Array<Tag|DependencyKey>]>*/) { | ||
this._helper.middlewares = (0, _normalizeMiddlewares2.default)(raw || []); | ||
return this; | ||
}; | ||
DefaultContainerManager.prototype.createContainer = function createContainer(parent /*: Container*/) { | ||
var container = this._createContainer((this._helper /*: ContainerHelper*/), parent); | ||
this._helper.containers.push(container); | ||
return container; | ||
@@ -157,3 +157,3 @@ }; | ||
if (provider) { | ||
var containers = this._helper.containers; | ||
var containers = this._containers; | ||
var k = containers.length; | ||
@@ -160,0 +160,0 @@ var dependants = provider.getDependants(); |
@@ -45,5 +45,2 @@ 'use strict'; | ||
var l /*: number*/ = this.dependants.length; | ||
if (!l) { | ||
return; | ||
} | ||
var dependants /*: Array<Set<Provider>>*/ = this.dependants; | ||
@@ -55,4 +52,3 @@ var inheritDependants /*: Array<Provider>*/ = dependency.getDependants(); | ||
for (var j = 0; j < k; j++) { | ||
var dependant /*: Provider*/ = inheritDependants[j]; | ||
dependantSet.add(dependant); | ||
dependantSet.add(inheritDependants[j]); | ||
} | ||
@@ -59,0 +55,0 @@ } |
@@ -6,3 +6,3 @@ /* @flow */ | ||
export type Dependency<T> = DepFn<T>|Class<T>; | ||
export type DependencyKey<T> = Dependency<T>|string; | ||
export type DependencyKey<T> = Dependency<T>; | ||
export type ArgsObject = { | ||
@@ -57,3 +57,2 @@ [name: string]: DependencyKey; | ||
export type Container = { | ||
parent: ?Container; | ||
get(annotatedDep: DependencyKey): any; | ||
@@ -66,7 +65,15 @@ getResolver(annotatedDep: DependencyKey): Resolver; | ||
export type CreateContainer = ( | ||
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 | ||
) => Container; | ||
} | ||
export type CreateContainer = (props: ContainerProps) => Container; | ||
export type ContainerManager = { | ||
@@ -88,8 +95,1 @@ setMiddlewares( | ||
} | ||
export type ContainerHelper = { | ||
updater: RelationUpdater; | ||
middlewares: Map<DependencyKey|Tag, Array<DependencyKey>>; | ||
removeContainer(container: Container): void; | ||
createResolver(annotatedDep: DependencyKey, container: Container): ?Resolver; | ||
} |
{ | ||
"name": "reactive-di", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"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
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
221128
2335