reactive-di
Advanced tools
Comparing version 7.0.0 to 7.0.1
@@ -5,2 +5,7 @@ # Change Log | ||
<a name="7.0.1"></a> | ||
## [7.0.1](https://github.com/zerkalica/reactive-di/compare/v7.0.0...v7.0.1) (2018-03-15) | ||
<a name="7.0.0"></a> | ||
@@ -7,0 +12,0 @@ # [7.0.0](https://github.com/zerkalica/reactive-di/compare/v6.1.0...v7.0.0) (2018-03-01) |
@@ -0,1 +1,3 @@ | ||
import { createConnect, AtomizedComponent } from 'urc'; | ||
function _inheritsLoose(subClass, superClass) { | ||
@@ -7,10 +9,2 @@ subClass.prototype = Object.create(superClass.prototype); | ||
function _assertThisInitialized(self) { | ||
if (self === void 0) { | ||
throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); | ||
} | ||
return self; | ||
} | ||
var rdiInst = Symbol('rdi_inst'); | ||
@@ -30,3 +24,3 @@ var rdiProp = Symbol('rdi_prop'); | ||
function () { | ||
function Injector(aliases, sheetManager, state, displayName, instance, cache, flags) { | ||
function Injector(contextAliases, sheetManager, state, displayName, instance, cache, flags) { | ||
this.id = ''; | ||
@@ -49,5 +43,5 @@ this.props = undefined; | ||
if (aliases !== undefined) { | ||
for (var i = 0; i < aliases.length; i++) { | ||
var item = aliases[i]; | ||
if (contextAliases !== undefined) { | ||
for (var i = 0; i < contextAliases.length; i++) { | ||
var item = contextAliases[i]; | ||
@@ -223,13 +217,9 @@ if (item instanceof Array) { | ||
_proto.invokeWithProps = function invokeWithProps(key, props, propsChanged) { | ||
_proto.getContext = function getContext(key, props) { | ||
var deps = key.deps || (key._r === undefined ? undefined : key._r[1]); | ||
if (deps === undefined) { | ||
return key(props); | ||
} | ||
if (deps === undefined) return undefined; | ||
var a = this.resolve(deps); | ||
var listeners = this._listeners; | ||
if (propsChanged === true && listeners !== undefined) { | ||
if (props !== undefined && listeners !== undefined) { | ||
for (var i = 0; i < listeners.length; i++) { | ||
@@ -242,35 +232,7 @@ var listener = listeners[i]; | ||
this._resolved = true; | ||
switch (a.length) { | ||
case 0: | ||
return key(props); | ||
case 1: | ||
return key(props, a[0]); | ||
case 2: | ||
return key(props, a[0], a[1]); | ||
case 3: | ||
return key(props, a[0], a[1], a[2]); | ||
case 4: | ||
return key(props, a[0], a[1], a[2], a[3]); | ||
case 5: | ||
return key(props, a[0], a[1], a[2], a[3], a[4]); | ||
case 6: | ||
return key(props, a[0], a[1], a[2], a[3], a[4], a[5]); | ||
case 7: | ||
return key(props, a[0], a[1], a[2], a[3], a[4], a[5], a[6]); | ||
default: | ||
return key.apply(void 0, [props].concat(a)); | ||
} | ||
return a[0]; | ||
}; | ||
_proto.copy = function copy(flags) { | ||
return new Injector(flags.aliases, null, this._state, flags.displayName, flags.instance, Object.create(this._cache), flags); | ||
return new Injector(flags.contextAliases, null, this._state, flags.displayName, flags.instance, Object.create(this._cache), flags); | ||
}; | ||
@@ -328,11 +290,3 @@ | ||
function setFunctionName(fn, name) { | ||
Object.defineProperty(fn, 'name', { | ||
value: name, | ||
writable: false | ||
}); | ||
fn.displayName = name; | ||
} | ||
function createReactWrapper(BaseComponent, ErrorComponent, Reaction, rootInjector, isFullEqual) { | ||
function createReactWrapper(BaseComponent, renderError, ReactAtom, rootInjector) { | ||
if (rootInjector === void 0) { | ||
@@ -342,140 +296,63 @@ rootInjector = new Injector(); | ||
if (isFullEqual === void 0) { | ||
isFullEqual = false; | ||
} | ||
var AtomizedComponent = | ||
var MixinComponent = | ||
/*#__PURE__*/ | ||
function (_BaseComponent) { | ||
_inheritsLoose(AtomizedComponent, _BaseComponent); | ||
function (_AtomizedComponent) { | ||
_inheritsLoose(MixinComponent, _AtomizedComponent); | ||
function AtomizedComponent(props, reactContext) { | ||
var _this; | ||
_this = _BaseComponent.call(this, props, reactContext) || this; | ||
_this._lastData = null; | ||
var injector = rootInjector; | ||
var cns = _this.constructor; | ||
var name = cns.displayName; | ||
if (props) { | ||
if (props.__lom_ctx !== undefined) injector = props.__lom_ctx; | ||
if (props.id) name = props.id; | ||
} | ||
_this._render = cns.render; | ||
_this._injector = injector.copy(cns); | ||
_this._injector.id = name; | ||
_this._injector.props = props; | ||
cns.instance++; | ||
_this._reaction = new Reaction(name, _assertThisInitialized(_this)); | ||
return _this; | ||
function MixinComponent() { | ||
return _AtomizedComponent.apply(this, arguments) || this; | ||
} | ||
var _proto = AtomizedComponent.prototype; | ||
var _proto = MixinComponent.prototype; | ||
_proto.toString = function toString() { | ||
return this._injector.toString(); | ||
}; // get displayName() { | ||
// return this.toString() | ||
// } | ||
// | ||
_proto.componentWillMount = function componentWillMount() { | ||
_AtomizedComponent.prototype.componentWillMount.call(this); | ||
var cns = this.constructor; | ||
_proto.shouldComponentUpdate = function shouldComponentUpdate(props) { | ||
var oldProps = this.props; | ||
this._injector.props = props; | ||
var count = 0; | ||
for (var k in oldProps) { | ||
count++; | ||
if (oldProps[k] !== props[k]) { | ||
this._reaction.reset(); | ||
return true; | ||
} | ||
if (cns.instance === undefined) { | ||
cns.instance = 0; | ||
cns.isDynamic = false; | ||
} | ||
for (var _k in props) { | ||
count--; | ||
if (oldProps[_k] !== props[_k]) { | ||
this._reaction.reset(); | ||
return true; | ||
} | ||
} | ||
if (count !== 0) { | ||
this._reaction.reset(); | ||
return true; | ||
} | ||
return false; | ||
cns.instance++; | ||
var injector = rootInjector; | ||
var props = this.props; | ||
if (props && props.__lom_ctx !== undefined) injector = props.__lom_ctx; | ||
this._injector = injector.copy(cns); | ||
this._injector.id = cns.displayName; | ||
this._injector.props = props; | ||
}; | ||
_proto.componentWillUnmount = function componentWillUnmount() { | ||
this._reaction.destructor(); | ||
this.constructor.instance--; | ||
this.props = undefined; | ||
this._lastData = null; | ||
this._injector.destructor(); | ||
if (this._render !== undefined) { | ||
this.constructor.instance--; | ||
this._injector.destructor(); | ||
this._injector = undefined; | ||
} | ||
_AtomizedComponent.prototype.componentWillUnmount.call(this); | ||
}; | ||
_proto.value = function value(propsChanged) { | ||
var data = null; | ||
var prevContext = Injector.parentContext; | ||
var injector = Injector.parentContext = this._injector; | ||
_proto.__value = function __value(isPropsChanged) { | ||
var oldInjector = Injector.parentContext; | ||
Injector.parentContext = this._injector; | ||
try { | ||
data = injector.invokeWithProps(this._render, this.props, propsChanged); | ||
this._lastData = data; | ||
} catch (error) { | ||
data = injector.invokeWithProps(this._render.onError || ErrorComponent, { | ||
error: error, | ||
children: this._lastData | ||
}); | ||
} | ||
var value = _AtomizedComponent.prototype.__value.call(this, isPropsChanged); | ||
Injector.parentContext = prevContext; | ||
return data; | ||
Injector.parentContext = oldInjector; | ||
return value; | ||
}; | ||
_proto.render = function render() { | ||
return this._reaction.value(); | ||
_proto._getContext = function _getContext(key, propsChanged) { | ||
return this._injector.getContext(key, propsChanged ? this.props : undefined); | ||
}; | ||
return AtomizedComponent; | ||
}(BaseComponent); | ||
return MixinComponent; | ||
}(AtomizedComponent); | ||
AtomizedComponent.isFullEqual = isFullEqual; | ||
var names = new Map(); | ||
return function reactWrapper(render) { | ||
var WrappedComponent = function WrappedComponent(props, context) { | ||
AtomizedComponent.call(this, props, context); | ||
}; | ||
WrappedComponent.instance = 0; | ||
WrappedComponent.render = render; | ||
WrappedComponent.isFullEqual = render.isFullEqual || isFullEqual; | ||
WrappedComponent.isDynamic = false; | ||
WrappedComponent.aliases = render.aliases; | ||
WrappedComponent.prototype = Object.create(AtomizedComponent.prototype); | ||
WrappedComponent.prototype.constructor = WrappedComponent; | ||
var name = render.displayName || render.name; | ||
var id = names.get(name) || 0; | ||
names.set(name, id + 1); | ||
if (id > 0) name = name + "_" + id; | ||
setFunctionName(WrappedComponent, name); | ||
return WrappedComponent; | ||
}; | ||
return createConnect({ | ||
ReactAtom: ReactAtom, | ||
renderError: renderError, | ||
BaseComponent: BaseComponent, | ||
MixinComponent: MixinComponent | ||
}); | ||
} | ||
@@ -625,3 +502,3 @@ | ||
function cloneComponent(fn, aliases, name) { | ||
function cloneComponent(fn, contextAliases, name) { | ||
var cloned = function cloned() { | ||
@@ -653,4 +530,4 @@ var a = arguments; | ||
cloned._r = fn._r; | ||
cloned.aliases = fn.aliases ? fn.aliases.concat(aliases) : aliases; | ||
cloned.displayName = name || "cloneComponent(" + dn(fn) + ", [" + aliases.map(provideMap).join(', ') + "])"; | ||
cloned.contextAliases = fn.contextAliases ? fn.contextAliases.concat(contextAliases) : contextAliases; | ||
cloned.displayName = name || "cloneComponent(" + dn(fn) + ", [" + contextAliases.map(provideMap).join(', ') + "])"; | ||
return cloned; | ||
@@ -667,60 +544,2 @@ } | ||
function createMobxReaction(Reaction) { | ||
return ( | ||
/*#__PURE__*/ | ||
function () { | ||
function RdiMobxReaction(name, host) { | ||
var _this = this; | ||
this._cache = undefined; | ||
this._host = host; | ||
this._track = function () { | ||
return _this.__track(); | ||
}; | ||
this._reaction = new Reaction(name, function () { | ||
return _this._onInvalidate(); | ||
}); | ||
} | ||
var _proto = RdiMobxReaction.prototype; | ||
_proto._onInvalidate = function _onInvalidate() { | ||
this._cache = undefined; | ||
this.value(); | ||
this._host.forceUpdate(); | ||
}; | ||
_proto.__track = function __track() { | ||
this._cache = this._host.value(); | ||
}; | ||
_proto.reset = function reset() { | ||
this._cache = undefined; | ||
}; | ||
_proto.value = function value() { | ||
if (this._cache === undefined) { | ||
this._reaction.track(this._track); | ||
} | ||
return this._cache; | ||
}; | ||
_proto.destructor = function destructor() { | ||
this._reaction.dispose(); | ||
this._reaction = undefined; | ||
this._host = undefined; | ||
this._cache = undefined; | ||
this._track = undefined; | ||
}; | ||
return RdiMobxReaction; | ||
}() | ||
); | ||
} | ||
var subRulesId = Symbol('rdi_sub_rules'); | ||
@@ -968,3 +787,3 @@ var nameId = Symbol('rdi_theme_name'); | ||
export { createReactWrapper, createCreateElement, Injector, cloneComponent, props, createMobxReaction, theme, JssSheetManager }; | ||
export { createReactWrapper, createCreateElement, Injector, cloneComponent, props, theme, JssSheetManager }; | ||
//# sourceMappingURL=reactive-di.es.js.map |
@@ -5,2 +5,4 @@ 'use strict'; | ||
var urc = require('urc'); | ||
function _inheritsLoose(subClass, superClass) { | ||
@@ -12,10 +14,2 @@ subClass.prototype = Object.create(superClass.prototype); | ||
function _assertThisInitialized(self) { | ||
if (self === void 0) { | ||
throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); | ||
} | ||
return self; | ||
} | ||
var rdiInst = Symbol('rdi_inst'); | ||
@@ -35,3 +29,3 @@ var rdiProp = Symbol('rdi_prop'); | ||
function () { | ||
function Injector(aliases, sheetManager, state, displayName, instance, cache, flags) { | ||
function Injector(contextAliases, sheetManager, state, displayName, instance, cache, flags) { | ||
this.id = ''; | ||
@@ -54,5 +48,5 @@ this.props = undefined; | ||
if (aliases !== undefined) { | ||
for (var i = 0; i < aliases.length; i++) { | ||
var item = aliases[i]; | ||
if (contextAliases !== undefined) { | ||
for (var i = 0; i < contextAliases.length; i++) { | ||
var item = contextAliases[i]; | ||
@@ -228,13 +222,9 @@ if (item instanceof Array) { | ||
_proto.invokeWithProps = function invokeWithProps(key, props, propsChanged) { | ||
_proto.getContext = function getContext(key, props) { | ||
var deps = key.deps || (key._r === undefined ? undefined : key._r[1]); | ||
if (deps === undefined) { | ||
return key(props); | ||
} | ||
if (deps === undefined) return undefined; | ||
var a = this.resolve(deps); | ||
var listeners = this._listeners; | ||
if (propsChanged === true && listeners !== undefined) { | ||
if (props !== undefined && listeners !== undefined) { | ||
for (var i = 0; i < listeners.length; i++) { | ||
@@ -247,35 +237,7 @@ var listener = listeners[i]; | ||
this._resolved = true; | ||
switch (a.length) { | ||
case 0: | ||
return key(props); | ||
case 1: | ||
return key(props, a[0]); | ||
case 2: | ||
return key(props, a[0], a[1]); | ||
case 3: | ||
return key(props, a[0], a[1], a[2]); | ||
case 4: | ||
return key(props, a[0], a[1], a[2], a[3]); | ||
case 5: | ||
return key(props, a[0], a[1], a[2], a[3], a[4]); | ||
case 6: | ||
return key(props, a[0], a[1], a[2], a[3], a[4], a[5]); | ||
case 7: | ||
return key(props, a[0], a[1], a[2], a[3], a[4], a[5], a[6]); | ||
default: | ||
return key.apply(void 0, [props].concat(a)); | ||
} | ||
return a[0]; | ||
}; | ||
_proto.copy = function copy(flags) { | ||
return new Injector(flags.aliases, null, this._state, flags.displayName, flags.instance, Object.create(this._cache), flags); | ||
return new Injector(flags.contextAliases, null, this._state, flags.displayName, flags.instance, Object.create(this._cache), flags); | ||
}; | ||
@@ -333,11 +295,3 @@ | ||
function setFunctionName(fn, name) { | ||
Object.defineProperty(fn, 'name', { | ||
value: name, | ||
writable: false | ||
}); | ||
fn.displayName = name; | ||
} | ||
function createReactWrapper(BaseComponent, ErrorComponent, Reaction, rootInjector, isFullEqual) { | ||
function createReactWrapper(BaseComponent, renderError, ReactAtom, rootInjector) { | ||
if (rootInjector === void 0) { | ||
@@ -347,140 +301,63 @@ rootInjector = new Injector(); | ||
if (isFullEqual === void 0) { | ||
isFullEqual = false; | ||
} | ||
var AtomizedComponent = | ||
var MixinComponent = | ||
/*#__PURE__*/ | ||
function (_BaseComponent) { | ||
_inheritsLoose(AtomizedComponent, _BaseComponent); | ||
function (_AtomizedComponent) { | ||
_inheritsLoose(MixinComponent, _AtomizedComponent); | ||
function AtomizedComponent(props, reactContext) { | ||
var _this; | ||
_this = _BaseComponent.call(this, props, reactContext) || this; | ||
_this._lastData = null; | ||
var injector = rootInjector; | ||
var cns = _this.constructor; | ||
var name = cns.displayName; | ||
if (props) { | ||
if (props.__lom_ctx !== undefined) injector = props.__lom_ctx; | ||
if (props.id) name = props.id; | ||
} | ||
_this._render = cns.render; | ||
_this._injector = injector.copy(cns); | ||
_this._injector.id = name; | ||
_this._injector.props = props; | ||
cns.instance++; | ||
_this._reaction = new Reaction(name, _assertThisInitialized(_this)); | ||
return _this; | ||
function MixinComponent() { | ||
return _AtomizedComponent.apply(this, arguments) || this; | ||
} | ||
var _proto = AtomizedComponent.prototype; | ||
var _proto = MixinComponent.prototype; | ||
_proto.toString = function toString() { | ||
return this._injector.toString(); | ||
}; // get displayName() { | ||
// return this.toString() | ||
// } | ||
// | ||
_proto.componentWillMount = function componentWillMount() { | ||
_AtomizedComponent.prototype.componentWillMount.call(this); | ||
var cns = this.constructor; | ||
_proto.shouldComponentUpdate = function shouldComponentUpdate(props) { | ||
var oldProps = this.props; | ||
this._injector.props = props; | ||
var count = 0; | ||
for (var k in oldProps) { | ||
count++; | ||
if (oldProps[k] !== props[k]) { | ||
this._reaction.reset(); | ||
return true; | ||
} | ||
if (cns.instance === undefined) { | ||
cns.instance = 0; | ||
cns.isDynamic = false; | ||
} | ||
for (var _k in props) { | ||
count--; | ||
if (oldProps[_k] !== props[_k]) { | ||
this._reaction.reset(); | ||
return true; | ||
} | ||
} | ||
if (count !== 0) { | ||
this._reaction.reset(); | ||
return true; | ||
} | ||
return false; | ||
cns.instance++; | ||
var injector = rootInjector; | ||
var props = this.props; | ||
if (props && props.__lom_ctx !== undefined) injector = props.__lom_ctx; | ||
this._injector = injector.copy(cns); | ||
this._injector.id = cns.displayName; | ||
this._injector.props = props; | ||
}; | ||
_proto.componentWillUnmount = function componentWillUnmount() { | ||
this._reaction.destructor(); | ||
this.constructor.instance--; | ||
this.props = undefined; | ||
this._lastData = null; | ||
this._injector.destructor(); | ||
if (this._render !== undefined) { | ||
this.constructor.instance--; | ||
this._injector.destructor(); | ||
this._injector = undefined; | ||
} | ||
_AtomizedComponent.prototype.componentWillUnmount.call(this); | ||
}; | ||
_proto.value = function value(propsChanged) { | ||
var data = null; | ||
var prevContext = Injector.parentContext; | ||
var injector = Injector.parentContext = this._injector; | ||
_proto.__value = function __value(isPropsChanged) { | ||
var oldInjector = Injector.parentContext; | ||
Injector.parentContext = this._injector; | ||
try { | ||
data = injector.invokeWithProps(this._render, this.props, propsChanged); | ||
this._lastData = data; | ||
} catch (error) { | ||
data = injector.invokeWithProps(this._render.onError || ErrorComponent, { | ||
error: error, | ||
children: this._lastData | ||
}); | ||
} | ||
var value = _AtomizedComponent.prototype.__value.call(this, isPropsChanged); | ||
Injector.parentContext = prevContext; | ||
return data; | ||
Injector.parentContext = oldInjector; | ||
return value; | ||
}; | ||
_proto.render = function render() { | ||
return this._reaction.value(); | ||
_proto._getContext = function _getContext(key, propsChanged) { | ||
return this._injector.getContext(key, propsChanged ? this.props : undefined); | ||
}; | ||
return AtomizedComponent; | ||
}(BaseComponent); | ||
return MixinComponent; | ||
}(urc.AtomizedComponent); | ||
AtomizedComponent.isFullEqual = isFullEqual; | ||
var names = new Map(); | ||
return function reactWrapper(render) { | ||
var WrappedComponent = function WrappedComponent(props, context) { | ||
AtomizedComponent.call(this, props, context); | ||
}; | ||
WrappedComponent.instance = 0; | ||
WrappedComponent.render = render; | ||
WrappedComponent.isFullEqual = render.isFullEqual || isFullEqual; | ||
WrappedComponent.isDynamic = false; | ||
WrappedComponent.aliases = render.aliases; | ||
WrappedComponent.prototype = Object.create(AtomizedComponent.prototype); | ||
WrappedComponent.prototype.constructor = WrappedComponent; | ||
var name = render.displayName || render.name; | ||
var id = names.get(name) || 0; | ||
names.set(name, id + 1); | ||
if (id > 0) name = name + "_" + id; | ||
setFunctionName(WrappedComponent, name); | ||
return WrappedComponent; | ||
}; | ||
return urc.createConnect({ | ||
ReactAtom: ReactAtom, | ||
renderError: renderError, | ||
BaseComponent: BaseComponent, | ||
MixinComponent: MixinComponent | ||
}); | ||
} | ||
@@ -630,3 +507,3 @@ | ||
function cloneComponent(fn, aliases, name) { | ||
function cloneComponent(fn, contextAliases, name) { | ||
var cloned = function cloned() { | ||
@@ -658,4 +535,4 @@ var a = arguments; | ||
cloned._r = fn._r; | ||
cloned.aliases = fn.aliases ? fn.aliases.concat(aliases) : aliases; | ||
cloned.displayName = name || "cloneComponent(" + dn(fn) + ", [" + aliases.map(provideMap).join(', ') + "])"; | ||
cloned.contextAliases = fn.contextAliases ? fn.contextAliases.concat(contextAliases) : contextAliases; | ||
cloned.displayName = name || "cloneComponent(" + dn(fn) + ", [" + contextAliases.map(provideMap).join(', ') + "])"; | ||
return cloned; | ||
@@ -672,60 +549,2 @@ } | ||
function createMobxReaction(Reaction) { | ||
return ( | ||
/*#__PURE__*/ | ||
function () { | ||
function RdiMobxReaction(name, host) { | ||
var _this = this; | ||
this._cache = undefined; | ||
this._host = host; | ||
this._track = function () { | ||
return _this.__track(); | ||
}; | ||
this._reaction = new Reaction(name, function () { | ||
return _this._onInvalidate(); | ||
}); | ||
} | ||
var _proto = RdiMobxReaction.prototype; | ||
_proto._onInvalidate = function _onInvalidate() { | ||
this._cache = undefined; | ||
this.value(); | ||
this._host.forceUpdate(); | ||
}; | ||
_proto.__track = function __track() { | ||
this._cache = this._host.value(); | ||
}; | ||
_proto.reset = function reset() { | ||
this._cache = undefined; | ||
}; | ||
_proto.value = function value() { | ||
if (this._cache === undefined) { | ||
this._reaction.track(this._track); | ||
} | ||
return this._cache; | ||
}; | ||
_proto.destructor = function destructor() { | ||
this._reaction.dispose(); | ||
this._reaction = undefined; | ||
this._host = undefined; | ||
this._cache = undefined; | ||
this._track = undefined; | ||
}; | ||
return RdiMobxReaction; | ||
}() | ||
); | ||
} | ||
var subRulesId = Symbol('rdi_sub_rules'); | ||
@@ -978,4 +797,3 @@ var nameId = Symbol('rdi_theme_name'); | ||
exports.props = props; | ||
exports.createMobxReaction = createMobxReaction; | ||
exports.theme = theme; | ||
exports.JssSheetManager = JssSheetManager; |
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
typeof define === 'function' && define.amd ? define(['exports'], factory) : | ||
(factory((global['reactive-di'] = {}))); | ||
}(this, (function (exports) { 'use strict'; | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('urc')) : | ||
typeof define === 'function' && define.amd ? define(['exports', 'urc'], factory) : | ||
(factory((global['reactive-di'] = {}),global.urc)); | ||
}(this, (function (exports,urc) { 'use strict'; | ||
@@ -13,10 +13,2 @@ function _inheritsLoose(subClass, superClass) { | ||
function _assertThisInitialized(self) { | ||
if (self === void 0) { | ||
throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); | ||
} | ||
return self; | ||
} | ||
var rdiInst = Symbol('rdi_inst'); | ||
@@ -36,3 +28,3 @@ var rdiProp = Symbol('rdi_prop'); | ||
function () { | ||
function Injector(aliases, sheetManager, state, displayName, instance, cache, flags) { | ||
function Injector(contextAliases, sheetManager, state, displayName, instance, cache, flags) { | ||
this.id = ''; | ||
@@ -55,5 +47,5 @@ this.props = undefined; | ||
if (aliases !== undefined) { | ||
for (var i = 0; i < aliases.length; i++) { | ||
var item = aliases[i]; | ||
if (contextAliases !== undefined) { | ||
for (var i = 0; i < contextAliases.length; i++) { | ||
var item = contextAliases[i]; | ||
@@ -229,13 +221,9 @@ if (item instanceof Array) { | ||
_proto.invokeWithProps = function invokeWithProps(key, props, propsChanged) { | ||
_proto.getContext = function getContext(key, props) { | ||
var deps = key.deps || (key._r === undefined ? undefined : key._r[1]); | ||
if (deps === undefined) { | ||
return key(props); | ||
} | ||
if (deps === undefined) return undefined; | ||
var a = this.resolve(deps); | ||
var listeners = this._listeners; | ||
if (propsChanged === true && listeners !== undefined) { | ||
if (props !== undefined && listeners !== undefined) { | ||
for (var i = 0; i < listeners.length; i++) { | ||
@@ -248,35 +236,7 @@ var listener = listeners[i]; | ||
this._resolved = true; | ||
switch (a.length) { | ||
case 0: | ||
return key(props); | ||
case 1: | ||
return key(props, a[0]); | ||
case 2: | ||
return key(props, a[0], a[1]); | ||
case 3: | ||
return key(props, a[0], a[1], a[2]); | ||
case 4: | ||
return key(props, a[0], a[1], a[2], a[3]); | ||
case 5: | ||
return key(props, a[0], a[1], a[2], a[3], a[4]); | ||
case 6: | ||
return key(props, a[0], a[1], a[2], a[3], a[4], a[5]); | ||
case 7: | ||
return key(props, a[0], a[1], a[2], a[3], a[4], a[5], a[6]); | ||
default: | ||
return key.apply(void 0, [props].concat(a)); | ||
} | ||
return a[0]; | ||
}; | ||
_proto.copy = function copy(flags) { | ||
return new Injector(flags.aliases, null, this._state, flags.displayName, flags.instance, Object.create(this._cache), flags); | ||
return new Injector(flags.contextAliases, null, this._state, flags.displayName, flags.instance, Object.create(this._cache), flags); | ||
}; | ||
@@ -334,11 +294,3 @@ | ||
function setFunctionName(fn, name) { | ||
Object.defineProperty(fn, 'name', { | ||
value: name, | ||
writable: false | ||
}); | ||
fn.displayName = name; | ||
} | ||
function createReactWrapper(BaseComponent, ErrorComponent, Reaction, rootInjector, isFullEqual) { | ||
function createReactWrapper(BaseComponent, renderError, ReactAtom, rootInjector) { | ||
if (rootInjector === void 0) { | ||
@@ -348,140 +300,63 @@ rootInjector = new Injector(); | ||
if (isFullEqual === void 0) { | ||
isFullEqual = false; | ||
} | ||
var AtomizedComponent = | ||
var MixinComponent = | ||
/*#__PURE__*/ | ||
function (_BaseComponent) { | ||
_inheritsLoose(AtomizedComponent, _BaseComponent); | ||
function (_AtomizedComponent) { | ||
_inheritsLoose(MixinComponent, _AtomizedComponent); | ||
function AtomizedComponent(props, reactContext) { | ||
var _this; | ||
_this = _BaseComponent.call(this, props, reactContext) || this; | ||
_this._lastData = null; | ||
var injector = rootInjector; | ||
var cns = _this.constructor; | ||
var name = cns.displayName; | ||
if (props) { | ||
if (props.__lom_ctx !== undefined) injector = props.__lom_ctx; | ||
if (props.id) name = props.id; | ||
} | ||
_this._render = cns.render; | ||
_this._injector = injector.copy(cns); | ||
_this._injector.id = name; | ||
_this._injector.props = props; | ||
cns.instance++; | ||
_this._reaction = new Reaction(name, _assertThisInitialized(_this)); | ||
return _this; | ||
function MixinComponent() { | ||
return _AtomizedComponent.apply(this, arguments) || this; | ||
} | ||
var _proto = AtomizedComponent.prototype; | ||
var _proto = MixinComponent.prototype; | ||
_proto.toString = function toString() { | ||
return this._injector.toString(); | ||
}; // get displayName() { | ||
// return this.toString() | ||
// } | ||
// | ||
_proto.componentWillMount = function componentWillMount() { | ||
_AtomizedComponent.prototype.componentWillMount.call(this); | ||
var cns = this.constructor; | ||
_proto.shouldComponentUpdate = function shouldComponentUpdate(props) { | ||
var oldProps = this.props; | ||
this._injector.props = props; | ||
var count = 0; | ||
for (var k in oldProps) { | ||
count++; | ||
if (oldProps[k] !== props[k]) { | ||
this._reaction.reset(); | ||
return true; | ||
} | ||
if (cns.instance === undefined) { | ||
cns.instance = 0; | ||
cns.isDynamic = false; | ||
} | ||
for (var _k in props) { | ||
count--; | ||
if (oldProps[_k] !== props[_k]) { | ||
this._reaction.reset(); | ||
return true; | ||
} | ||
} | ||
if (count !== 0) { | ||
this._reaction.reset(); | ||
return true; | ||
} | ||
return false; | ||
cns.instance++; | ||
var injector = rootInjector; | ||
var props = this.props; | ||
if (props && props.__lom_ctx !== undefined) injector = props.__lom_ctx; | ||
this._injector = injector.copy(cns); | ||
this._injector.id = cns.displayName; | ||
this._injector.props = props; | ||
}; | ||
_proto.componentWillUnmount = function componentWillUnmount() { | ||
this._reaction.destructor(); | ||
this.constructor.instance--; | ||
this.props = undefined; | ||
this._lastData = null; | ||
this._injector.destructor(); | ||
if (this._render !== undefined) { | ||
this.constructor.instance--; | ||
this._injector.destructor(); | ||
this._injector = undefined; | ||
} | ||
_AtomizedComponent.prototype.componentWillUnmount.call(this); | ||
}; | ||
_proto.value = function value(propsChanged) { | ||
var data = null; | ||
var prevContext = Injector.parentContext; | ||
var injector = Injector.parentContext = this._injector; | ||
_proto.__value = function __value(isPropsChanged) { | ||
var oldInjector = Injector.parentContext; | ||
Injector.parentContext = this._injector; | ||
try { | ||
data = injector.invokeWithProps(this._render, this.props, propsChanged); | ||
this._lastData = data; | ||
} catch (error) { | ||
data = injector.invokeWithProps(this._render.onError || ErrorComponent, { | ||
error: error, | ||
children: this._lastData | ||
}); | ||
} | ||
var value = _AtomizedComponent.prototype.__value.call(this, isPropsChanged); | ||
Injector.parentContext = prevContext; | ||
return data; | ||
Injector.parentContext = oldInjector; | ||
return value; | ||
}; | ||
_proto.render = function render() { | ||
return this._reaction.value(); | ||
_proto._getContext = function _getContext(key, propsChanged) { | ||
return this._injector.getContext(key, propsChanged ? this.props : undefined); | ||
}; | ||
return AtomizedComponent; | ||
}(BaseComponent); | ||
return MixinComponent; | ||
}(urc.AtomizedComponent); | ||
AtomizedComponent.isFullEqual = isFullEqual; | ||
var names = new Map(); | ||
return function reactWrapper(render) { | ||
var WrappedComponent = function WrappedComponent(props, context) { | ||
AtomizedComponent.call(this, props, context); | ||
}; | ||
WrappedComponent.instance = 0; | ||
WrappedComponent.render = render; | ||
WrappedComponent.isFullEqual = render.isFullEqual || isFullEqual; | ||
WrappedComponent.isDynamic = false; | ||
WrappedComponent.aliases = render.aliases; | ||
WrappedComponent.prototype = Object.create(AtomizedComponent.prototype); | ||
WrappedComponent.prototype.constructor = WrappedComponent; | ||
var name = render.displayName || render.name; | ||
var id = names.get(name) || 0; | ||
names.set(name, id + 1); | ||
if (id > 0) name = name + "_" + id; | ||
setFunctionName(WrappedComponent, name); | ||
return WrappedComponent; | ||
}; | ||
return urc.createConnect({ | ||
ReactAtom: ReactAtom, | ||
renderError: renderError, | ||
BaseComponent: BaseComponent, | ||
MixinComponent: MixinComponent | ||
}); | ||
} | ||
@@ -631,3 +506,3 @@ | ||
function cloneComponent(fn, aliases, name) { | ||
function cloneComponent(fn, contextAliases, name) { | ||
var cloned = function cloned() { | ||
@@ -659,4 +534,4 @@ var a = arguments; | ||
cloned._r = fn._r; | ||
cloned.aliases = fn.aliases ? fn.aliases.concat(aliases) : aliases; | ||
cloned.displayName = name || "cloneComponent(" + dn(fn) + ", [" + aliases.map(provideMap).join(', ') + "])"; | ||
cloned.contextAliases = fn.contextAliases ? fn.contextAliases.concat(contextAliases) : contextAliases; | ||
cloned.displayName = name || "cloneComponent(" + dn(fn) + ", [" + contextAliases.map(provideMap).join(', ') + "])"; | ||
return cloned; | ||
@@ -673,60 +548,2 @@ } | ||
function createMobxReaction(Reaction) { | ||
return ( | ||
/*#__PURE__*/ | ||
function () { | ||
function RdiMobxReaction(name, host) { | ||
var _this = this; | ||
this._cache = undefined; | ||
this._host = host; | ||
this._track = function () { | ||
return _this.__track(); | ||
}; | ||
this._reaction = new Reaction(name, function () { | ||
return _this._onInvalidate(); | ||
}); | ||
} | ||
var _proto = RdiMobxReaction.prototype; | ||
_proto._onInvalidate = function _onInvalidate() { | ||
this._cache = undefined; | ||
this.value(); | ||
this._host.forceUpdate(); | ||
}; | ||
_proto.__track = function __track() { | ||
this._cache = this._host.value(); | ||
}; | ||
_proto.reset = function reset() { | ||
this._cache = undefined; | ||
}; | ||
_proto.value = function value() { | ||
if (this._cache === undefined) { | ||
this._reaction.track(this._track); | ||
} | ||
return this._cache; | ||
}; | ||
_proto.destructor = function destructor() { | ||
this._reaction.dispose(); | ||
this._reaction = undefined; | ||
this._host = undefined; | ||
this._cache = undefined; | ||
this._track = undefined; | ||
}; | ||
return RdiMobxReaction; | ||
}() | ||
); | ||
} | ||
var subRulesId = Symbol('rdi_sub_rules'); | ||
@@ -979,3 +796,2 @@ var nameId = Symbol('rdi_theme_name'); | ||
exports.props = props; | ||
exports.createMobxReaction = createMobxReaction; | ||
exports.theme = theme; | ||
@@ -982,0 +798,0 @@ exports.JssSheetManager = JssSheetManager; |
{ | ||
"name": "reactive-di", | ||
"version": "7.0.0", | ||
"version": "7.0.1", | ||
"description": "Reactive dependency injection", | ||
@@ -68,3 +68,3 @@ "publishConfig": { | ||
"flow-bin": "^0.66.0", | ||
"lom_atom": "^4.0.0", | ||
"lom_atom": "^4.0.1", | ||
"mobx": "^3.5.1", | ||
@@ -81,3 +81,6 @@ "mocha": "^5.0.1", | ||
"uglify-es": "^3.3.9" | ||
}, | ||
"dependencies": { | ||
"urc": "^1.0.3" | ||
} | ||
} |
@@ -21,3 +21,3 @@ # Reactive DI [![Build Status](https://secure.travis-ci.org/zerkalica/reactive-di.png)](http://travis-ci.org/zerkalica/reactive-di) | ||
* [todomvc benchmark](http://mol.js.org/app/bench/#bench=https%3A%2F%2Fzerkalica.github.io%2Futb%2Fbenchmark%2F/sample=preact-lom_atom~preact-mobx~preact-raw~preact-reactive-di) | ||
* [fiddle](https://jsfiddle.net/zerkalica/jxo6hqf8/6/) example with loading and error handling demo. | ||
* [fiddle](https://jsfiddle.net/zerkalica/jxo6hqf8/9/) example with loading and error handling demo. | ||
@@ -24,0 +24,0 @@ ## TOC |
@@ -25,3 +25,3 @@ // @flow | ||
export default function cloneComponent<V: Function>(fn: V, aliases: IProvideItem[], name?: string): V { | ||
export default function cloneComponent<V: Function>(fn: V, contextAliases: IProvideItem[], name?: string): V { | ||
const cloned = function () { | ||
@@ -40,6 +40,6 @@ const a = arguments | ||
cloned._r = fn._r | ||
cloned.aliases = fn.aliases ? fn.aliases.concat(aliases) : aliases | ||
cloned.displayName = name || `cloneComponent(${dn(fn)}, [${aliases.map(provideMap).join(', ')}])` | ||
cloned.contextAliases = fn.contextAliases ? fn.contextAliases.concat(contextAliases) : contextAliases | ||
cloned.displayName = name || `cloneComponent(${dn(fn)}, [${contextAliases.map(provideMap).join(', ')}])` | ||
return (cloned: any) | ||
} |
// @flow | ||
import type {TypedPropertyDescriptor} from './interfaces' | ||
import type {IReaction} from './reactivity/interfaces' | ||
import {createConnect, AtomizedComponent} from 'urc' | ||
import type {IReactHost, IReactAtom, IRenderError, ErrorProps} from 'urc' | ||
import Injector from './Injector' | ||
import type {IAtomize, IFromError, IRenderFn, IReactComponent, IProvideItem, IArg, IPropsWithContext} from './interfaces' | ||
import type {IRenderFn} from './interfaces' | ||
function setFunctionName(fn: Function, name: string) { | ||
Object.defineProperty(fn, 'name', {value: name, writable: false}) | ||
fn.displayName = name | ||
} | ||
export default function createReactWrapper<IElement>( | ||
BaseComponent: Class<*>, | ||
ErrorComponent: IFromError<IElement>, | ||
Reaction: Class<IReaction<any>>, | ||
renderError: IRenderError<IElement, *>, | ||
ReactAtom: Class<IReactAtom<IElement>>, | ||
rootInjector?: Injector = new Injector(), | ||
isFullEqual?: boolean = false | ||
): IAtomize<IElement, *> { | ||
class AtomizedComponent<State> extends BaseComponent { | ||
props: IPropsWithContext | ||
static displayName: string | ||
) { | ||
class MixinComponent<Props: Object, State, Context> extends AtomizedComponent<Props, State, Context, IElement> { | ||
_injector: Injector | ||
static render: IRenderFn<IElement, State> | ||
static instance: number | ||
static isFullEqual = isFullEqual | ||
props: Props | ||
componentWillMount() { | ||
super.componentWillMount() | ||
const cns: Function = this.constructor | ||
if (cns.instance === undefined) { | ||
cns.instance = 0 | ||
cns.isDynamic = false | ||
} | ||
_render: IRenderFn<IElement, State> | ||
_reaction: IReaction<any> | ||
cns.instance++ | ||
constructor( | ||
props: IPropsWithContext, | ||
reactContext?: Object | ||
) { | ||
super(props, reactContext) | ||
let injector: Injector = rootInjector | ||
const cns = this.constructor | ||
let name = cns.displayName | ||
if (props) { | ||
if (props.__lom_ctx !== undefined) injector = props.__lom_ctx | ||
if (props.id) name = props.id | ||
} | ||
this._render = cns.render | ||
const props = this.props | ||
if (props && props.__lom_ctx !== undefined) injector = props.__lom_ctx | ||
this._injector = injector.copy(cns) | ||
this._injector.id = name | ||
this._injector.id = cns.displayName | ||
this._injector.props = props | ||
cns.instance++ | ||
this._reaction = new Reaction(name, this) | ||
} | ||
toString() { | ||
return this._injector.toString() | ||
} | ||
// get displayName() { | ||
// return this.toString() | ||
// } | ||
// | ||
shouldComponentUpdate(props: IPropsWithContext) { | ||
const oldProps = this.props | ||
this._injector.props = props | ||
let count = 0 | ||
for (let k in oldProps) { | ||
count++ | ||
if (oldProps[k] !== props[k]) { | ||
this._reaction.reset() | ||
return true | ||
} | ||
} | ||
for (let k in props) { | ||
count-- | ||
if (oldProps[k] !== props[k]) { | ||
this._reaction.reset() | ||
return true | ||
} | ||
} | ||
if (count !== 0) { | ||
this._reaction.reset() | ||
return true | ||
} | ||
return false | ||
} | ||
componentWillUnmount() { | ||
this._reaction.destructor() | ||
this.props = (undefined: any) | ||
this._lastData = null | ||
if (this._render !== undefined) { | ||
this.constructor.instance-- | ||
this._injector.destructor() | ||
this._injector = (undefined: any) | ||
} | ||
this.constructor.instance-- | ||
this._injector.destructor() | ||
super.componentWillUnmount() | ||
} | ||
_lastData: ?IElement = null | ||
value(propsChanged: boolean): ?IElement { | ||
let data: ?IElement = null | ||
const prevContext = Injector.parentContext | ||
const injector = Injector.parentContext = this._injector | ||
try { | ||
data = injector.invokeWithProps(this._render, this.props, propsChanged) | ||
this._lastData = data | ||
} catch (error) { | ||
data = injector.invokeWithProps(this._render.onError || ErrorComponent, {error, children: this._lastData}) | ||
} | ||
Injector.parentContext = prevContext | ||
return data | ||
__value(isPropsChanged: boolean) { | ||
const oldInjector = Injector.parentContext | ||
Injector.parentContext = this._injector | ||
const value = super.__value(isPropsChanged) | ||
Injector.parentContext = oldInjector | ||
return value | ||
} | ||
render() { | ||
return this._reaction.value() | ||
_getContext(key: Function, propsChanged: boolean): Context { | ||
return this._injector.getContext(key, propsChanged ? this.props : undefined) | ||
} | ||
} | ||
const names: Map<string, number> = new Map() | ||
return function reactWrapper<State>( | ||
render: IRenderFn<IElement, State> | ||
): Class<IReactComponent<IElement>> { | ||
const WrappedComponent = function(props: IPropsWithContext, context?: Object) { | ||
AtomizedComponent.call(this, props, context) | ||
} | ||
WrappedComponent.instance = 0 | ||
WrappedComponent.render = render | ||
WrappedComponent.isFullEqual = render.isFullEqual || isFullEqual | ||
WrappedComponent.isDynamic = false | ||
WrappedComponent.aliases = render.aliases | ||
WrappedComponent.prototype = Object.create(AtomizedComponent.prototype) | ||
WrappedComponent.prototype.constructor = WrappedComponent | ||
let name = render.displayName || render.name | ||
let id = names.get(name) || 0 | ||
names.set(name, id + 1) | ||
if (id > 0) name = `${name}_${id}` | ||
setFunctionName(WrappedComponent, name) | ||
return (WrappedComponent: any) | ||
} | ||
return ((createConnect({ | ||
ReactAtom, | ||
renderError, | ||
BaseComponent, | ||
MixinComponent | ||
}): any): IRenderFn<*, *>) | ||
} |
@@ -8,3 +8,2 @@ // @flow | ||
export {default as props} from './props' | ||
export {default as createMobxReaction} from './reactivity/createMobxReaction' | ||
export {default as theme} from './theming/theme' | ||
@@ -11,0 +10,0 @@ export {default as JssSheetManager} from './theming/JssSheetManager' |
@@ -26,3 +26,3 @@ // @flow | ||
isDynamic?: boolean; | ||
aliases?: IProvideItem[]; | ||
contextAliases?: IProvideItem[]; | ||
} | ||
@@ -47,3 +47,3 @@ export default class Injector { | ||
constructor( | ||
aliases?: IProvideItem[], | ||
contextAliases?: IProvideItem[], | ||
sheetManager?: ?ISheetManager, | ||
@@ -66,5 +66,5 @@ state?: IState, | ||
const map = this._cache = cache || (Object.create(null): Object) | ||
if (aliases !== undefined) { | ||
for (let i = 0; i < aliases.length; i++) { | ||
const item = aliases[i] | ||
if (contextAliases !== undefined) { | ||
for (let i = 0; i < contextAliases.length; i++) { | ||
const item = contextAliases[i] | ||
if (item instanceof Array) { | ||
@@ -202,10 +202,8 @@ const src: string | Function = item[0] | ||
invokeWithProps<V>(key: Function, props?: Object, propsChanged?: boolean): V { | ||
getContext<Context, Props>(key: Function, props?: Props): Context { | ||
const deps = key.deps || (key._r === undefined ? undefined : key._r[1]) | ||
if (deps === undefined) { | ||
return key(props) | ||
} | ||
if (deps === undefined) return (undefined: any) | ||
const a = this.resolve(deps) | ||
const listeners = this._listeners | ||
if (propsChanged === true && listeners !== undefined) { | ||
if (props !== undefined && listeners !== undefined) { | ||
for (let i = 0; i < listeners.length; i++) { | ||
@@ -217,13 +215,3 @@ const listener = listeners[i] | ||
this._resolved = true | ||
switch (a.length) { | ||
case 0: return key(props) | ||
case 1: return key(props, a[0]) | ||
case 2: return key(props, a[0], a[1]) | ||
case 3: return key(props, a[0], a[1], a[2]) | ||
case 4: return key(props, a[0], a[1], a[2], a[3]) | ||
case 5: return key(props, a[0], a[1], a[2], a[3], a[4]) | ||
case 6: return key(props, a[0], a[1], a[2], a[3], a[4], a[5]) | ||
case 7: return key(props, a[0], a[1], a[2], a[3], a[4], a[5], a[6]) | ||
default: return key(props, ...a) | ||
} | ||
return a[0] | ||
} | ||
@@ -233,3 +221,3 @@ | ||
return new Injector( | ||
flags.aliases, | ||
flags.contextAliases, | ||
null, | ||
@@ -236,0 +224,0 @@ this._state, |
@@ -37,4 +37,3 @@ // @flow | ||
deps?: IArg[]; | ||
onError?: IFromError<IElement>; | ||
aliases?: IProvideItem[]; | ||
contextAliases?: IProvideItem[]; | ||
} | ||
@@ -41,0 +40,0 @@ |
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
179641
1
24
2609
+ Addedurc@^1.0.3
+ Addedurc@1.0.8(transitive)