reactive-di
Advanced tools
Comparing version 0.0.29 to 1.0.0
'use strict'; | ||
exports.__esModule = true; | ||
exports.syncsetter = exports.syncsetterAnnotation = exports.asyncsetter = exports.asyncsetterAnnotation = exports.observable = exports.observableAnnotation = exports.reset = exports.resetAnnotation = exports.pendingLoaderAnnotation = exports.pendingLoader = exports.loader = exports.loaderAnnotation = exports.model = exports.modelAnnotation = exports.factory = exports.factoryAnnotation = exports.meta = exports.klassAnnotation = exports.klass = exports.alias = undefined; | ||
exports.klass = exports.factory = exports.compose = exports.value = exports.tag = exports.alias = undefined; | ||
var _klass = require('./plugins/class/klass'); | ||
var _compose = require('./plugins/compose/compose'); | ||
var _factory = require('./plugins/factory/factory'); | ||
var _meta = require('./plugins/meta/meta'); | ||
var _klass = require('./plugins/class/klass'); | ||
var _model = require('./plugins/model/model'); | ||
var _value = require('./plugins/value/value'); | ||
var _loader = require('./plugins/loader/loader'); | ||
var _alias = require('./plugins/alias/alias'); | ||
var _reset = require('./plugins/loader/reset'); | ||
var _tag = require('./plugins/tag/tag'); | ||
var _observable = require('./plugins/observable/observable'); | ||
var _asyncsetter = require('./plugins/setter/asyncsetter'); | ||
var _syncsetter = require('./plugins/setter/syncsetter'); | ||
var _alias = require('./plugins/alias/alias'); | ||
exports.alias = _alias.alias; | ||
exports.klass = _klass.klass; | ||
exports.klassAnnotation = _klass.klassAnnotation; | ||
exports.meta = _meta.meta; | ||
exports.factoryAnnotation = _factory.factoryAnnotation; | ||
exports.factory = _factory.factory; | ||
exports.modelAnnotation = _model.modelAnnotation; | ||
exports.model = _model.model; | ||
exports.loaderAnnotation = _loader.loaderAnnotation; | ||
exports.loader = _loader.loader; | ||
exports.pendingLoader = _loader.pendingLoader; | ||
exports.pendingLoaderAnnotation = _loader.pendingLoaderAnnotation; | ||
exports.resetAnnotation = _reset.resetAnnotation; | ||
exports.reset = _reset.reset; | ||
exports.observableAnnotation = _observable.observableAnnotation; | ||
exports.observable = _observable.observable; | ||
exports.asyncsetterAnnotation = _asyncsetter.asyncsetterAnnotation; | ||
exports.asyncsetter = _asyncsetter.asyncsetter; | ||
exports.syncsetterAnnotation = _syncsetter.syncsetterAnnotation; | ||
exports.syncsetter = _syncsetter.syncsetter; | ||
exports.alias = _alias.aliasAnn; | ||
exports.tag = _tag.tagAnn; | ||
exports.value = _value.valueAnn; | ||
exports.compose = _compose.composeAnn; | ||
exports.factory = _factory.factoryAnn; | ||
exports.klass = _klass.klassAnn; | ||
//# sourceMappingURL=annotations.js.map |
'use strict'; | ||
exports.__esModule = true; | ||
exports.merge = exports.getFunctionName = exports.createPureStateDi = exports.BaseCollection = exports.SymbolMetaDriver = exports.DefaultIdCreator = exports.defaultPlugins = undefined; | ||
exports.defaultPlugins = exports.createConfigResolver = exports.createDefaultContainer = exports.BaseProvider = exports.SimpleMap = exports.createDummyRelationUpdater = exports.createHotRelationUpdater = exports.annotationDriver = undefined; | ||
var _createPureStateDi = require('./createPureStateDi'); | ||
var _BaseProvider = require('./core/BaseProvider'); | ||
var _createPureStateDi2 = _interopRequireDefault(_createPureStateDi); | ||
var _BaseProvider2 = _interopRequireDefault(_BaseProvider); | ||
var _getFunctionName = require('./utils/getFunctionName'); | ||
var _createConfigResolver = require('./core/createConfigResolver'); | ||
var _getFunctionName2 = _interopRequireDefault(_getFunctionName); | ||
var _createConfigResolver2 = _interopRequireDefault(_createConfigResolver); | ||
var _merge = require('./utils/merge'); | ||
var _defaultPlugins = require('./plugins/defaultPlugins'); | ||
var _merge2 = _interopRequireDefault(_merge); | ||
var _defaultPlugins2 = _interopRequireDefault(_defaultPlugins); | ||
var _BaseCollection = require('./utils/BaseCollection'); | ||
var _SimpleMap = require('./utils/SimpleMap'); | ||
var _BaseCollection2 = _interopRequireDefault(_BaseCollection); | ||
var _SimpleMap2 = _interopRequireDefault(_SimpleMap); | ||
var _DefaultIdCreator = require('./core/DefaultIdCreator'); | ||
var _createHotRelationUpdater = require('./core/updaters/createHotRelationUpdater'); | ||
var _DefaultIdCreator2 = _interopRequireDefault(_DefaultIdCreator); | ||
var _createHotRelationUpdater2 = _interopRequireDefault(_createHotRelationUpdater); | ||
var _SymbolMetaDriver = require('./drivers/SymbolMetaDriver'); | ||
var _createDummyRelationUpdater = require('./core/updaters/createDummyRelationUpdater'); | ||
var _SymbolMetaDriver2 = _interopRequireDefault(_SymbolMetaDriver); | ||
var _createDummyRelationUpdater2 = _interopRequireDefault(_createDummyRelationUpdater); | ||
var _defaultPlugins = require('./defaultPlugins'); | ||
var _annotationDriver = require('./core/annotationDriver'); | ||
var _defaultPlugins2 = _interopRequireDefault(_defaultPlugins); | ||
var _annotationDriver2 = _interopRequireDefault(_annotationDriver); | ||
var _createDefaultContainer = require('./core/createDefaultContainer'); | ||
var _createDefaultContainer2 = _interopRequireDefault(_createDefaultContainer); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
exports.annotationDriver = _annotationDriver2.default; | ||
exports.createHotRelationUpdater = _createHotRelationUpdater2.default; | ||
exports.createDummyRelationUpdater = _createDummyRelationUpdater2.default; | ||
exports.SimpleMap = _SimpleMap2.default; | ||
exports.BaseProvider = _BaseProvider2.default; | ||
exports.createDefaultContainer = _createDefaultContainer2.default; | ||
exports.createConfigResolver = _createConfigResolver2.default; | ||
exports.defaultPlugins = _defaultPlugins2.default; | ||
exports.DefaultIdCreator = _DefaultIdCreator2.default; | ||
exports.SymbolMetaDriver = _SymbolMetaDriver2.default; | ||
exports.BaseCollection = _BaseCollection2.default; | ||
exports.createPureStateDi = _createPureStateDi2.default; | ||
exports.getFunctionName = _getFunctionName2.default; | ||
exports.merge = _merge2.default; | ||
//# sourceMappingURL=index.js.map |
@@ -5,10 +5,26 @@ 'use strict'; | ||
exports.alias = alias; | ||
/*:: import type {AliasAnnotation} from 'reactive-di/i/plugins/aliasInterfaces'*/ | ||
function alias /*:: <Source: Function, Target: Function>*/(source /*: Source*/, target /*: Target*/) /*: AliasAnnotation<Source, Target>*/ { | ||
exports.aliasAnn = aliasAnn; | ||
var _annotationDriver = require('../../core/annotationDriver'); | ||
var _annotationDriver2 = _interopRequireDefault(_annotationDriver); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
/*:: import type {DependencyKey} from 'reactive-di/i/coreInterfaces'*/ | ||
/*:: import type {AliasAnnotation} from 'reactive-di/i/pluginsInterfaces'*/ | ||
function alias(target /*: DependencyKey*/, aliasTarget /*: DependencyKey*/) /*: AliasAnnotation*/ { | ||
return { | ||
kind: 'alias', | ||
source: source, | ||
target: target | ||
target: target, | ||
alias: aliasTarget | ||
}; | ||
} | ||
function aliasAnn(aliasTarget /*: Dependency*/) /*: (target: Dependency) => Dependency*/ { | ||
return function _alias(target /*: Dependency*/) /*: Dependency*/ { | ||
_annotationDriver2.default.annotate(target, (alias(target, aliasTarget) /*: Annotation*/)); | ||
return target; | ||
}; | ||
} | ||
//# sourceMappingURL=alias.js.map |
'use strict'; | ||
exports.__esModule = true; | ||
exports.ClassDepImpl = undefined; | ||
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck'); | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; }; | ||
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2); | ||
var _createProxy = require('../../utils/createProxy'); | ||
var _defaultFinalizer = require('../../pluginsCommon/defaultFinalizer'); | ||
var _fastCall = require('../../utils/fastCall'); | ||
var _defaultFinalizer2 = _interopRequireDefault(_defaultFinalizer); | ||
var _BaseProvider2 = require('../../core/BaseProvider'); | ||
var _resolveDeps = require('../../pluginsCommon/resolveDeps'); | ||
var _BaseProvider3 = _interopRequireDefault(_BaseProvider2); | ||
var _resolveDeps2 = _interopRequireDefault(_resolveDeps); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var _DepsResolverImpl = require('../../pluginsCommon/DepsResolverImpl'); | ||
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; } | ||
var _DepsResolverImpl2 = _interopRequireDefault(_DepsResolverImpl); | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
var _pluginImpls = require('../../pluginsCommon/pluginImpls'); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var _createProxy = require('../../utils/createProxy'); | ||
/*:: import type {ClassAnnotation} from 'reactive-di/i/pluginsInterfaces'*/ | ||
/*:: import type { | ||
Tag, | ||
Dependency, | ||
Resolver, | ||
Provider, | ||
Container, | ||
ResolveDepsResult | ||
} from 'reactive-di/i/coreInterfaces'*/ | ||
var _fastCall = require('../../utils/fastCall'); | ||
var ClassResolver = function () { | ||
function ClassResolver(resolver /*: () => ResolveDepsResult*/, target /*: Dependency*/, displayName /*: string*/) { | ||
_classCallCheck(this, ClassResolver); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
this._isCached = false; | ||
this._value = null; | ||
this._target = target; | ||
this._resolver = resolver; | ||
this.displayName = displayName; | ||
} | ||
/*:: import type { | ||
DepArgs, | ||
DepBase | ||
} from 'reactive-di/i/nodeInterfaces'*/ | ||
/*:: import type {AnnotationResolver} from 'reactive-di/i/nodeInterfaces'*/ | ||
/*:: import type {ClassAnnotation} from 'reactive-di/i/plugins/classInterfaces'*/ | ||
// eslint-disable-line | ||
/*:: import type {Plugin} from 'reactive-di/i/pluginInterfaces'*/ | ||
ClassResolver.prototype.reset = function reset() { | ||
this._isCached = false; | ||
}; | ||
ClassResolver.prototype.resolve = function resolve() { | ||
if (this._isCached) { | ||
return this._value; | ||
} | ||
// implements ClassDep | ||
/*:: import type {ClassDep} from 'reactive-di/i/plugins/classInterfaces'*/ | ||
var _resolver = this._resolver(); | ||
var ClassDepImpl = exports.ClassDepImpl = function () { | ||
function ClassDepImpl /*:: <V: Object>*/(annotation /*: ClassAnnotation<V>*/) { | ||
(0, _classCallCheck3.default)(this, ClassDepImpl); | ||
var deps = _resolver.deps; | ||
var middlewares = _resolver.middlewares; | ||
this.kind = 'class'; | ||
this.base = new _pluginImpls.DepBaseImpl(annotation); | ||
this._target = annotation.target; | ||
} | ||
ClassDepImpl.prototype.resolve = function resolve() { | ||
if (!this.base.isRecalculate) { | ||
return this._value; | ||
var object /*: any*/ = void 0; | ||
object = (0, _fastCall.fastCreateObject)(this._target, deps); | ||
if (middlewares) { | ||
if ((typeof object === 'undefined' ? 'undefined' : _typeof(object)) !== 'object') { | ||
throw new Error('No object returns from ' + this.displayName); | ||
} | ||
object = (0, _createProxy.createObjectProxy)(object, middlewares); | ||
} | ||
var args = (0, _resolveDeps2.default)(this._depArgs); | ||
var obj /*: V*/ = (0, _fastCall.fastCreateObject)(this._target, args.deps); | ||
if (args.middlewares) { | ||
obj = (0, _createProxy.createObjectProxy)(obj, args.middlewares); | ||
} | ||
this.base.isRecalculate = false; | ||
this._value = obj; | ||
this._value = object; | ||
this._isCached = true; | ||
@@ -67,36 +72,33 @@ return this._value; | ||
ClassDepImpl.prototype.init = function init(depArgs /*: DepArgs*/) { | ||
this._depArgs = depArgs; | ||
}; | ||
return ClassDepImpl; | ||
return ClassResolver; | ||
}(); | ||
// depends on factory | ||
// implements Plugin | ||
var ClassProvider = function (_BaseProvider) { | ||
_inherits(ClassProvider, _BaseProvider); | ||
function ClassProvider() { | ||
_classCallCheck(this, ClassProvider); | ||
var ClassPlugin = function () { | ||
function ClassPlugin() { | ||
(0, _classCallCheck3.default)(this, ClassPlugin); | ||
this.kind = 'class'; | ||
return _possibleConstructorReturn(this, _BaseProvider.apply(this, arguments)); | ||
} | ||
ClassPlugin.prototype.create = function create(annotation /*: ClassAnnotation<V>*/, acc /*: AnnotationResolver*/) { | ||
annotation.id = acc.createId(); // eslint-disable-line | ||
var dep /*: ClassDepImpl<V>*/ = new ClassDepImpl(annotation); | ||
var resolver = new _DepsResolverImpl2.default(acc); | ||
acc.begin(dep); | ||
dep.init(resolver.getDeps(annotation.deps, annotation.target, dep.base.tags)); | ||
acc.end(dep); | ||
ClassProvider.prototype.init = function init(acc /*: Container*/) { | ||
this._resolver = acc.createDepResolver(this.annotation, this.tags); | ||
}; | ||
ClassPlugin.prototype.finalize = function finalize(dep /*: ClassDep*/, target /*: Dep*/) { | ||
(0, _defaultFinalizer2.default)(dep.base, target); | ||
ClassProvider.prototype.createResolver = function createResolver() { | ||
var annotation = this.annotation; | ||
return new ClassResolver(this._resolver, annotation.dep || (annotation.target /*: any*/), this.displayName); | ||
}; | ||
return ClassPlugin; | ||
}(); | ||
return ClassProvider; | ||
}(_BaseProvider3.default); | ||
exports.default = ClassPlugin; | ||
exports.default = { | ||
kind: 'klass', | ||
create: function create(annotation /*: ClassAnnotation*/) { | ||
return new ClassProvider(annotation); | ||
} | ||
}; | ||
//# sourceMappingURL=ClassPlugin.js.map |
@@ -5,13 +5,16 @@ 'use strict'; | ||
exports.klass = klass; | ||
exports.klassAnnotation = klassAnnotation; | ||
exports.klassAnn = klassAnn; | ||
var _driver = require('../../pluginsCommon/driver'); | ||
var _annotationDriver = require('../../core/annotationDriver'); | ||
var _driver2 = _interopRequireDefault(_driver); | ||
var _annotationDriver2 = _interopRequireDefault(_annotationDriver); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
/*:: import type {DepItem} from 'reactive-di/i/annotationInterfaces'*/ | ||
/*:: import type {ClassAnnotation} from 'reactive-di/i/plugins/classInterfaces'*/ | ||
function klass /*:: <V: Object>*/(target /*: Class<V>*/) /*: ClassAnnotation<V>*/ { | ||
/*:: import type { | ||
Dependency, | ||
DepItem | ||
} from 'reactive-di/i/coreInterfaces'*/ | ||
/*:: import type {ClassAnnotation} from 'reactive-di/i/pluginsInterfaces'*/ | ||
function klass(target /*: Dependency*/) /*: ClassAnnotation*/ { | ||
for (var _len = arguments.length, deps = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
@@ -22,4 +25,3 @@ deps[_key - 1] = arguments[_key]; | ||
return { | ||
kind: 'class', | ||
id: '', | ||
kind: 'klass', | ||
target: target, | ||
@@ -30,3 +32,3 @@ deps: deps | ||
function klassAnnotation /*:: <V: Function>*/() /*: (target: V) => V*/ { | ||
function klassAnn /*:: <V: Function>*/() /*: (target: V) => V*/ { | ||
for (var _len2 = arguments.length, deps = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
@@ -37,5 +39,6 @@ deps[_key2] = arguments[_key2]; | ||
return function __klass(target /*: V*/) /*: V*/ { | ||
return _driver2.default.annotate(target, klass.apply(undefined, [target].concat(deps))); | ||
_annotationDriver2.default.annotate(target, klass.apply(undefined, [target].concat(deps))); | ||
return target; | ||
}; | ||
} | ||
//# sourceMappingURL=klass.js.map |
@@ -5,13 +5,13 @@ 'use strict'; | ||
exports.factory = factory; | ||
exports.factoryAnnotation = factoryAnnotation; | ||
exports.factoryAnn = factoryAnn; | ||
var _driver = require('../../pluginsCommon/driver'); | ||
var _annotationDriver = require('../../core/annotationDriver'); | ||
var _driver2 = _interopRequireDefault(_driver); | ||
var _annotationDriver2 = _interopRequireDefault(_annotationDriver); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
/*:: import type {DepFn, DepItem} from 'reactive-di/i/annotationInterfaces'*/ | ||
/*:: import type {FactoryAnnotation} from 'reactive-di/i/plugins/factoryInterfaces'*/ | ||
function factory /*:: <V: Function>*/(target /*: DepFn<V>*/) /*: FactoryAnnotation<V>*/ { | ||
/*:: import type {DepItem} from 'reactive-di/i/coreInterfaces'*/ | ||
/*:: import type {FactoryAnnotation} from 'reactive-di/i/pluginsInterfaces'*/ | ||
function factory(target /*: Function*/) /*: FactoryAnnotation*/ { | ||
for (var _len = arguments.length, deps = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
@@ -23,3 +23,2 @@ deps[_key - 1] = arguments[_key]; | ||
kind: 'factory', | ||
id: '', | ||
target: target, | ||
@@ -30,3 +29,3 @@ deps: deps | ||
function factoryAnnotation /*:: <V: Function>*/() /*: (target: V) => V*/ { | ||
function factoryAnn /*:: <V: Function>*/() /*: (target: V) => V*/ { | ||
for (var _len2 = arguments.length, deps = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
@@ -37,5 +36,6 @@ deps[_key2] = arguments[_key2]; | ||
return function __factory(target /*: V*/) /*: V*/ { | ||
return _driver2.default.annotate(target, factory.apply(undefined, [target].concat(deps))); | ||
_annotationDriver2.default.annotate(target, factory.apply(undefined, [target].concat(deps))); | ||
return target; | ||
}; | ||
} | ||
//# sourceMappingURL=factory.js.map |
'use strict'; | ||
exports.__esModule = true; | ||
exports.FactoryDepImpl = undefined; | ||
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck'); | ||
var _fastCall = require('../../utils/fastCall'); | ||
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2); | ||
var _BaseProvider2 = require('../../core/BaseProvider'); | ||
var _defaultFinalizer = require('../../pluginsCommon/defaultFinalizer'); | ||
var _BaseProvider3 = _interopRequireDefault(_BaseProvider2); | ||
var _defaultFinalizer2 = _interopRequireDefault(_defaultFinalizer); | ||
var _createProxy = require('../../utils/createProxy'); | ||
var _resolveDeps2 = require('../../pluginsCommon/resolveDeps'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var _resolveDeps3 = _interopRequireDefault(_resolveDeps2); | ||
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; } | ||
var _DepsResolverImpl = require('../../pluginsCommon/DepsResolverImpl'); | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
var _DepsResolverImpl2 = _interopRequireDefault(_DepsResolverImpl); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var _pluginImpls = require('../../pluginsCommon/pluginImpls'); | ||
var _createProxy = require('../../utils/createProxy'); | ||
var _fastCall = require('../../utils/fastCall'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
/*:: import type {FactoryAnnotation} from 'reactive-di/i/pluginsInterfaces'*/ | ||
/*:: import type { | ||
DepFn | ||
} from 'reactive-di/i/annotationInterfaces'*/ | ||
/*:: import type { | ||
DepArgs, | ||
DepBase, | ||
AnnotationResolver | ||
} from 'reactive-di/i/nodeInterfaces'*/ | ||
// eslint-disable-line | ||
/*:: import type {Plugin} from 'reactive-di/i/pluginInterfaces'*/ | ||
/*:: import type { | ||
FactoryDep, | ||
FactoryAnnotation | ||
} from 'reactive-di/i/plugins/factoryInterfaces'*/ | ||
Tag, | ||
Dependency, | ||
Resolver, | ||
ResolveDepsResult, | ||
Container, | ||
Provider | ||
} from 'reactive-di/i/coreInterfaces'*/ | ||
var FactoryResolver = function () { | ||
function FactoryResolver(resolver /*: () => ResolveDepsResult*/, target /*: Dependency*/, displayName /*: string*/) { | ||
_classCallCheck(this, FactoryResolver); | ||
// implements FactoryDep | ||
var FactoryDepImpl = exports.FactoryDepImpl = function () { | ||
function FactoryDepImpl /*:: <V: any>*/(annotation /*: FactoryAnnotation<V>*/) { | ||
(0, _classCallCheck3.default)(this, FactoryDepImpl); | ||
this.kind = 'factory'; | ||
this.base = new _pluginImpls.DepBaseImpl(annotation); | ||
this._target = annotation.target; | ||
this._isCached = false; | ||
this._value = null; | ||
this._target = target; | ||
this._resolver = resolver; | ||
this.displayName = displayName; | ||
} | ||
FactoryDepImpl.prototype.init = function init(depArgs /*: DepArgs*/) { | ||
this._depArgs = depArgs; | ||
FactoryResolver.prototype.reset = function reset() { | ||
this._isCached = false; | ||
}; | ||
FactoryDepImpl.prototype.resolve = function resolve() { | ||
if (!this.base.isRecalculate) { | ||
FactoryResolver.prototype.resolve = function resolve() { | ||
if (this._isCached) { | ||
return this._value; | ||
} | ||
var _resolveDeps = (0, _resolveDeps3.default)(this._depArgs); | ||
var _resolver = this._resolver(); | ||
var deps = _resolveDeps.deps; | ||
var middlewares = _resolveDeps.middlewares; | ||
// debugger | ||
var deps = _resolver.deps; | ||
var middlewares = _resolver.middlewares; | ||
var fn /*: V*/ = void 0; | ||
var fn /*: any*/ = void 0; | ||
fn = (0, _fastCall.fastCall)(this._target, deps); | ||
if (middlewares) { | ||
if (typeof fn !== 'function') { | ||
throw new Error('No callable returns from ' + this.base.displayName); | ||
throw new Error('No callable returns from ' + this.displayName); | ||
} | ||
@@ -81,3 +65,3 @@ fn = (0, _createProxy.createFunctionProxy)(fn, middlewares); | ||
this._value = fn; | ||
this.base.isRecalculate = false; | ||
this._isCached = true; | ||
@@ -87,32 +71,33 @@ return this._value; | ||
return FactoryDepImpl; | ||
return FactoryResolver; | ||
}(); | ||
// depends on meta | ||
// implements Plugin | ||
var FactoryProvider = function (_BaseProvider) { | ||
_inherits(FactoryProvider, _BaseProvider); | ||
function FactoryProvider() { | ||
_classCallCheck(this, FactoryProvider); | ||
var FactoryPlugin = function () { | ||
function FactoryPlugin() { | ||
(0, _classCallCheck3.default)(this, FactoryPlugin); | ||
this.kind = 'factory'; | ||
return _possibleConstructorReturn(this, _BaseProvider.apply(this, arguments)); | ||
} | ||
FactoryPlugin.prototype.create = function create(annotation /*: FactoryAnnotation<V>*/, acc /*: AnnotationResolver*/) { | ||
annotation.id = acc.createId(); // eslint-disable-line | ||
var dep = new FactoryDepImpl(annotation); | ||
var resolver = new _DepsResolverImpl2.default(acc); | ||
acc.begin(dep); | ||
dep.init(resolver.getDeps(annotation.deps, annotation.target, dep.base.tags)); | ||
acc.end(dep); | ||
FactoryProvider.prototype.init = function init(acc /*: Container*/) { | ||
this._resolver = acc.createDepResolver(this.annotation, this.tags); | ||
}; | ||
FactoryPlugin.prototype.finalize = function finalize(dep /*: FactoryDep*/, target /*: AnyDep*/) { | ||
(0, _defaultFinalizer2.default)(dep.base, target); | ||
FactoryProvider.prototype.createResolver = function createResolver() { | ||
var annotation = this.annotation; | ||
return new FactoryResolver(this._resolver, annotation.dep || (annotation.target /*: any*/), this.displayName); | ||
}; | ||
return FactoryPlugin; | ||
}(); | ||
return FactoryProvider; | ||
}(_BaseProvider3.default); | ||
exports.default = FactoryPlugin; | ||
exports.default = { | ||
kind: 'factory', | ||
create: function create(annotation /*: FactoryAnnotation*/) { | ||
return new FactoryProvider(annotation); | ||
} | ||
}; | ||
//# sourceMappingURL=FactoryPlugin.js.map |
'use strict'; | ||
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck'); | ||
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2); | ||
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; }(); | ||
@@ -20,2 +16,4 @@ /* eslint-env mocha */ | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
describe('createProxyTest', function () { | ||
@@ -95,3 +93,3 @@ describe('function proxy', function () { | ||
function My() { | ||
(0, _classCallCheck3.default)(this, My); | ||
_classCallCheck(this, My); | ||
} | ||
@@ -98,0 +96,0 @@ |
@@ -16,2 +16,4 @@ 'use strict'; | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
describe('getFunctionName', function () { | ||
@@ -30,6 +32,43 @@ it('should return valid function name', function () { | ||
it('should return empty function name for anonymous functions', function () { | ||
it('should return constructor name for class object', function () { | ||
var _rec2 = new _powerAssertRecorder(); | ||
(0, _powerAssert2.default)(_rec2._expr(_rec2._capt(_rec2._capt((0, _getFunctionName2.default)(function () { | ||
var B = function B() { | ||
_classCallCheck(this, B); | ||
}; | ||
var b = new B(); | ||
(0, _powerAssert2.default)(_rec2._expr(_rec2._capt(_rec2._capt((0, _getFunctionName2.default)(_rec2._capt(b, 'arguments/0/left/arguments/0')), 'arguments/0/left') === 'B', 'arguments/0'), { | ||
content: 'assert(getFunctionName(b) === \'B\')', | ||
filepath: 'src/utils/__tests__/getFunctionNameTest.js', | ||
line: 17 | ||
})); | ||
}); | ||
it('should return empty name for empty object', function () { | ||
var _rec3 = new _powerAssertRecorder(); | ||
var b = {}; | ||
(0, _powerAssert2.default)(_rec3._expr(_rec3._capt(_rec3._capt((0, _getFunctionName2.default)(_rec3._capt(b, 'arguments/0/left/arguments/0')), 'arguments/0/left') === '', 'arguments/0'), { | ||
content: 'assert(getFunctionName(b) === \'\')', | ||
filepath: 'src/utils/__tests__/getFunctionNameTest.js', | ||
line: 22 | ||
})); | ||
}); | ||
it('should return name, based on props for object', function () { | ||
var _rec4 = new _powerAssertRecorder(); | ||
var b = { aa: 123, bb: 1 }; | ||
(0, _powerAssert2.default)(_rec4._expr(_rec4._capt(_rec4._capt((0, _getFunctionName2.default)(_rec4._capt(b, 'arguments/0/left/arguments/0')), 'arguments/0/left') === 'aa,bb', 'arguments/0'), { | ||
content: 'assert(getFunctionName(b) === \'aa,bb\')', | ||
filepath: 'src/utils/__tests__/getFunctionNameTest.js', | ||
line: 27 | ||
})); | ||
}); | ||
it('should return empty function name for anonymous functions', function () { | ||
var _rec5 = new _powerAssertRecorder(); | ||
(0, _powerAssert2.default)(_rec5._expr(_rec5._capt(_rec5._capt((0, _getFunctionName2.default)(function () { | ||
return 0; | ||
@@ -39,31 +78,22 @@ }), 'arguments/0/left') === '', 'arguments/0'), { | ||
filepath: 'src/utils/__tests__/getFunctionNameTest.js', | ||
line: 15 | ||
line: 31 | ||
})); | ||
}); | ||
it('should throw error if undefined argument', function () { | ||
_powerAssert2.default.throws(function () { | ||
return (0, _getFunctionName2.default)(); | ||
}); | ||
_powerAssert2.default.throws(function () { | ||
return (0, _getFunctionName2.default)(null); | ||
}); | ||
}); | ||
it('should return empty name if empty argument', function () { | ||
var _rec3 = new _powerAssertRecorder(), | ||
_rec4 = new _powerAssertRecorder(); | ||
var _rec6 = new _powerAssertRecorder(), | ||
_rec7 = new _powerAssertRecorder(); | ||
_powerAssert2.default.equal(_rec3._expr(_rec3._capt((0, _getFunctionName2.default)(0), 'arguments/0'), { | ||
content: 'assert.equal(getFunctionName(0), \'\')', | ||
_powerAssert2.default.equal(_rec6._expr(_rec6._capt((0, _getFunctionName2.default)(0), 'arguments/0'), { | ||
content: 'assert.equal(getFunctionName(0), \'0\')', | ||
filepath: 'src/utils/__tests__/getFunctionNameTest.js', | ||
line: 24 | ||
}), ''); | ||
_powerAssert2.default.equal(_rec4._expr(_rec4._capt((0, _getFunctionName2.default)(false), 'arguments/0'), { | ||
content: 'assert.equal(getFunctionName(false), \'\')', | ||
line: 35 | ||
}), '0'); | ||
_powerAssert2.default.equal(_rec7._expr(_rec7._capt((0, _getFunctionName2.default)(false), 'arguments/0'), { | ||
content: 'assert.equal(getFunctionName(false), \'false\')', | ||
filepath: 'src/utils/__tests__/getFunctionNameTest.js', | ||
line: 25 | ||
}), ''); | ||
line: 36 | ||
}), 'false'); | ||
}); | ||
}); | ||
//# sourceMappingURL=getFunctionNameTest.js.map |
'use strict'; | ||
exports.__esModule = true; | ||
var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of'); | ||
var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf); | ||
var _getOwnPropertyNames = require('babel-runtime/core-js/object/get-own-property-names'); | ||
var _getOwnPropertyNames2 = _interopRequireDefault(_getOwnPropertyNames); | ||
var _create = require('babel-runtime/core-js/object/create'); | ||
var _create2 = _interopRequireDefault(_create); | ||
exports.createFunctionProxy = createFunctionProxy; | ||
@@ -22,4 +9,2 @@ exports.createObjectProxy = createObjectProxy; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
/*:: export type MiddlewareFn = (result: any, ...args: Array<any>) => void;*/ | ||
@@ -73,4 +58,4 @@ /*:: export type MiddlewareMap = {[method: string]: MiddlewareFn};*/ | ||
function createObjectProxy /*:: <T: Object>*/(source /*: T*/, middlewares /*: Array<MiddlewareMap>*/) /*: T*/ { | ||
var props /*: Object*/ = (0, _create2.default)(source); | ||
var methods /*: Array<string>*/ = (0, _getOwnPropertyNames2.default)((0, _getPrototypeOf2.default)(source)); | ||
var props /*: Object*/ = Object.create(source); | ||
var methods /*: Array<string>*/ = Object.getOwnPropertyNames(Object.getPrototypeOf(source)); | ||
for (var i = 0, j = methods.length; i < j; i++) { | ||
@@ -77,0 +62,0 @@ var name = methods[i]; |
'use strict'; | ||
exports.__esModule = true; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; }; | ||
exports.default = getFunctionName; | ||
var STRIP_COMMENTS /*: RegExp*/ = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg; | ||
var FN_MAGIC /*: string*/ = 'function'; | ||
function getFunctionName(func /*: Function*/) /*: string*/ { | ||
function getFunctionName(func /*: ?Function|string|number|Object*/) /*: string*/ { | ||
if (func === null || (typeof func === 'undefined' ? 'undefined' : _typeof(func)) !== 'object' && typeof func !== 'function') { | ||
return JSON.stringify(func); | ||
} | ||
if (func.displayName) { | ||
return func.displayName; | ||
} | ||
var fn = (typeof func === 'undefined' ? 'undefined' : _typeof(func)) === 'object' ? func.constructor : func; | ||
var fnStr = func.toString().replace(STRIP_COMMENTS, ''); | ||
if (fn === Object) { | ||
return Object.keys(func).join(','); | ||
} | ||
var fnStr = fn.toString().replace(STRIP_COMMENTS, ''); | ||
return fnStr.slice(fnStr.indexOf(FN_MAGIC) + FN_MAGIC.length + 1, fnStr.indexOf('(')); | ||
} | ||
//# sourceMappingURL=getFunctionName.js.map |
/* @flow */ | ||
declare function beforeEach(cb: () => void): void; | ||
declare function describe(name: string, cb: () => void): void; | ||
declare function it(name: string, cb: (done?: () => void) => void): ?Promise<void>; |
{ | ||
"name": "reactive-di", | ||
"version": "0.0.29", | ||
"version": "1.0.0", | ||
"description": "Reactive dependency injection", | ||
@@ -20,3 +20,3 @@ "publishConfig": { | ||
"update": "ncu -ua && npm install", | ||
"clean": "rm -rf $npm_package_config_builddir/dist coverage interfaces", | ||
"clean": "rm -rf $npm_package_config_builddir/dist", | ||
"build": "npm run clean && babel src --source-maps --out-dir $npm_package_config_builddir/dist", | ||
@@ -63,3 +63,3 @@ "build.dev": "babel src --source-maps --out-dir $npm_package_config_builddir/dist --watch", | ||
"babel-cli": "^6.6.5", | ||
"babel-core": "^6.7.2", | ||
"babel-core": "^6.7.4", | ||
"babel-plugin-espower": "^2.1.2", | ||
@@ -71,3 +71,2 @@ "babel-plugin-flow-comments": "^6.3.19", | ||
"babel-plugin-transform-flow-strip-types": "^6.7.0", | ||
"babel-plugin-transform-runtime": "^6.6.0", | ||
"babel-preset-es2015": "^6.6.0", | ||
@@ -81,6 +80,3 @@ "babel-preset-es2015-loose": "^7.0.0", | ||
"sinon": "^1.17.3" | ||
}, | ||
"dependencies": { | ||
"zen-observable": "^0.x.x" | ||
} | ||
} |
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
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
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
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
0
16
1
222001
92
2346
- Removedzen-observable@^0.x.x
- Removedzen-observable@0.10.0(transitive)