reactive-di
Advanced tools
Comparing version 1.0.5 to 1.0.6
@@ -69,3 +69,3 @@ 'use strict'; | ||
var object /*: Object*/ = void 0; | ||
var object /*: O*/ = void 0; | ||
object = (0, _fastCall.fastCreateObject)(this._target, deps); | ||
@@ -89,7 +89,15 @@ if (middlewares) { | ||
for (var i = 0, j = deps.length; i < j; i++) { | ||
argsObject[depNames[i]] = deps[i].get(); | ||
var dep = deps[i]; | ||
if (!dep.isCached) { | ||
dep.update(); | ||
} | ||
argsObject[depNames[i]] = dep.value; | ||
} | ||
} else { | ||
for (var _i = 0, _j = deps.length; _i < _j; _i++) { | ||
argsArray.push(deps[_i].get()); | ||
var _dep = deps[_i]; | ||
if (!_dep.isCached) { | ||
_dep.update(); | ||
} | ||
argsArray[_i] = _dep.value; | ||
} | ||
@@ -102,3 +110,7 @@ } | ||
for (var _i2 = 0, _j2 = middlewares.length; _i2 < _j2; _i2++) { | ||
resolvedMiddlewares.push(middlewares[_i2].get()); | ||
var _dep2 = middlewares[_i2]; | ||
if (!_dep2.isCached) { | ||
_dep2.update(); | ||
} | ||
resolvedMiddlewares[_i2] = _dep2.value; | ||
} | ||
@@ -105,0 +117,0 @@ } |
@@ -22,3 +22,3 @@ 'use strict'; | ||
var BaseProvider = function () { | ||
function BaseProvider /*:: <Ann: Annotation, P: Provider>*/(annotation /*: Ann*/) { | ||
function BaseProvider /*:: <V, Ann: Annotation, P: Provider>*/(annotation /*: Ann*/) { | ||
_classCallCheck(this, BaseProvider); | ||
@@ -42,5 +42,3 @@ | ||
BaseProvider.prototype.get = function get() { | ||
return null; | ||
}; | ||
BaseProvider.prototype.update = function update() {}; | ||
@@ -47,0 +45,0 @@ BaseProvider.prototype.addDependency = function addDependency(dependency /*: P*/) { |
@@ -133,3 +133,8 @@ 'use strict'; | ||
DefaultContainer.prototype.get = function get(annotatedDep /*: DependencyKey*/) { | ||
return this.getProvider(annotatedDep).get(); | ||
var dep = this.getProvider(annotatedDep); | ||
if (!dep.isCached) { | ||
dep.update(); | ||
} | ||
return dep.value; | ||
}; | ||
@@ -136,0 +141,0 @@ |
@@ -20,3 +20,2 @@ 'use strict'; | ||
ArgumentHelper, | ||
Tag, | ||
Provider, | ||
@@ -29,3 +28,3 @@ Container | ||
function ClassProvider() { | ||
function ClassProvider /*:: <V: Object>*/() { | ||
_classCallCheck(this, ClassProvider); | ||
@@ -38,14 +37,7 @@ | ||
this._helper = container.createArgumentHelper(this.annotation); | ||
this._target = this.annotation.target; | ||
}; | ||
ClassProvider.prototype.get = function get() { | ||
if (this.isCached) { | ||
return this._value; | ||
} | ||
this._value = this._helper.createObject(); | ||
ClassProvider.prototype.update = function update() { | ||
this.value = this._helper.createObject(); | ||
this.isCached = true; | ||
return this._value; | ||
}; | ||
@@ -52,0 +44,0 @@ |
@@ -19,3 +19,3 @@ 'use strict'; | ||
/*:: import type { | ||
Tag, | ||
DepFn, | ||
Container, | ||
@@ -29,3 +29,3 @@ ArgumentHelper, | ||
function ComposeProvider() { | ||
function ComposeProvider /*:: <V>*/() { | ||
_classCallCheck(this, ComposeProvider); | ||
@@ -38,3 +38,4 @@ | ||
var helper /*: ArgumentHelper*/ = container.createArgumentHelper(this.annotation); | ||
this._value = function getValue() /*: any*/ { | ||
this.isCached = true; | ||
this.value = function getValue() /*: V*/ { | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
@@ -52,6 +53,2 @@ args[_key] = arguments[_key]; | ||
ComposeProvider.prototype.get = function get() { | ||
return this._value; | ||
}; | ||
return ComposeProvider; | ||
@@ -58,0 +55,0 @@ }(_BaseProvider3.default); |
@@ -19,5 +19,3 @@ 'use strict'; | ||
/*:: import type { | ||
Tag, | ||
ArgumentHelper, | ||
Dependency, | ||
Container, | ||
@@ -30,3 +28,3 @@ Provider | ||
function FactoryProvider() { | ||
function FactoryProvider /*:: <V>*/() { | ||
_classCallCheck(this, FactoryProvider); | ||
@@ -41,10 +39,5 @@ | ||
FactoryProvider.prototype.get = function get() { | ||
if (this.isCached) { | ||
return this._value; | ||
} | ||
this._value = this._helper.invokeFunction(); | ||
FactoryProvider.prototype.update = function update() { | ||
this.value = this._helper.invokeFunction(); | ||
this.isCached = true; | ||
return this._value; | ||
}; | ||
@@ -51,0 +44,0 @@ |
@@ -17,6 +17,8 @@ 'use strict'; | ||
/*:: import type {ValueAnnotation} from 'reactive-di/i/pluginsInterfaces'*/ | ||
/*:: import type { | ||
Provider, | ||
Collection | ||
ValueAnnotation, | ||
ValueProvider as IValueProvider | ||
} from 'reactive-di/i/pluginsInterfaces'*/ | ||
/*:: import type { | ||
Provider | ||
} from 'reactive-di/i/coreInterfaces'*/ | ||
@@ -27,3 +29,3 @@ | ||
function ValueProvider() { | ||
function ValueProvider /*:: <V>*/() { | ||
_classCallCheck(this, ValueProvider); | ||
@@ -36,11 +38,8 @@ | ||
// eslint-disable-line | ||
this._value = this.annotation.value; | ||
this.value = this.annotation.value; | ||
}; | ||
ValueProvider.prototype.get = function get() { | ||
return this._value; | ||
}; | ||
ValueProvider.prototype.set = function set(value /*: V*/) { | ||
this.value = value; | ||
ValueProvider.prototype.set = function set(value /*: any*/) { | ||
this._value = value; | ||
return true; | ||
@@ -47,0 +46,0 @@ }; |
@@ -32,3 +32,3 @@ /* @flow */ | ||
export type Provider<Ann: Annotation, P: Provider> = Disposable & { | ||
export type Provider<V, Ann: Annotation, P: Provider> = Disposable & { | ||
kind: any; | ||
@@ -62,7 +62,10 @@ displayName: string; | ||
init(container: Container): void; | ||
dispose(): void; | ||
get(): any; | ||
value: V; | ||
update(): void; | ||
addDependency(dependency: P): void; | ||
@@ -72,5 +75,5 @@ addDependant(dependant: P): void; | ||
export type Plugin<Ann: Annotation> = { | ||
export type Plugin<Ann: Annotation, P: Provider> = { | ||
kind: any; | ||
create(annotation: Ann, container: Container): Provider; | ||
create(annotation: Ann, container: Container): P; | ||
} | ||
@@ -81,3 +84,3 @@ | ||
invokeFunction(): any; | ||
createObject(): Object; | ||
createObject<O: Object>(): O; | ||
} | ||
@@ -84,0 +87,0 @@ |
@@ -28,10 +28,10 @@ /* @flow */ | ||
export type ValueAnnotation = Annotation & { | ||
export type ValueAnnotation<V> = Annotation & { | ||
kind: 'value'; | ||
value: any; | ||
value: V; | ||
} | ||
export type ValueProvider = Provider<ValueAnnotation> & { | ||
export type ValueProvider<V> = Provider<V, ValueAnnotation, Provider> & { | ||
kind: 'value'; | ||
set(value: any): boolean; | ||
set(value: V): boolean; | ||
} |
{ | ||
"name": "reactive-di", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"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
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
214750