reactive-di
Advanced tools
Comparing version 1.0.11 to 1.1.0
@@ -16,8 +16,8 @@ 'use strict'; | ||
Annotation, | ||
Container, | ||
Provider | ||
Provider, | ||
Container | ||
} from 'reactive-di/i/coreInterfaces'*/ | ||
var BaseProvider = function () { | ||
function BaseProvider /*:: <InitState>*/(annotation /*: Annotation*/) { | ||
function BaseProvider(annotation /*: Annotation*/, container /*: Container*/) { | ||
_classCallCheck(this, BaseProvider); | ||
@@ -30,7 +30,5 @@ | ||
this.tags = annotation.tags || []; | ||
container.beginInitialize(((this /*: any*/) /*: Provider*/)); | ||
} | ||
BaseProvider.prototype.init = function init(container /*: Container*/, initState /*: ?InitState*/) {}; // eslint-disable-line | ||
BaseProvider.prototype.dispose = function dispose() {}; | ||
@@ -37,0 +35,0 @@ |
@@ -48,3 +48,5 @@ 'use strict'; | ||
DependencyKey, | ||
Annotation | ||
Annotation, | ||
Plugin, | ||
CreatePlugin | ||
} from 'reactive-di/i/coreInterfaces'*/ | ||
@@ -158,3 +160,3 @@ /*:: import type { | ||
function createManagerFactory() /*: (config?: Array<Annotation>) => ContainerManager*/ { | ||
var pluginsConfig /*:: ?: Array<Class<Plugin>>*/ = arguments.length <= 0 || arguments[0] === undefined ? _defaultPlugins2.default : arguments[0]; | ||
var pluginsConfig /*:: ?: Array<CreatePlugin>*/ = arguments.length <= 0 || arguments[0] === undefined ? _defaultPlugins2.default : arguments[0]; | ||
var createUpdater /*:: ?: () => RelationUpdater*/ = arguments.length <= 1 || arguments[1] === undefined ? _createDummyRelationUpdater2.default : arguments[1]; | ||
@@ -170,7 +172,4 @@ | ||
} | ||
function initPlugins(PluginClass /*: Class<Plugin>*/) /*: Plugin*/ { | ||
return new PluginClass(createContainerManager); | ||
} | ||
plugins = (0, _createPluginsMap2.default)(pluginsConfig.map(initPlugins)); | ||
plugins = (0, _createPluginsMap2.default)(createContainerManager, pluginsConfig); | ||
@@ -177,0 +176,0 @@ return createContainerManager; |
@@ -24,2 +24,3 @@ 'use strict'; | ||
/*:: import type { | ||
Plugin, | ||
Annotation, | ||
@@ -144,2 +145,6 @@ Tag, | ||
DefaultContainer.prototype.beginInitialize = function beginInitialize(provider /*: Provider*/) { | ||
this._updater.begin(provider); | ||
}; | ||
DefaultContainer.prototype.getProvider = function getProvider(annotatedDep /*: DependencyKey*/) { | ||
@@ -170,9 +175,12 @@ var provider /*: ?Provider*/ = this._providerCache.get(annotatedDep); | ||
} | ||
provider = plugin.create(annotation, (this /*: Container*/)); | ||
this._updater.begin(provider); | ||
provider.init((this /*: Container*/), this._initState.get(annotatedDep)); | ||
this._updater.end(provider); | ||
var container = plugin.createContainer(annotation, this); | ||
var updater = this._updater; | ||
var l = updater.length; | ||
provider = plugin.createProvider(annotation, container, this._initState.get(annotatedDep)); | ||
if (l !== updater.length) { | ||
updater.end(provider); | ||
} | ||
this._providerCache.set(annotatedDep, provider); | ||
this._privateCache.set(annotatedDep, provider); | ||
container._privateCache.set(annotatedDep, provider); | ||
@@ -179,0 +187,0 @@ return provider; |
'use strict'; | ||
exports.__esModule = true; | ||
exports.default = createAliasPlugin; | ||
@@ -10,3 +11,4 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
Container, | ||
Provider | ||
Provider, | ||
Plugin | ||
} from 'reactive-di/i/coreInterfaces'*/ | ||
@@ -21,3 +23,7 @@ | ||
AliasPlugin.prototype.create = function create(annotation /*: AliasAnnotation*/, container /*: Container*/) { | ||
AliasPlugin.prototype.createContainer = function createContainer(annotation /*: AliasAnnotation*/, container /*: Container*/) { | ||
return container; | ||
}; | ||
AliasPlugin.prototype.createProvider = function createProvider(annotation /*: AliasAnnotation*/, container /*: Container*/) { | ||
return container.getProvider(annotation.alias); | ||
@@ -29,3 +35,5 @@ }; | ||
exports.default = AliasPlugin; | ||
function createAliasPlugin() /*: Plugin*/ { | ||
return new AliasPlugin(); | ||
} | ||
//# sourceMappingURL=AliasPlugin.js.map |
'use strict'; | ||
exports.__esModule = true; | ||
exports.default = createClassPlugin; | ||
@@ -21,3 +22,4 @@ var _BaseProvider2 = require('../../core/BaseProvider'); | ||
PipeProvider, | ||
Container | ||
Container, | ||
Plugin | ||
} from 'reactive-di/i/coreInterfaces'*/ | ||
@@ -28,18 +30,13 @@ | ||
function ClassProvider /*:: <V>*/(annotation /*: ClassAnnotation*/) { | ||
function ClassProvider /*:: <V>*/(annotation /*: ClassAnnotation*/, container /*: Container*/) { | ||
_classCallCheck(this, ClassProvider); | ||
var _this = _possibleConstructorReturn(this, _BaseProvider.call(this, annotation)); | ||
var _this = _possibleConstructorReturn(this, _BaseProvider.call(this, annotation, container)); | ||
_this.type = 'pipe'; | ||
_this._helper = (null /*: any*/); | ||
_this._annotation = annotation; | ||
_this._helper = container.createArgumentHelper(annotation); | ||
return _this; | ||
} | ||
ClassProvider.prototype.init = function init(container /*: Container*/) { | ||
this._helper = container.createArgumentHelper(this._annotation); | ||
}; | ||
ClassProvider.prototype.update = function update() { | ||
@@ -59,10 +56,17 @@ this.value = this._helper.createObject(); | ||
ClassPlugin.prototype.create = function create(annotation /*: ClassAnnotation*/) { | ||
return new ClassProvider(annotation); | ||
ClassPlugin.prototype.createContainer = function createContainer(annotation /*: ClassAnnotation*/, container /*: Container*/) { | ||
return container; | ||
}; | ||
ClassPlugin.prototype.createProvider = function createProvider(annotation /*: ClassAnnotation*/, container /*: Container*/) { | ||
// eslint-disable-line | ||
return new ClassProvider(annotation, container); | ||
}; | ||
return ClassPlugin; | ||
}(); | ||
exports.default = ClassPlugin; | ||
function createClassPlugin() /*: Plugin*/ { | ||
return new ClassPlugin(); | ||
} | ||
//# sourceMappingURL=ClassPlugin.js.map |
'use strict'; | ||
exports.__esModule = true; | ||
exports.default = createComposePlugin; | ||
@@ -22,3 +23,4 @@ var _BaseProvider2 = require('../../core/BaseProvider'); | ||
ArgumentHelper, | ||
PipeProvider | ||
PipeProvider, | ||
Plugin | ||
} from 'reactive-di/i/coreInterfaces'*/ | ||
@@ -29,17 +31,13 @@ | ||
function ComposeProvider /*:: <V>*/(annotation /*: ComposeAnnotation*/) { | ||
function ComposeProvider /*:: <V>*/(annotation /*: ComposeAnnotation*/, container /*: Container*/) { | ||
_classCallCheck(this, ComposeProvider); | ||
var _this = _possibleConstructorReturn(this, _BaseProvider.call(this, annotation)); | ||
var _this = _possibleConstructorReturn(this, _BaseProvider.call(this, annotation, container)); | ||
_this.type = 'pipe'; | ||
_this._annotation = annotation; | ||
return _this; | ||
} | ||
_this.isCached = true; | ||
var helper /*: ArgumentHelper*/ = container.createArgumentHelper(annotation); | ||
ComposeProvider.prototype.init = function init(container /*: Container*/) { | ||
var helper /*: ArgumentHelper*/ = container.createArgumentHelper(this._annotation); | ||
this.isCached = true; | ||
this.value = function getValue() /*: V*/ { | ||
_this.value = function getValue() /*: V*/ { | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
@@ -51,3 +49,4 @@ args[_key] = arguments[_key]; | ||
}; | ||
}; | ||
return _this; | ||
} | ||
@@ -64,10 +63,16 @@ return ComposeProvider; | ||
ComposePlugin.prototype.create = function create(annotation /*: ComposeAnnotation*/) { | ||
return new ComposeProvider(annotation); | ||
ComposePlugin.prototype.createContainer = function createContainer(annotation /*: ComposeAnnotation*/, container /*: Container*/) { | ||
return container; | ||
}; | ||
ComposePlugin.prototype.createProvider = function createProvider(annotation /*: ComposeAnnotation*/, container /*: Container*/) { | ||
return new ComposeProvider(annotation, container); | ||
}; | ||
return ComposePlugin; | ||
}(); | ||
exports.default = ComposePlugin; | ||
function createComposePlugin() /*: Plugin*/ { | ||
return new ComposePlugin(); | ||
} | ||
//# sourceMappingURL=ComposePlugin.js.map |
@@ -27,5 +27,10 @@ 'use strict'; | ||
var plugins /*: Array<Class<Plugin>>*/ = [_ComposePlugin2.default, _FactoryPlugin2.default, _ClassPlugin2.default, _ValuePlugin2.default, _AliasPlugin2.default]; | ||
/*:: import type { | ||
CreatePlugin | ||
} from 'reactive-di/i/coreInterfaces'*/ | ||
var plugins /*: Array<CreatePlugin>*/ = [_ComposePlugin2.default, _FactoryPlugin2.default, _ClassPlugin2.default, _ValuePlugin2.default, _AliasPlugin2.default]; | ||
exports.default = plugins; | ||
//# sourceMappingURL=defaultPlugins.js.map |
'use strict'; | ||
exports.__esModule = true; | ||
exports.default = createFactoryPlugin; | ||
@@ -21,3 +22,4 @@ var _BaseProvider2 = require('../../core/BaseProvider'); | ||
Container, | ||
PipeProvider | ||
PipeProvider, | ||
Plugin | ||
} from 'reactive-di/i/coreInterfaces'*/ | ||
@@ -28,18 +30,13 @@ | ||
function FactoryProvider /*:: <V>*/(annotation /*: FactoryAnnotation*/) { | ||
function FactoryProvider /*:: <V>*/(annotation /*: FactoryAnnotation*/, container /*: Container*/) { | ||
_classCallCheck(this, FactoryProvider); | ||
var _this = _possibleConstructorReturn(this, _BaseProvider.call(this, annotation)); | ||
var _this = _possibleConstructorReturn(this, _BaseProvider.call(this, annotation, container)); | ||
_this.type = 'pipe'; | ||
_this._helper = (null /*: any*/); | ||
_this._annotation = annotation; | ||
_this._helper = container.createArgumentHelper(annotation); | ||
return _this; | ||
} | ||
FactoryProvider.prototype.init = function init(container /*: Container*/) { | ||
this._helper = container.createArgumentHelper(this._annotation); | ||
}; | ||
FactoryProvider.prototype.update = function update() { | ||
@@ -59,10 +56,16 @@ this.value = this._helper.invokeFunction(); | ||
FactoryPlugin.prototype.create = function create(annotation /*: FactoryAnnotation*/) { | ||
return new FactoryProvider(annotation); | ||
FactoryPlugin.prototype.createContainer = function createContainer(annotation /*: FactoryAnnotation*/, container /*: Container*/) { | ||
return container; | ||
}; | ||
FactoryPlugin.prototype.createProvider = function createProvider(annotation /*: FactoryAnnotation*/, container /*: Container*/) { | ||
return new FactoryProvider(annotation, container); | ||
}; | ||
return FactoryPlugin; | ||
}(); | ||
exports.default = FactoryPlugin; | ||
function createFactoryPlugin() /*: Plugin*/ { | ||
return new FactoryPlugin(); | ||
} | ||
//# sourceMappingURL=FactoryPlugin.js.map |
'use strict'; | ||
exports.__esModule = true; | ||
exports.default = createValuePlugin; | ||
@@ -21,2 +22,4 @@ var _BaseProvider2 = require('../../core/BaseProvider'); | ||
/*:: import type { | ||
Plugin, | ||
Container, | ||
ValueProvider as IValueProvider | ||
@@ -28,19 +31,13 @@ } from 'reactive-di/i/coreInterfaces'*/ | ||
function ValueProvider /*:: <V>*/(annotation /*: ValueAnnotation<V>*/) { | ||
function ValueProvider /*:: <V>*/(annotation /*: ValueAnnotation<V>*/, container /*: Container*/, value /*: ?V*/) { | ||
_classCallCheck(this, ValueProvider); | ||
var _this = _possibleConstructorReturn(this, _BaseProvider.call(this, annotation)); | ||
var _this = _possibleConstructorReturn(this, _BaseProvider.call(this, annotation, container)); | ||
_this.type = 'value'; | ||
_this.value = annotation.value; | ||
_this.value = value || annotation.value; | ||
return _this; | ||
} | ||
ValueProvider.prototype.init = function init(container /*: Container*/, value /*: ?V*/) { | ||
if (value) { | ||
this.value = value; | ||
} | ||
}; | ||
ValueProvider.prototype.set = function set(value /*: V*/) { | ||
@@ -61,10 +58,16 @@ this.value = value; | ||
ValuePlugin.prototype.create = function create(annotation /*: ValueAnnotation*/) { | ||
return new ValueProvider(annotation); | ||
ValuePlugin.prototype.createContainer = function createContainer(annotation /*: ValueAnnotation*/, container /*: Container*/) { | ||
return container; | ||
}; | ||
ValuePlugin.prototype.createProvider = function createProvider(annotation /*: ValueAnnotation*/, container /*: Container*/, value /*: any*/) { | ||
return new ValueProvider(annotation, container, value); | ||
}; | ||
return ValuePlugin; | ||
}(); | ||
exports.default = ValuePlugin; | ||
function createValuePlugin() /*: Plugin*/ { | ||
return new ValuePlugin(); | ||
} | ||
//# sourceMappingURL=ValuePlugin.js.map |
'use strict'; | ||
exports.__esModule = true; | ||
exports.default = createProvidersMap; | ||
exports.default = createPluginsMap; | ||
@@ -12,10 +12,16 @@ var _SimpleMap = require('./SimpleMap'); | ||
function createProvidersMap(plugins /*: Array<Plugin>*/) /*: Map<string, Plugin>*/ { | ||
/*:: import type { | ||
CreateContainerManager, | ||
CreatePlugin, | ||
Plugin | ||
} from 'reactive-di/i/coreInterfaces'*/ | ||
function createPluginsMap(createContainerManager /*: CreateContainerManager*/, plugins /*: Array<CreatePlugin>*/) /*: Map<string, Plugin>*/ { | ||
var pluginMap /*: Map<string, Plugin>*/ = new _SimpleMap2.default(); | ||
for (var i = 0, l = plugins.length; i < l; i++) { | ||
var plugin /*: Plugin*/ = plugins[i]; | ||
var plugin /*: Plugin*/ = plugins[i](createContainerManager); | ||
pluginMap.set(plugin.kind, plugin); | ||
} | ||
return pluginMap; | ||
} | ||
//# sourceMappingURL=createPluginsMap.js.map |
@@ -35,4 +35,3 @@ /* @flow */ | ||
success: boolean; | ||
error: boolean; | ||
reason: string; | ||
error: ?Error; | ||
} | ||
@@ -45,3 +44,3 @@ | ||
export type PipeProvider<V, InitState> = { | ||
export type PipeProvider<V> = { | ||
type: 'pipe'; | ||
@@ -83,15 +82,2 @@ | ||
/** | ||
* Resolve dependencies here via Container.createArgumentHelper() | ||
* | ||
* @example | ||
* | ||
* ```js | ||
* init(container: Container): void { | ||
* this._helper = container.createArgumentHelper(this._annotation); | ||
* } | ||
* ``` | ||
*/ | ||
init(container: Container, initState: ?InitState): void; | ||
/** | ||
* Set isDisposed = true and runs some logic for unsubscribes | ||
@@ -117,3 +103,3 @@ */ | ||
export type ValueProvider<V, InitState> = { | ||
export type ValueProvider<V> = { | ||
type: 'value'; | ||
@@ -128,3 +114,2 @@ set(v: V): boolean; | ||
value: V; | ||
init(container: Container, initState: InitState): void; | ||
dispose(): void; | ||
@@ -136,3 +121,3 @@ update(): void; | ||
export type ListenerProvider<V, InitState> = { | ||
export type ListenerProvider<V> = { | ||
type: 'listener'; | ||
@@ -147,3 +132,2 @@ notify(): void; | ||
value: V; | ||
init(container: Container, initState: InitState): void; | ||
dispose(): void; | ||
@@ -155,3 +139,3 @@ update(): void; | ||
export type EmiterProvider<V, InitState> = { | ||
export type EmiterProvider<V> = { | ||
type: 'emiter'; | ||
@@ -167,3 +151,2 @@ state: PromiseSource; | ||
value: V; | ||
init(container: Container, initState: InitState): void; | ||
dispose(): void; | ||
@@ -184,3 +167,5 @@ update(): void; | ||
export type Container = { | ||
_privateCache: Map<DependencyKey, Provider>; | ||
createArgumentHelper(annotation: DepAnnotation): ArgumentHelper; | ||
beginInitialize(provider: Provider): void; | ||
get(annotatedDep: DependencyKey): any; | ||
@@ -208,1 +193,13 @@ getProvider(annotatedDep: DependencyKey): Provider; | ||
} | ||
export type Plugin<State, A: Annotation, P: Provider> = { | ||
kind: any; | ||
createContainer(annotation: A, parent: Container): Container; | ||
createProvider( | ||
annotation: A, | ||
container: Container, | ||
initialState: ?State | ||
): P; | ||
} | ||
export type CreatePlugin = (cm: CreateContainerManager) => Plugin; |
@@ -5,4 +5,2 @@ /* @flow */ | ||
Disposable, | ||
Collection, | ||
Container, | ||
Tag, | ||
@@ -13,3 +11,3 @@ DependencyKey, | ||
Provider, | ||
Plugin, | ||
CreatePlugin, | ||
RelationUpdater, | ||
@@ -31,11 +29,6 @@ CreateContainerManager, | ||
declare class Plugin { | ||
kind: any; | ||
create(annotation: Annotation, container: Container): Provider; | ||
} | ||
declare function createManagerFactory( | ||
pluginsConfig?: Array<Plugin>, | ||
pluginsConfig?: Array<CreatePlugin>, | ||
createUpdater?: () => RelationUpdater | ||
): (config?: Array<Annotation>) => ContainerManager; | ||
): CreateContainerManager; | ||
@@ -55,3 +48,3 @@ declare function createHotRelationUpdater(): RelationUpdater; | ||
declare class BaseProvider<InitState> { | ||
declare class BaseProvider { | ||
displayName: string; | ||
@@ -63,3 +56,2 @@ tags: Array<Tag>; | ||
init(container: Container, initState: ?InitState): void; | ||
dispose(): void; | ||
@@ -66,0 +58,0 @@ update(): void; |
{ | ||
"name": "reactive-di", | ||
"version": "1.0.11", | ||
"version": "1.1.0", | ||
"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
222229
2404