reactive-di
Advanced tools
Comparing version 4.0.11 to 4.0.12
@@ -5,2 +5,7 @@ # Change Log | ||
<a name="4.0.12"></a> | ||
## [4.0.12](https://github.com/zerkalica/reactive-di/compare/v4.0.11...v4.0.12) (2017-09-10) | ||
<a name="4.0.11"></a> | ||
@@ -7,0 +12,0 @@ ## [4.0.11](https://github.com/zerkalica/reactive-di/compare/v4.0.10...v4.0.11) (2017-09-10) |
@@ -126,5 +126,6 @@ import { defaultContext, detached, memkey } from 'lom_atom'; | ||
var Injector = function () { | ||
function Injector(items, sheetProcessor, state, parent, displayName, instance) { | ||
function Injector(items, sheetProcessor, state, parent, displayName, instance, aliases) { | ||
this._resolved = false; | ||
this._listeners = undefined; | ||
this._aliases = aliases; | ||
this._instance = instance || 0; | ||
@@ -159,3 +160,5 @@ this._state = state || null; | ||
Injector.prototype.value = function value(key) { | ||
Injector.prototype.value = function value(rawKey) { | ||
var key = this._aliases === undefined ? rawKey : this._aliases.get(rawKey) || rawKey; | ||
var value = this._cache.get(key); | ||
@@ -271,3 +274,8 @@ | ||
Injector.prototype.alias = function alias(key) { | ||
return this._cache.get(key) || key; | ||
if (this._aliases === undefined) return key; | ||
var newKey = this._aliases.get(key); | ||
if (newKey === undefined) return key; | ||
return newKey; | ||
}; | ||
@@ -327,4 +335,4 @@ | ||
Injector.prototype.copy = function copy(items, displayName, instance) { | ||
return new Injector(items, this._sheetManager, this._state, this, this.displayName + '.' + displayName, instance); | ||
Injector.prototype.copy = function copy(items, displayName, instance, aliases) { | ||
return new Injector(items, this._sheetManager, this._state, this, this.displayName + '.' + displayName, instance, aliases); | ||
}; | ||
@@ -422,2 +430,8 @@ | ||
if (isAtomic) { | ||
if (parentContext !== undefined) { | ||
newEl = parentContext.alias(el); | ||
if (newEl === null) return null; | ||
if (newEl !== undefined) el = newEl; | ||
} | ||
if (el.__lom === undefined) { | ||
@@ -497,16 +511,6 @@ el.__lom = atomize(el); | ||
var parentInjector = props.__lom_ctx || rootInjector; | ||
var render = parentInjector._cache.get(cns.render); | ||
if (render === null) { | ||
_this._el = null; | ||
_this._keys = undefined; | ||
_this._render = undefined; | ||
} else { | ||
_this._render = render === undefined ? cns.render : render; | ||
var injectorName = cns.displayName + (cns.instance ? '[' + cns.instance + ']' : ''); | ||
_this._injector = parentInjector.copy(_this._render.provides, injectorName, cns.instance); | ||
cns.instance++; | ||
} | ||
_this._render = cns.render; | ||
var injectorName = cns.displayName + (cns.instance ? '[' + cns.instance + ']' : ''); | ||
_this._injector = parentInjector.copy(undefined, injectorName, cns.instance, _this._render.aliases); | ||
cns.instance++; | ||
return _this; | ||
@@ -585,6 +589,2 @@ } | ||
return function reactWrapper(render) { | ||
if (render.__lom !== undefined) { | ||
return render.__lom; | ||
} | ||
var WrappedComponent = function WrappedComponent(props, context) { | ||
@@ -619,6 +619,6 @@ AtomizedComponent.call(this, props, context); | ||
function provideMap(item) { | ||
return item instanceof Array ? "[" + dn(item[0]) + ", " + dn(item[1]) + "]" : dn(item); | ||
return "[" + dn(item[0]) + ", " + dn(item[1]) + "]"; | ||
} | ||
function cloneComponent(fn, items, name) { | ||
function cloneComponent(fn, aliases, name) { | ||
var cloned = function cloned() { | ||
@@ -647,4 +647,5 @@ switch (arguments.length) { | ||
cloned.deps = fn.deps; | ||
cloned.provides = items; | ||
cloned.displayName = name || "cloneComponent(" + dn(fn) + ", [" + items.map(provideMap).join(', ') + "])"; | ||
cloned._r = fn._r; | ||
cloned.aliases = aliases !== undefined ? new Map(aliases) : undefined; | ||
cloned.displayName = name || "cloneComponent(" + dn(fn) + ", [" + aliases.map(provideMap).join(', ') + "])"; | ||
return cloned; | ||
@@ -651,0 +652,0 @@ } |
@@ -130,5 +130,6 @@ 'use strict'; | ||
var Injector = function () { | ||
function Injector(items, sheetProcessor, state, parent, displayName, instance) { | ||
function Injector(items, sheetProcessor, state, parent, displayName, instance, aliases) { | ||
this._resolved = false; | ||
this._listeners = undefined; | ||
this._aliases = aliases; | ||
this._instance = instance || 0; | ||
@@ -163,3 +164,5 @@ this._state = state || null; | ||
Injector.prototype.value = function value(key) { | ||
Injector.prototype.value = function value(rawKey) { | ||
var key = this._aliases === undefined ? rawKey : this._aliases.get(rawKey) || rawKey; | ||
var value = this._cache.get(key); | ||
@@ -275,3 +278,8 @@ | ||
Injector.prototype.alias = function alias(key) { | ||
return this._cache.get(key) || key; | ||
if (this._aliases === undefined) return key; | ||
var newKey = this._aliases.get(key); | ||
if (newKey === undefined) return key; | ||
return newKey; | ||
}; | ||
@@ -331,4 +339,4 @@ | ||
Injector.prototype.copy = function copy(items, displayName, instance) { | ||
return new Injector(items, this._sheetManager, this._state, this, this.displayName + '.' + displayName, instance); | ||
Injector.prototype.copy = function copy(items, displayName, instance, aliases) { | ||
return new Injector(items, this._sheetManager, this._state, this, this.displayName + '.' + displayName, instance, aliases); | ||
}; | ||
@@ -426,2 +434,8 @@ | ||
if (isAtomic) { | ||
if (parentContext !== undefined) { | ||
newEl = parentContext.alias(el); | ||
if (newEl === null) return null; | ||
if (newEl !== undefined) el = newEl; | ||
} | ||
if (el.__lom === undefined) { | ||
@@ -501,16 +515,6 @@ el.__lom = atomize(el); | ||
var parentInjector = props.__lom_ctx || rootInjector; | ||
var render = parentInjector._cache.get(cns.render); | ||
if (render === null) { | ||
_this._el = null; | ||
_this._keys = undefined; | ||
_this._render = undefined; | ||
} else { | ||
_this._render = render === undefined ? cns.render : render; | ||
var injectorName = cns.displayName + (cns.instance ? '[' + cns.instance + ']' : ''); | ||
_this._injector = parentInjector.copy(_this._render.provides, injectorName, cns.instance); | ||
cns.instance++; | ||
} | ||
_this._render = cns.render; | ||
var injectorName = cns.displayName + (cns.instance ? '[' + cns.instance + ']' : ''); | ||
_this._injector = parentInjector.copy(undefined, injectorName, cns.instance, _this._render.aliases); | ||
cns.instance++; | ||
return _this; | ||
@@ -589,6 +593,2 @@ } | ||
return function reactWrapper(render) { | ||
if (render.__lom !== undefined) { | ||
return render.__lom; | ||
} | ||
var WrappedComponent = function WrappedComponent(props, context) { | ||
@@ -623,6 +623,6 @@ AtomizedComponent.call(this, props, context); | ||
function provideMap(item) { | ||
return item instanceof Array ? "[" + dn(item[0]) + ", " + dn(item[1]) + "]" : dn(item); | ||
return "[" + dn(item[0]) + ", " + dn(item[1]) + "]"; | ||
} | ||
function cloneComponent(fn, items, name) { | ||
function cloneComponent(fn, aliases, name) { | ||
var cloned = function cloned() { | ||
@@ -651,4 +651,5 @@ switch (arguments.length) { | ||
cloned.deps = fn.deps; | ||
cloned.provides = items; | ||
cloned.displayName = name || "cloneComponent(" + dn(fn) + ", [" + items.map(provideMap).join(', ') + "])"; | ||
cloned._r = fn._r; | ||
cloned.aliases = aliases !== undefined ? new Map(aliases) : undefined; | ||
cloned.displayName = name || "cloneComponent(" + dn(fn) + ", [" + aliases.map(provideMap).join(', ') + "])"; | ||
return cloned; | ||
@@ -655,0 +656,0 @@ } |
@@ -130,5 +130,6 @@ (function (global, factory) { | ||
var Injector = function () { | ||
function Injector(items, sheetProcessor, state, parent, displayName, instance) { | ||
function Injector(items, sheetProcessor, state, parent, displayName, instance, aliases) { | ||
this._resolved = false; | ||
this._listeners = undefined; | ||
this._aliases = aliases; | ||
this._instance = instance || 0; | ||
@@ -163,3 +164,5 @@ this._state = state || null; | ||
Injector.prototype.value = function value(key) { | ||
Injector.prototype.value = function value(rawKey) { | ||
var key = this._aliases === undefined ? rawKey : this._aliases.get(rawKey) || rawKey; | ||
var value = this._cache.get(key); | ||
@@ -275,3 +278,8 @@ | ||
Injector.prototype.alias = function alias(key) { | ||
return this._cache.get(key) || key; | ||
if (this._aliases === undefined) return key; | ||
var newKey = this._aliases.get(key); | ||
if (newKey === undefined) return key; | ||
return newKey; | ||
}; | ||
@@ -331,4 +339,4 @@ | ||
Injector.prototype.copy = function copy(items, displayName, instance) { | ||
return new Injector(items, this._sheetManager, this._state, this, this.displayName + '.' + displayName, instance); | ||
Injector.prototype.copy = function copy(items, displayName, instance, aliases) { | ||
return new Injector(items, this._sheetManager, this._state, this, this.displayName + '.' + displayName, instance, aliases); | ||
}; | ||
@@ -426,2 +434,8 @@ | ||
if (isAtomic) { | ||
if (parentContext !== undefined) { | ||
newEl = parentContext.alias(el); | ||
if (newEl === null) return null; | ||
if (newEl !== undefined) el = newEl; | ||
} | ||
if (el.__lom === undefined) { | ||
@@ -501,16 +515,6 @@ el.__lom = atomize(el); | ||
var parentInjector = props.__lom_ctx || rootInjector; | ||
var render = parentInjector._cache.get(cns.render); | ||
if (render === null) { | ||
_this._el = null; | ||
_this._keys = undefined; | ||
_this._render = undefined; | ||
} else { | ||
_this._render = render === undefined ? cns.render : render; | ||
var injectorName = cns.displayName + (cns.instance ? '[' + cns.instance + ']' : ''); | ||
_this._injector = parentInjector.copy(_this._render.provides, injectorName, cns.instance); | ||
cns.instance++; | ||
} | ||
_this._render = cns.render; | ||
var injectorName = cns.displayName + (cns.instance ? '[' + cns.instance + ']' : ''); | ||
_this._injector = parentInjector.copy(undefined, injectorName, cns.instance, _this._render.aliases); | ||
cns.instance++; | ||
return _this; | ||
@@ -589,6 +593,2 @@ } | ||
return function reactWrapper(render) { | ||
if (render.__lom !== undefined) { | ||
return render.__lom; | ||
} | ||
var WrappedComponent = function WrappedComponent(props, context) { | ||
@@ -623,6 +623,6 @@ AtomizedComponent.call(this, props, context); | ||
function provideMap(item) { | ||
return item instanceof Array ? "[" + dn(item[0]) + ", " + dn(item[1]) + "]" : dn(item); | ||
return "[" + dn(item[0]) + ", " + dn(item[1]) + "]"; | ||
} | ||
function cloneComponent(fn, items, name) { | ||
function cloneComponent(fn, aliases, name) { | ||
var cloned = function cloned() { | ||
@@ -651,4 +651,5 @@ switch (arguments.length) { | ||
cloned.deps = fn.deps; | ||
cloned.provides = items; | ||
cloned.displayName = name || "cloneComponent(" + dn(fn) + ", [" + items.map(provideMap).join(', ') + "])"; | ||
cloned._r = fn._r; | ||
cloned.aliases = aliases !== undefined ? new Map(aliases) : undefined; | ||
cloned.displayName = name || "cloneComponent(" + dn(fn) + ", [" + aliases.map(provideMap).join(', ') + "])"; | ||
return cloned; | ||
@@ -655,0 +656,0 @@ } |
{ | ||
"name": "reactive-di", | ||
"version": "4.0.11", | ||
"version": "4.0.12", | ||
"description": "Reactive dependency injection", | ||
@@ -5,0 +5,0 @@ "publishConfig": { |
@@ -20,9 +20,7 @@ // @flow | ||
function provideMap(item: IProvideItem): string { | ||
return item instanceof Array | ||
? `[${dn(item[0])}, ${dn(item[1])}]` | ||
: dn(item) | ||
function provideMap(item: [Function, Function]): string { | ||
return `[${dn(item[0])}, ${dn(item[1])}]` | ||
} | ||
export default function cloneComponent<V: Function>(fn: V, items: IProvideItem[], name?: string): V { | ||
export default function cloneComponent<V: Function>(fn: V, aliases: [Function, Function][], name?: string): V { | ||
const cloned = function () { | ||
@@ -39,5 +37,6 @@ switch (arguments.length) { | ||
cloned.deps = fn.deps | ||
cloned.provides = items | ||
cloned.displayName = name || `cloneComponent(${dn(fn)}, [${items.map(provideMap).join(', ')}])` | ||
cloned._r = fn._r | ||
cloned.aliases = aliases !== undefined ? new Map(aliases) : undefined | ||
cloned.displayName = name || `cloneComponent(${dn(fn)}, [${aliases.map(provideMap).join(', ')}])` | ||
return (cloned: any) | ||
} |
@@ -20,3 +20,3 @@ // @flow | ||
onError?: IFromError<IElement>; | ||
provides?: IProvideItem[]; | ||
aliases?: Map<Function, Function>; | ||
} | ||
@@ -65,2 +65,8 @@ | ||
if (isAtomic) { | ||
if (parentContext !== undefined) { | ||
newEl = parentContext.alias(el) | ||
if (newEl === null) return null | ||
if (newEl !== undefined) el = newEl | ||
} | ||
if (el.__lom === undefined) { | ||
@@ -138,19 +144,11 @@ el.__lom = atomize(el) | ||
const parentInjector = props.__lom_ctx || rootInjector | ||
const render = parentInjector._cache.get(cns.render) | ||
if (render === null) { | ||
this._el = null | ||
this._keys = (undefined: any) | ||
this._render = (undefined: any) | ||
} else { | ||
this._render = render === undefined ? cns.render : render | ||
const injectorName = cns.displayName + (cns.instance ? ('[' + cns.instance + ']') : '') | ||
this._injector = parentInjector.copy( | ||
this._render.provides, | ||
injectorName, | ||
cns.instance | ||
) | ||
cns.instance++ | ||
} | ||
this._render = cns.render | ||
const injectorName = cns.displayName + (cns.instance ? ('[' + cns.instance + ']') : '') | ||
this._injector = parentInjector.copy( | ||
undefined, | ||
injectorName, | ||
cns.instance, | ||
this._render.aliases | ||
) | ||
cns.instance++ | ||
} | ||
@@ -227,6 +225,2 @@ | ||
): Class<IReactComponent<IElement>> { | ||
if (render.__lom !== undefined) { | ||
return render.__lom | ||
} | ||
const WrappedComponent = function(props: IPropsWithContext, context?: Object) { | ||
@@ -233,0 +227,0 @@ AtomizedComponent.call(this, props, context) |
@@ -84,2 +84,3 @@ // @flow | ||
_cache: Map<Function, any> | ||
_aliases: Map<Function, Function> | void | ||
_instance: number | ||
@@ -96,4 +97,6 @@ | ||
displayName?: string, | ||
instance?: number | ||
instance?: number, | ||
aliases?: Map<Function, Function> | ||
) { | ||
this._aliases = aliases | ||
this._instance = instance || 0 | ||
@@ -127,3 +130,4 @@ this._state = state || null | ||
value<V>(key: Function): V { | ||
value<V>(rawKey: Function): V { | ||
const key = this._aliases === undefined ? rawKey : (this._aliases.get(rawKey) || rawKey) | ||
let value = this._cache.get(key) | ||
@@ -200,4 +204,8 @@ if (value === undefined) { | ||
alias(key: Function) { | ||
return this._cache.get(key) || key | ||
alias(key: Function): ?Function { | ||
if (this._aliases === undefined) return key | ||
const newKey = this._aliases.get(key) | ||
if (newKey === undefined) return key | ||
return newKey | ||
} | ||
@@ -234,3 +242,3 @@ | ||
copy(items?: IProvideItem[], displayName: string, instance?: number): Injector { | ||
copy(items?: IProvideItem[], displayName: string, instance?: number, aliases?: Map<Function, Function>): Injector { | ||
return new Injector( | ||
@@ -242,3 +250,4 @@ items, | ||
this.displayName + '.' + displayName, | ||
instance | ||
instance, | ||
aliases | ||
) | ||
@@ -245,0 +254,0 @@ } |
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
182632
2000