reactive-di
Advanced tools
Comparing version 1.0.9 to 1.0.10
@@ -21,10 +21,8 @@ 'use strict'; | ||
var BaseProvider = function () { | ||
function BaseProvider /*:: <V, A: Annotation, P: Provider>*/(annotation /*: A*/) { | ||
function BaseProvider(annotation /*: Annotation*/) { | ||
_classCallCheck(this, BaseProvider); | ||
this.kind = annotation.kind; | ||
this.dependencies = [((this /*: any*/) /*: P*/)]; | ||
this.dependencies = [(this /*: any*/)]; | ||
this.isCached = false; | ||
this.isDisposed = false; | ||
this.value = (null /*: any*/); | ||
this.displayName = annotation.displayName || annotation.kind + '@' + (0, _getFunctionName2.default)(annotation.target); | ||
@@ -34,3 +32,3 @@ this.tags = annotation.tags || []; | ||
BaseProvider.prototype.init = function init(annotation /*: A*/, container /*: Container*/) {}; // eslint-disable-line | ||
BaseProvider.prototype.init = function init(container /*: Container*/) {}; // eslint-disable-line | ||
@@ -42,8 +40,9 @@ | ||
BaseProvider.prototype.addDependency = function addDependency(dependency /*: P*/) {}; // eslint-disable-line | ||
BaseProvider.prototype.addDependency = function addDependency(dependency /*: Provider*/) { | ||
dependency.addDependant((this /*: any*/)); | ||
}; | ||
BaseProvider.prototype.addDependant = function addDependant(dependant /*: Provider*/) {}; // eslint-disable-line | ||
BaseProvider.prototype.addDependant = function addDependant(dependant /*: P*/) {}; // eslint-disable-line | ||
return BaseProvider; | ||
@@ -50,0 +49,0 @@ }(); |
@@ -51,3 +51,2 @@ 'use strict'; | ||
/*:: import type { | ||
Plugin, | ||
RelationUpdater, | ||
@@ -159,13 +158,21 @@ Container, | ||
function createManagerFactory() /*: (config?: Array<Annotation>) => ContainerManager*/ { | ||
var pluginsConfig /*:: ?: Array<Plugin>*/ = arguments.length <= 0 || arguments[0] === undefined ? _defaultPlugins2.default : arguments[0]; | ||
var pluginsConfig /*:: ?: Array<Class<Plugin>>*/ = arguments.length <= 0 || arguments[0] === undefined ? _defaultPlugins2.default : arguments[0]; | ||
var createUpdater /*:: ?: () => RelationUpdater*/ = arguments.length <= 1 || arguments[1] === undefined ? _createDummyRelationUpdater2.default : arguments[1]; | ||
var plugins /*: Map<string, Plugin>*/ = (0, _createPluginsMap2.default)(pluginsConfig); | ||
var plugins /*: Map<string, Plugin>*/ = void 0; | ||
var updater = createUpdater(); | ||
return function createContainerManager() /*: ContainerManager*/ { | ||
function createContainerManager() /*: ContainerManager*/ { | ||
var config /*:: ?: Array<Annotation>*/ = arguments.length <= 0 || arguments[0] === undefined ? [] : arguments[0]; | ||
return new DefaultContainerManager(new _AnnotationMap2.default(config), plugins, createUpdater()); | ||
}; | ||
return new DefaultContainerManager(new _AnnotationMap2.default(config), plugins, updater); | ||
} | ||
function initPlugins(PluginClass /*: Class<Plugin>*/) /*: Plugin*/ { | ||
return new PluginClass(createContainerManager); | ||
} | ||
plugins = (0, _createPluginsMap2.default)(pluginsConfig.map(initPlugins)); | ||
return createContainerManager; | ||
} | ||
//# sourceMappingURL=createManagerFactory.js.map |
@@ -32,3 +32,2 @@ 'use strict'; | ||
RelationUpdater, | ||
Plugin, | ||
Provider, | ||
@@ -172,3 +171,3 @@ DepAnnotation | ||
this._updater.begin(provider); | ||
provider.init(annotation, (this /*: Container*/)); | ||
provider.init((this /*: Container*/)); | ||
this._updater.end(provider); | ||
@@ -175,0 +174,0 @@ |
'use strict'; | ||
exports.__esModule = true; | ||
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'*/ | ||
@@ -9,8 +12,18 @@ /*:: import type { | ||
} from 'reactive-di/i/coreInterfaces'*/ | ||
exports.default = { | ||
kind: 'alias', | ||
create: function create(annotation /*: AliasAnnotation*/, container /*: Container*/) { | ||
var AliasPlugin = function () { | ||
function AliasPlugin() { | ||
_classCallCheck(this, AliasPlugin); | ||
this.kind = 'alias'; | ||
} | ||
AliasPlugin.prototype.create = function create(annotation /*: AliasAnnotation*/, container /*: Container*/) { | ||
return container.getProvider(annotation.alias); | ||
} | ||
}; | ||
}; | ||
return AliasPlugin; | ||
}(); | ||
exports.default = AliasPlugin; | ||
//# sourceMappingURL=AliasPlugin.js.map |
@@ -20,3 +20,3 @@ 'use strict'; | ||
ArgumentHelper, | ||
Provider, | ||
PipeProvider, | ||
Container | ||
@@ -28,16 +28,16 @@ } from 'reactive-di/i/coreInterfaces'*/ | ||
function ClassProvider /*:: <V: Object>*/() { | ||
var _temp, _this, _ret; | ||
function ClassProvider /*:: <V: Object>*/(annotation /*: ClassAnnotation*/) { | ||
_classCallCheck(this, ClassProvider); | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
var _this = _possibleConstructorReturn(this, _BaseProvider.call(this, annotation)); | ||
return _ret = (_temp = (_this = _possibleConstructorReturn(this, _BaseProvider.call.apply(_BaseProvider, [this].concat(args))), _this), _this._helper = (null /*: any*/), _temp), _possibleConstructorReturn(_this, _ret); | ||
_this.type = 'pipe'; | ||
_this._helper = (null /*: any*/); | ||
_this._annotation = annotation; | ||
return _this; | ||
} | ||
ClassProvider.prototype.init = function init(annotation /*: ClassAnnotation*/, container /*: Container*/) { | ||
this._helper = container.createArgumentHelper(annotation); | ||
ClassProvider.prototype.init = function init(container /*: Container*/) { | ||
this._helper = container.createArgumentHelper(this._annotation); | ||
}; | ||
@@ -49,15 +49,20 @@ | ||
ClassProvider.prototype.addDependency = function addDependency(dependency /*: Provider*/) { | ||
dependency.addDependant(this); | ||
}; | ||
return ClassProvider; | ||
}(_BaseProvider3.default); | ||
exports.default = { | ||
kind: 'klass', | ||
create: function create(annotation /*: ClassAnnotation*/) { | ||
var ClassPlugin = function () { | ||
function ClassPlugin() { | ||
_classCallCheck(this, ClassPlugin); | ||
this.kind = 'klass'; | ||
} | ||
ClassPlugin.prototype.create = function create(annotation /*: ClassAnnotation*/) { | ||
return new ClassProvider(annotation); | ||
} | ||
}; | ||
}; | ||
return ClassPlugin; | ||
}(); | ||
exports.default = ClassPlugin; | ||
//# sourceMappingURL=ClassPlugin.js.map |
@@ -22,3 +22,3 @@ 'use strict'; | ||
ArgumentHelper, | ||
Provider | ||
PipeProvider | ||
} from 'reactive-di/i/coreInterfaces'*/ | ||
@@ -29,10 +29,15 @@ | ||
function ComposeProvider /*:: <V>*/() { | ||
function ComposeProvider /*:: <V>*/(annotation /*: ComposeAnnotation*/) { | ||
_classCallCheck(this, ComposeProvider); | ||
return _possibleConstructorReturn(this, _BaseProvider.apply(this, arguments)); | ||
var _this = _possibleConstructorReturn(this, _BaseProvider.call(this, annotation)); | ||
_this.type = 'pipe'; | ||
_this._annotation = annotation; | ||
return _this; | ||
} | ||
ComposeProvider.prototype.init = function init(annotation /*: ComposeAnnotation*/, container /*: Container*/) { | ||
var helper /*: ArgumentHelper*/ = container.createArgumentHelper(annotation); | ||
ComposeProvider.prototype.init = function init(container /*: Container*/) { | ||
var helper /*: ArgumentHelper*/ = container.createArgumentHelper(this._annotation); | ||
this.isCached = true; | ||
@@ -51,8 +56,17 @@ this.value = function getValue() /*: V*/ { | ||
exports.default = { | ||
kind: 'compose', | ||
create: function create(annotation /*: ComposeAnnotation*/) { | ||
var ComposePlugin = function () { | ||
function ComposePlugin() { | ||
_classCallCheck(this, ComposePlugin); | ||
this.kind = 'compose'; | ||
} | ||
ComposePlugin.prototype.create = function create(annotation /*: ComposeAnnotation*/) { | ||
return new ComposeProvider(annotation); | ||
} | ||
}; | ||
}; | ||
return ComposePlugin; | ||
}(); | ||
exports.default = ComposePlugin; | ||
//# sourceMappingURL=ComposePlugin.js.map |
@@ -27,10 +27,5 @@ 'use strict'; | ||
/*:: import type { | ||
Plugin | ||
} from 'reactive-di/i/coreInterfaces'*/ | ||
var plugins /*: Array<Class<Plugin>>*/ = [_ComposePlugin2.default, _FactoryPlugin2.default, _ClassPlugin2.default, _ValuePlugin2.default, _AliasPlugin2.default]; | ||
var plugins /*: Array<Plugin>*/ = [_ComposePlugin2.default, _FactoryPlugin2.default, _ClassPlugin2.default, _ValuePlugin2.default, _AliasPlugin2.default]; | ||
exports.default = plugins; | ||
//# sourceMappingURL=defaultPlugins.js.map |
@@ -21,3 +21,3 @@ 'use strict'; | ||
Container, | ||
Provider | ||
PipeProvider | ||
} from 'reactive-di/i/coreInterfaces'*/ | ||
@@ -28,16 +28,16 @@ | ||
function FactoryProvider /*:: <V>*/() { | ||
var _temp, _this, _ret; | ||
function FactoryProvider /*:: <V>*/(annotation /*: FactoryAnnotation*/) { | ||
_classCallCheck(this, FactoryProvider); | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
var _this = _possibleConstructorReturn(this, _BaseProvider.call(this, annotation)); | ||
return _ret = (_temp = (_this = _possibleConstructorReturn(this, _BaseProvider.call.apply(_BaseProvider, [this].concat(args))), _this), _this._helper = (null /*: any*/), _temp), _possibleConstructorReturn(_this, _ret); | ||
_this.type = 'pipe'; | ||
_this._helper = (null /*: any*/); | ||
_this._annotation = annotation; | ||
return _this; | ||
} | ||
FactoryProvider.prototype.init = function init(annotation /*: FactoryAnnotation*/, container /*: Container*/) { | ||
this._helper = container.createArgumentHelper(annotation); | ||
FactoryProvider.prototype.init = function init(container /*: Container*/) { | ||
this._helper = container.createArgumentHelper(this._annotation); | ||
}; | ||
@@ -49,15 +49,20 @@ | ||
FactoryProvider.prototype.addDependency = function addDependency(dependency /*: Provider*/) { | ||
dependency.addDependant(this); | ||
}; | ||
return FactoryProvider; | ||
}(_BaseProvider3.default); | ||
exports.default = { | ||
kind: 'factory', | ||
create: function create(annotation /*: FactoryAnnotation*/) { | ||
var FactoryPlugin = function () { | ||
function FactoryPlugin() { | ||
_classCallCheck(this, FactoryPlugin); | ||
this.kind = 'factory'; | ||
} | ||
FactoryPlugin.prototype.create = function create(annotation /*: FactoryAnnotation*/) { | ||
return new FactoryProvider(annotation); | ||
} | ||
}; | ||
}; | ||
return FactoryPlugin; | ||
}(); | ||
exports.default = FactoryPlugin; | ||
//# sourceMappingURL=FactoryPlugin.js.map |
@@ -18,7 +18,6 @@ 'use strict'; | ||
/*:: import type { | ||
ValueAnnotation, | ||
ValueProvider as IValueProvider | ||
ValueAnnotation | ||
} from 'reactive-di/i/pluginsInterfaces'*/ | ||
/*:: import type { | ||
Provider | ||
ValueProvider as IValueProvider | ||
} from 'reactive-di/i/coreInterfaces'*/ | ||
@@ -34,2 +33,4 @@ | ||
_this.type = 'value'; | ||
_this.value = annotation.value; | ||
@@ -44,15 +45,20 @@ return _this; | ||
ValueProvider.prototype.addDependency = function addDependency(dependency /*: Provider*/) { | ||
dependency.addDependant(this); | ||
}; | ||
return ValueProvider; | ||
}(_BaseProvider3.default); | ||
exports.default = { | ||
kind: 'value', | ||
create: function create(annotation /*: ValueAnnotation*/) { | ||
var ValuePlugin = function () { | ||
function ValuePlugin() { | ||
_classCallCheck(this, ValuePlugin); | ||
this.kind = 'value'; | ||
} | ||
ValuePlugin.prototype.create = function create(annotation /*: ValueAnnotation*/) { | ||
return new ValueProvider(annotation); | ||
} | ||
}; | ||
}; | ||
return ValuePlugin; | ||
}(); | ||
exports.default = ValuePlugin; | ||
//# sourceMappingURL=ValuePlugin.js.map |
@@ -12,3 +12,2 @@ 'use strict'; | ||
/*:: import type {Plugin} from 'reactive-di/i/coreInterfaces'*/ | ||
function createProvidersMap(plugins /*: Array<Plugin>*/) /*: Map<string, Plugin>*/ { | ||
@@ -15,0 +14,0 @@ var pluginMap /*: Map<string, Plugin>*/ = new _SimpleMap2.default(); |
@@ -32,8 +32,17 @@ /* @flow */ | ||
export type Provider<V, A: Annotation, P: Provider> = { | ||
/** | ||
* Provider type | ||
*/ | ||
kind: any; | ||
export type Meta = { | ||
pending: boolean; | ||
success: boolean; | ||
error: boolean; | ||
reason: string; | ||
} | ||
export type PromiseSource = { | ||
promise: ?Promise<void>; | ||
meta: Meta; | ||
} | ||
export type PipeProvider<V> = { | ||
type: 'pipe'; | ||
/** | ||
@@ -53,3 +62,3 @@ * Debug name | ||
*/ | ||
dependencies: Array<P>; | ||
dependencies: Array<Provider>; | ||
@@ -79,8 +88,8 @@ /** | ||
* ```js | ||
* init(annotation: FactoryAnnotation, container: Container): void { | ||
* this._helper = container.createArgumentHelper(annotation); | ||
* init(container: Container): void { | ||
* this._helper = container.createArgumentHelper(this._annotation); | ||
* } | ||
* ``` | ||
*/ | ||
init(annotation: A, container: Container): void; | ||
init(container: Container): void; | ||
@@ -100,3 +109,3 @@ /** | ||
*/ | ||
addDependency(dependency: P): void; | ||
addDependency(dependency: Provider): void; | ||
@@ -106,10 +115,58 @@ /** | ||
*/ | ||
addDependant(dependant: P): void; | ||
addDependant(dependant: Provider): void; | ||
} | ||
export type Plugin<Ann: Annotation, P: Provider> = { | ||
kind: any; | ||
create(annotation: Ann, container: Container): P; | ||
export type ValueProvider<V> = { | ||
type: 'value'; | ||
set(v: V): boolean; | ||
displayName: string; | ||
tags: Array<Tag>; | ||
dependencies: Array<Provider>; | ||
isCached: boolean; | ||
isDisposed: boolean; | ||
value: V; | ||
init(container: Container): void; | ||
dispose(): void; | ||
update(): void; | ||
addDependency(dependency: Provider): void; | ||
addDependant(dependant: Provider): void; | ||
} | ||
export type ListenerProvider<V> = { | ||
type: 'listener'; | ||
notify(): void; | ||
displayName: string; | ||
tags: Array<Tag>; | ||
dependencies: Array<Provider>; | ||
isCached: boolean; | ||
isDisposed: boolean; | ||
value: V; | ||
init(container: Container): void; | ||
dispose(): void; | ||
update(): void; | ||
addDependency(dependency: Provider): void; | ||
addDependant(dependant: Provider): void; | ||
} | ||
export type EmiterProvider<V> = { | ||
type: 'emiter'; | ||
state: PromiseSource; | ||
displayName: string; | ||
tags: Array<Tag>; | ||
dependencies: Array<Provider>; | ||
isCached: boolean; | ||
isDisposed: boolean; | ||
value: V; | ||
init(container: Container): void; | ||
dispose(): void; | ||
update(): void; | ||
addDependency(dependency: Provider): void; | ||
addDependant(dependant: Provider): void; | ||
} | ||
export type Provider<V> = PipeProvider<V> | ValueProvider<V> | ListenerProvider<V> | EmiterProvider<V>; | ||
export type ArgumentHelper = { | ||
@@ -116,0 +173,0 @@ invokeComposed(...args: Array<any>): any; |
@@ -5,5 +5,2 @@ /* @flow */ | ||
Annotation, | ||
Provider, | ||
Tag, | ||
DepItem, | ||
DependencyKey | ||
@@ -33,6 +30,1 @@ } from 'reactive-di/i/coreInterfaces' | ||
} | ||
export type ValueProvider<V> = Provider<V, ValueAnnotation, Provider> & { | ||
kind: 'value'; | ||
set(value: V): boolean; | ||
} |
@@ -29,2 +29,7 @@ /* @flow */ | ||
declare class Plugin { | ||
kind: any; | ||
create(annotation: Annotation, container: Container): Provider; | ||
} | ||
declare function createManagerFactory( | ||
@@ -48,4 +53,3 @@ pluginsConfig?: Array<Plugin>, | ||
declare class BaseProvider<V, Ann: Annotation, P: Provider> { | ||
kind: any; | ||
declare class BaseProvider<V> { | ||
displayName: string; | ||
@@ -56,12 +60,10 @@ tags: Array<Tag>; | ||
isCached: boolean; | ||
dependencies: Array<Provider|P>; | ||
dependencies: Array<Provider>; | ||
constructor(annotation: Ann): void; | ||
init(annotation: Ann, container: Container): void; | ||
init(container: Container): void; | ||
dispose(): void; | ||
update(): void; | ||
addDependency(dependency: P): void; | ||
addDependant(dependant: P): void; | ||
addDependency(dependency: Provider): void; | ||
addDependant(dependant: Provider): void; | ||
} | ||
} |
{ | ||
"name": "reactive-di", | ||
"version": "1.0.9", | ||
"version": "1.0.10", | ||
"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
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
217893
2374