Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

reactive-di

Package Overview
Dependencies
Maintainers
1
Versions
134
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

reactive-di - npm Package Compare versions

Comparing version 4.0.0 to 4.0.1

5

CHANGELOG.md

@@ -5,3 +5,8 @@ # Change Log

<a name="4.0.1"></a>
## [4.0.1](https://github.com/zerkalica/reactive-di/compare/v4.0.0...v4.0.1) (2017-08-03)
<a name="4.0.0"></a>
# [4.0.0](https://github.com/zerkalica/reactive-di/compare/v3.2.0...v4.0.0) (2017-08-01)

140

dist/reactive-di.es.js

@@ -1,2 +0,2 @@

import { defaultContext, detached, mem, memkey } from 'lom_atom';
import { defaultContext, detached, memkey } from 'lom_atom';

@@ -39,3 +39,3 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {

var _class;
var _class2;

@@ -72,20 +72,34 @@ function _applyDecoratedDescriptor$1(target, property, decorators, descriptor, context) {

var chainCount = 0;
var FakeSheet = function () {
function FakeSheet() {
this.classes = {};
}
FakeSheet.prototype.update = function update(props) {
return this;
};
FakeSheet.prototype.attach = function attach() {
return this;
};
FakeSheet.prototype.detach = function detach() {
return this;
};
return FakeSheet;
}();
var defaultSheetProcessor = {
createStyleSheet: function createStyleSheet(cssProps) {
return {
attach: function attach() {
return this;
},
detach: function detach() {
return this;
},
classes: {}
};
return new FakeSheet();
}
};
var Injector = (_class = function () {
function Injector(parent, items, sheetProcessor) {
var Injector = (_class2 = function () {
function Injector(items, sheetProcessor, parent) {
this.parent = parent;
this.top = parent ? parent.top : this;
this._sheetProcessor = sheetProcessor || defaultSheetProcessor;
this._sticky = undefined;

@@ -99,3 +113,7 @@ if (items !== undefined) {

} else if (typeof item === 'function') {
this.value(item, null, true);
if (this._sticky === undefined) {
this._sticky = new Set();
}
this._sticky.add(item);
} else {

@@ -108,3 +126,3 @@ this.value(item.constructor, item, true);

Injector.prototype.value = function value(key, next, force) {
Injector.prototype.value = function value(key, next, force, oldValue) {
if (next !== undefined) return next;

@@ -114,7 +132,5 @@

if (this.top === this) {
var _sheet = this._sheetProcessor.createStyleSheet(this.instance(key));
_sheet.attach();
return _sheet;
var sheet = oldValue === undefined ? this._sheetProcessor.createStyleSheet(this._fastCall(key)) : oldValue.update(this._fastCall(key));
sheet.attach();
return sheet;
}

@@ -125,3 +141,3 @@

if (this.parent !== undefined) {
if (this.parent !== undefined && (this._sticky === undefined || !this._sticky.has(key))) {
chainCount++;

@@ -137,9 +153,18 @@ var value = this.parent.value(key);

if (chainCount === 0) {
return this.instance(key);
return this._fastNew(key);
}
return undefined;
};
Injector.prototype._destroyProp = function _destroyProp(key, value) {
if (typeof key === 'function' && key.theme !== undefined && value !== undefined) {
value.detach();
return;
}
};
Injector.prototype._destroy = function _destroy() {
this._sticky = undefined;
this.parent = undefined;
this.map = undefined;
this.top = undefined;

@@ -149,3 +174,5 @@ this._sheetProcessor = undefined;

Injector.prototype._fastCall = function _fastCall(key, args) {
Injector.prototype._fastNew = function _fastNew(key) {
var args = this.resolve(key.deps);
switch (args.length) {

@@ -167,2 +194,5 @@ case 1:

case 6:
return new key(args[0], args[1], args[2], args[3], args[4], args[5]);
default:

@@ -173,11 +203,34 @@ return new (Function.prototype.bind.apply(key, [null].concat(args)))();

Injector.prototype.instance = function instance(key) {
return this._fastCall(key, this.resolve(key.deps));
Injector.prototype._fastCall = function _fastCall(key) {
var args = this.resolve(key.deps);
switch (args.length) {
case 1:
return key(args[0]);
case 2:
return key(args[0], args[1]);
case 3:
return key(args[0], args[1], args[2]);
case 4:
return key(args[0], args[1], args[2], args[3]);
case 5:
return key(args[0], args[1], args[2], args[3], args[4]);
case 6:
return key(args[0], args[1], args[2], args[3], args[4], args[5]);
default:
return key.apply(undefined, args);
}
};
Injector.prototype.copy = function copy(items) {
return new Injector(this, items, this._sheetProcessor);
return new Injector(items, this._sheetProcessor, this);
};
Injector.prototype.resolve = function resolve(argDeps, acc) {
Injector.prototype.resolve = function resolve(argDeps) {
var result = [];

@@ -195,9 +248,3 @@

var key = argDep[prop];
if (key.theme === undefined) {
obj[prop] = this.value(key);
} else if (acc !== undefined) {
acc.sheet = this.value(key);
obj[prop] = acc.sheet.classes;
}
obj[prop] = key.theme === undefined ? this.value(key) : this.value(key).classes;
}

@@ -216,3 +263,3 @@

return Injector;
}(), (_applyDecoratedDescriptor$1(_class.prototype, "value", [memkey], Object.getOwnPropertyDescriptor(_class.prototype, "value"), _class.prototype)), _class);
}(), (_applyDecoratedDescriptor$1(_class2.prototype, "value", [memkey], Object.getOwnPropertyDescriptor(_class2.prototype, "value"), _class2.prototype)), _class2);

@@ -387,3 +434,2 @@ function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) {

_this._injector = undefined;
_this.sheet = undefined;
_this._el = undefined;

@@ -405,3 +451,3 @@ _this._render = render;

AtomizedComponent.prototype.componentWillUnmount = function componentWillUnmount() {
defaultContext.getAtom(this, this.r, 'r').destroyed(true);
defaultContext.getAtom('r$', this).destroyed(true);
};

@@ -416,7 +462,2 @@

if (this.sheet !== undefined && this.constructor.instances === 0) {
this.sheet.detach();
}
this.sheet = undefined;
this._el = undefined;

@@ -433,4 +474,5 @@ this.props = undefined;

return this._injector;
};
}; // @mem
AtomizedComponent.prototype._state = function _state(next, force) {

@@ -443,9 +485,3 @@ var injector = this._injector || this._getInjector();

var oldSheet = this.sheet;
var state = injector.resolve(this._render.deps, this)[0];
if (oldSheet !== undefined && this.sheet !== oldSheet) {
oldSheet.detach();
}
var state = injector.resolve(this._render.deps)[0];
return state;

@@ -488,3 +524,3 @@ };

return AtomizedComponent;
}(BaseComponent), (_applyDecoratedDescriptor(_class.prototype, "_state", [mem], Object.getOwnPropertyDescriptor(_class.prototype, "_state"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "r", [detached], Object.getOwnPropertyDescriptor(_class.prototype, "r"), _class.prototype)), _class);
}(BaseComponent), (_applyDecoratedDescriptor(_class.prototype, "r", [detached], Object.getOwnPropertyDescriptor(_class.prototype, "r"), _class.prototype)), _class);
return function reactWrapper(render) {

@@ -491,0 +527,0 @@ function WrappedComponent(props, context) {

@@ -1,2 +0,2 @@

"use strict";function _applyDecoratedDescriptor$1(e,t,r,o,n){var i={};return Object.keys(o).forEach(function(e){i[e]=o[e]}),i.enumerable=!!i.enumerable,i.configurable=!!i.configurable,("value"in i||i.initializer)&&(i.writable=!0),i=r.slice().reverse().reduce(function(r,o){return o(e,t,r)||r},i),n&&void 0!==i.initializer&&(i.value=i.initializer?i.initializer.call(n):void 0,i.initializer=void 0),void 0===i.initializer&&(Object.defineProperty(e,t,i),i=null),i}function _applyDecoratedDescriptor(e,t,r,o,n){var i={};return Object.keys(o).forEach(function(e){i[e]=o[e]}),i.enumerable=!!i.enumerable,i.configurable=!!i.configurable,("value"in i||i.initializer)&&(i.writable=!0),i=r.slice().reverse().reduce(function(r,o){return o(e,t,r)||r},i),n&&void 0!==i.initializer&&(i.value=i.initializer?i.initializer.call(n):void 0,i.initializer=void 0),void 0===i.initializer&&(Object.defineProperty(e,t,i),i=null),i}function createEventFix(e){function t(t){e(t),lom_atom.defaultContext.run()}return t.displayName=e.displayName||e.name,t}function shouldUpdate(e,t){if(e===t)return!1;if(!e&&t||!t&&e)return!0;var r=0;for(var o in e){if(e[o]!==t[o])return!0;r++}for(var n in t)r--;return 0!==r}function createCreateElement(e,t){return function(){var r=arguments[0],o=arguments[1],n=void 0,i="function"==typeof r&&void 0===r.prototype.render;switch(i?(void 0===r.__lom&&(r.__lom=e(r)),n=r.__lom,o?o.__lom_ctx=parentContext:o={__lom_ctx:parentContext}):n=r,o&&(o.onKeyPress&&(o.onKeyPress=createEventFix(o.onKeyPress)),o.onKeyDown&&(o.onKeyDown=createEventFix(o.onKeyDown)),o.onKeyUp&&(o.onKeyUp=createEventFix(o.onKeyUp)),o.onInput&&(o.onChange=createEventFix(o.onInput)),o.onChange&&(o.onChange=createEventFix(o.onChange))),arguments.length){case 2:return t(n,o);case 3:return t(n,o,arguments[2]);case 4:return t(n,o,arguments[2],arguments[3]);case 5:return t(n,o,arguments[2],arguments[3],arguments[4]);case 6:return t(n,o,arguments[2],arguments[3],arguments[4],arguments[5]);case 7:return t(n,o,arguments[2],arguments[3],arguments[4],arguments[5],arguments[6]);case 8:return t(n,o,arguments[2],arguments[3],arguments[4],arguments[5],arguments[6],arguments[7]);case 9:return t(n,o,arguments[2],arguments[3],arguments[4],arguments[5],arguments[6],arguments[7],arguments[8]);default:if(!1===i)return t.apply(null,arguments);for(var s=[n,o],a=2,c=arguments.length;a<c;a++)s.push(arguments[a]);return t.apply(null,s)}}}function createReactWrapper(e,t){var r,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:new Injector,n=(r=function(e){function r(t,r,o){var n;return n=e.call(this,t,r)||this,n._propsChanged=!0,n._injector=void 0,n.sheet=void 0,n._el=void 0,n._render=o,void 0===o.deps&&void 0===o.props||n.constructor.instances++,n}return inheritsLoose(r,e),r.prototype.shouldComponentUpdate=function(e){return this._propsChanged=shouldUpdate(this.props,e),this._propsChanged},r.prototype.componentWillUnmount=function(){lom_atom.defaultContext.getAtom(this,this.r,"r").destroyed(!0)},r.prototype._destroy=function(){var e=this._render;void 0===e.deps&&void 0===e.props||this.constructor.instances--,void 0!==this.sheet&&0===this.constructor.instances&&this.sheet.detach(),this.sheet=void 0,this._el=void 0,this.props=void 0,this._injector=void 0,this._render=void 0},r.prototype._getInjector=function(){var e=this.props.__lom_ctx||o;return this._injector=this.constructor.instances>0?e.copy():e,this._injector},r.prototype._state=function(e,t){var r=this._injector||this._getInjector();this._render.props&&t&&r.value(this._render.props,this.props,!0);var o=this.sheet,n=r.resolve(this._render.deps,this)[0];return void 0!==o&&this.sheet!==o&&o.detach(),n},r.prototype.r=function(e,r){var o=void 0,n=this._render,i=parentContext;parentContext=this._injector||this._getInjector();var s=void 0!==n.deps?this._state(void 0,r):void 0;try{o=n(this.props,s)}catch(e){var a=n.onError||t;o=a({error:e},void 0===a.deps?void 0:parentContext.resolve(a.deps)[0])}return parentContext=i,r||(this._el=o,this.forceUpdate(),this._el=void 0),this._propsChanged=!1,o},r.prototype.render=function(){return void 0===this._el?this.r(void 0,this._propsChanged):this._el},r}(e),_applyDecoratedDescriptor(r.prototype,"_state",[lom_atom.mem],Object.getOwnPropertyDescriptor(r.prototype,"_state"),r.prototype),_applyDecoratedDescriptor(r.prototype,"r",[lom_atom.detached],Object.getOwnPropertyDescriptor(r.prototype,"r"),r.prototype),r);return function(e){function t(t,r){n.call(this,t,r,e)}return t.instances=0,t.displayName=e.displayName||e.name,t.prototype=Object.create(n.prototype),t.prototype.constructor=t,t}}Object.defineProperty(exports,"__esModule",{value:!0});var lom_atom=require("lom_atom"),_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},inheritsLoose=function(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t},_class,chainCount=0,defaultSheetProcessor={createStyleSheet:function(e){return{attach:function(){return this},detach:function(){return this},classes:{}}}},Injector=(_class=function(){function e(e,t,r){if(this.parent=e,this.top=e?e.top:this,this._sheetProcessor=r||defaultSheetProcessor,void 0!==t)for(var o=0;o<t.length;o++){var n=t[o];n instanceof Array?this.value(n[0],n[1],!0):"function"==typeof n?this.value(n,null,!0):this.value(n.constructor,n,!0)}}return e.prototype.value=function(e,t,r){if(void 0!==t)return t;if(!0===e.theme){if(this.top===this){var o=this._sheetProcessor.createStyleSheet(this.instance(e));return o.attach(),o}return this.top.value(e)}if(void 0!==this.parent){chainCount++;var n=this.parent.value(e);if(chainCount--,void 0!==n)return n}return 0===chainCount?this.instance(e):void 0},e.prototype._destroy=function(){this.parent=void 0,this.map=void 0,this.top=void 0,this._sheetProcessor=void 0},e.prototype._fastCall=function(e,t){switch(t.length){case 1:return new e(t[0]);case 2:return new e(t[0],t[1]);case 3:return new e(t[0],t[1],t[2]);case 4:return new e(t[0],t[1],t[2],t[3]);case 5:return new e(t[0],t[1],t[2],t[3],t[4]);default:return new(Function.prototype.bind.apply(e,[null].concat(t)))}},e.prototype.instance=function(e){return this._fastCall(e,this.resolve(e.deps))},e.prototype.copy=function(t){return new e(this,t,this._sheetProcessor)},e.prototype.resolve=function(e,t){var r=[];if(void 0!==e)for(var o=0,n=e.length;o<n;o++){var i=e[o];if("object"===_typeof(i)){var s={};for(var a in i){var c=i[a];void 0===c.theme?s[a]=this.value(c):void 0!==t&&(t.sheet=this.value(c),s[a]=t.sheet.classes)}r.push(s)}else r.push(this.value(i))}return r},e}(),_applyDecoratedDescriptor$1(_class.prototype,"value",[lom_atom.memkey],Object.getOwnPropertyDescriptor(_class.prototype,"value"),_class.prototype),_class),parentContext=void 0;exports.createReactWrapper=createReactWrapper,exports.createCreateElement=createCreateElement,exports.Injector=Injector;
"use strict";function _applyDecoratedDescriptor$1(t,e,r,o,n){var i={};return Object.keys(o).forEach(function(t){i[t]=o[t]}),i.enumerable=!!i.enumerable,i.configurable=!!i.configurable,("value"in i||i.initializer)&&(i.writable=!0),i=r.slice().reverse().reduce(function(r,o){return o(t,e,r)||r},i),n&&void 0!==i.initializer&&(i.value=i.initializer?i.initializer.call(n):void 0,i.initializer=void 0),void 0===i.initializer&&(Object.defineProperty(t,e,i),i=null),i}function _applyDecoratedDescriptor(t,e,r,o,n){var i={};return Object.keys(o).forEach(function(t){i[t]=o[t]}),i.enumerable=!!i.enumerable,i.configurable=!!i.configurable,("value"in i||i.initializer)&&(i.writable=!0),i=r.slice().reverse().reduce(function(r,o){return o(t,e,r)||r},i),n&&void 0!==i.initializer&&(i.value=i.initializer?i.initializer.call(n):void 0,i.initializer=void 0),void 0===i.initializer&&(Object.defineProperty(t,e,i),i=null),i}function createEventFix(t){function e(e){t(e),lom_atom.defaultContext.run()}return e.displayName=t.displayName||t.name,e}function shouldUpdate(t,e){if(t===e)return!1;if(!t&&e||!e&&t)return!0;var r=0;for(var o in t){if(t[o]!==e[o])return!0;r++}for(var n in e)r--;return 0!==r}function createCreateElement(t,e){return function(){var r=arguments[0],o=arguments[1],n=void 0,i="function"==typeof r&&void 0===r.prototype.render;switch(i?(void 0===r.__lom&&(r.__lom=t(r)),n=r.__lom,o?o.__lom_ctx=parentContext:o={__lom_ctx:parentContext}):n=r,o&&(o.onKeyPress&&(o.onKeyPress=createEventFix(o.onKeyPress)),o.onKeyDown&&(o.onKeyDown=createEventFix(o.onKeyDown)),o.onKeyUp&&(o.onKeyUp=createEventFix(o.onKeyUp)),o.onInput&&(o.onChange=createEventFix(o.onInput)),o.onChange&&(o.onChange=createEventFix(o.onChange))),arguments.length){case 2:return e(n,o);case 3:return e(n,o,arguments[2]);case 4:return e(n,o,arguments[2],arguments[3]);case 5:return e(n,o,arguments[2],arguments[3],arguments[4]);case 6:return e(n,o,arguments[2],arguments[3],arguments[4],arguments[5]);case 7:return e(n,o,arguments[2],arguments[3],arguments[4],arguments[5],arguments[6]);case 8:return e(n,o,arguments[2],arguments[3],arguments[4],arguments[5],arguments[6],arguments[7]);case 9:return e(n,o,arguments[2],arguments[3],arguments[4],arguments[5],arguments[6],arguments[7],arguments[8]);default:if(!1===i)return e.apply(null,arguments);for(var s=[n,o],a=2,c=arguments.length;a<c;a++)s.push(arguments[a]);return e.apply(null,s)}}}function createReactWrapper(t,e){var r,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:new Injector,n=(r=function(t){function r(e,r,o){var n;return n=t.call(this,e,r)||this,n._propsChanged=!0,n._injector=void 0,n._el=void 0,n._render=o,void 0===o.deps&&void 0===o.props||n.constructor.instances++,n}return inheritsLoose(r,t),r.prototype.shouldComponentUpdate=function(t){return this._propsChanged=shouldUpdate(this.props,t),this._propsChanged},r.prototype.componentWillUnmount=function(){lom_atom.defaultContext.getAtom("r$",this).destroyed(!0)},r.prototype._destroy=function(){var t=this._render;void 0===t.deps&&void 0===t.props||this.constructor.instances--,this._el=void 0,this.props=void 0,this._injector=void 0,this._render=void 0},r.prototype._getInjector=function(){var t=this.props.__lom_ctx||o;return this._injector=this.constructor.instances>0?t.copy():t,this._injector},r.prototype._state=function(t,e){var r=this._injector||this._getInjector();return this._render.props&&e&&r.value(this._render.props,this.props,!0),r.resolve(this._render.deps)[0]},r.prototype.r=function(t,r){var o=void 0,n=this._render,i=parentContext;parentContext=this._injector||this._getInjector();var s=void 0!==n.deps?this._state(void 0,r):void 0;try{o=n(this.props,s)}catch(t){var a=n.onError||e;o=a({error:t},void 0===a.deps?void 0:parentContext.resolve(a.deps)[0])}return parentContext=i,r||(this._el=o,this.forceUpdate(),this._el=void 0),this._propsChanged=!1,o},r.prototype.render=function(){return void 0===this._el?this.r(void 0,this._propsChanged):this._el},r}(t),_applyDecoratedDescriptor(r.prototype,"r",[lom_atom.detached],Object.getOwnPropertyDescriptor(r.prototype,"r"),r.prototype),r);return function(t){function e(e,r){n.call(this,e,r,t)}return e.instances=0,e.displayName=t.displayName||t.name,e.prototype=Object.create(n.prototype),e.prototype.constructor=e,e}}Object.defineProperty(exports,"__esModule",{value:!0});var lom_atom=require("lom_atom"),_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},inheritsLoose=function(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,t.__proto__=e},_class2,chainCount=0,FakeSheet=function(){function t(){this.classes={}}return t.prototype.update=function(t){return this},t.prototype.attach=function(){return this},t.prototype.detach=function(){return this},t}(),defaultSheetProcessor={createStyleSheet:function(t){return new FakeSheet}},Injector=(_class2=function(){function t(t,e,r){if(this.parent=r,this.top=r?r.top:this,this._sheetProcessor=e||defaultSheetProcessor,this._sticky=void 0,void 0!==t)for(var o=0;o<t.length;o++){var n=t[o];n instanceof Array?this.value(n[0],n[1],!0):"function"==typeof n?(void 0===this._sticky&&(this._sticky=new Set),this._sticky.add(n)):this.value(n.constructor,n,!0)}}return t.prototype.value=function(t,e,r,o){if(void 0!==e)return e;if(!0===t.theme){if(this.top===this){var n=void 0===o?this._sheetProcessor.createStyleSheet(this._fastCall(t)):o.update(this._fastCall(t));return n.attach(),n}return this.top.value(t)}if(void 0!==this.parent&&(void 0===this._sticky||!this._sticky.has(t))){chainCount++;var i=this.parent.value(t);if(chainCount--,void 0!==i)return i}return 0===chainCount?this._fastNew(t):void 0},t.prototype._destroyProp=function(t,e){"function"!=typeof t||void 0===t.theme||void 0===e||e.detach()},t.prototype._destroy=function(){this._sticky=void 0,this.parent=void 0,this.top=void 0,this._sheetProcessor=void 0},t.prototype._fastNew=function(t){var e=this.resolve(t.deps);switch(e.length){case 1:return new t(e[0]);case 2:return new t(e[0],e[1]);case 3:return new t(e[0],e[1],e[2]);case 4:return new t(e[0],e[1],e[2],e[3]);case 5:return new t(e[0],e[1],e[2],e[3],e[4]);case 6:return new t(e[0],e[1],e[2],e[3],e[4],e[5]);default:return new(Function.prototype.bind.apply(t,[null].concat(e)))}},t.prototype._fastCall=function(t){var e=this.resolve(t.deps);switch(e.length){case 1:return t(e[0]);case 2:return t(e[0],e[1]);case 3:return t(e[0],e[1],e[2]);case 4:return t(e[0],e[1],e[2],e[3]);case 5:return t(e[0],e[1],e[2],e[3],e[4]);case 6:return t(e[0],e[1],e[2],e[3],e[4],e[5]);default:return t.apply(void 0,e)}},t.prototype.copy=function(e){return new t(e,this._sheetProcessor,this)},t.prototype.resolve=function(t){var e=[];if(void 0!==t)for(var r=0,o=t.length;r<o;r++){var n=t[r];if("object"===_typeof(n)){var i={};for(var s in n){var a=n[s];i[s]=void 0===a.theme?this.value(a):this.value(a).classes}e.push(i)}else e.push(this.value(n))}return e},t}(),_applyDecoratedDescriptor$1(_class2.prototype,"value",[lom_atom.memkey],Object.getOwnPropertyDescriptor(_class2.prototype,"value"),_class2.prototype),_class2),parentContext=void 0;exports.createReactWrapper=createReactWrapper,exports.createCreateElement=createCreateElement,exports.Injector=Injector;
//# sourceMappingURL=reactive-di.js.map

@@ -1,2 +0,2 @@

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("lom_atom")):"function"==typeof define&&define.amd?define(["exports","lom_atom"],e):e(t["reactive-di"]={},t.lom_atom)}(this,function(t,e){"use strict";function r(t,e,r,o,n){var i={};return Object.keys(o).forEach(function(t){i[t]=o[t]}),i.enumerable=!!i.enumerable,i.configurable=!!i.configurable,("value"in i||i.initializer)&&(i.writable=!0),i=r.slice().reverse().reduce(function(r,o){return o(t,e,r)||r},i),n&&void 0!==i.initializer&&(i.value=i.initializer?i.initializer.call(n):void 0,i.initializer=void 0),void 0===i.initializer&&(Object.defineProperty(t,e,i),i=null),i}function o(t){function r(r){t(r),e.defaultContext.run()}return r.displayName=t.displayName||t.name,r}function n(t,e){if(t===e)return!1;if(!t&&e||!e&&t)return!0;var r=0;for(var o in t){if(t[o]!==e[o])return!0;r++}for(var n in e)r--;return 0!==r}var i,s="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},a=function(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,t.__proto__=e},c=0,p={createStyleSheet:function(t){return{attach:function(){return this},detach:function(){return this},classes:{}}}},u=(i=function(){function t(t,e,r){if(this.parent=t,this.top=t?t.top:this,this._sheetProcessor=r||p,void 0!==e)for(var o=0;o<e.length;o++){var n=e[o];n instanceof Array?this.value(n[0],n[1],!0):"function"==typeof n?this.value(n,null,!0):this.value(n.constructor,n,!0)}}return t.prototype.value=function(t,e,r){if(void 0!==e)return e;if(!0===t.theme){if(this.top===this){var o=this._sheetProcessor.createStyleSheet(this.instance(t));return o.attach(),o}return this.top.value(t)}if(void 0!==this.parent){c++;var n=this.parent.value(t);if(c--,void 0!==n)return n}return 0===c?this.instance(t):void 0},t.prototype._destroy=function(){this.parent=void 0,this.map=void 0,this.top=void 0,this._sheetProcessor=void 0},t.prototype._fastCall=function(t,e){switch(e.length){case 1:return new t(e[0]);case 2:return new t(e[0],e[1]);case 3:return new t(e[0],e[1],e[2]);case 4:return new t(e[0],e[1],e[2],e[3]);case 5:return new t(e[0],e[1],e[2],e[3],e[4]);default:return new(Function.prototype.bind.apply(t,[null].concat(e)))}},t.prototype.instance=function(t){return this._fastCall(t,this.resolve(t.deps))},t.prototype.copy=function(e){return new t(this,e,this._sheetProcessor)},t.prototype.resolve=function(t,e){var r=[];if(void 0!==t)for(var o=0,n=t.length;o<n;o++){var i=t[o];if("object"===s(i)){var a={};for(var c in i){var p=i[c];void 0===p.theme?a[c]=this.value(p):void 0!==e&&(e.sheet=this.value(p),a[c]=e.sheet.classes)}r.push(a)}else r.push(this.value(i))}return r},t}(),function(t,e,r,o,n){var i={};Object.keys(o).forEach(function(t){i[t]=o[t]}),i.enumerable=!!i.enumerable,i.configurable=!!i.configurable,("value"in i||i.initializer)&&(i.writable=!0),i=r.slice().reverse().reduce(function(r,o){return o(t,e,r)||r},i),n&&void 0!==i.initializer&&(i.value=i.initializer?i.initializer.call(n):void 0,i.initializer=void 0),void 0===i.initializer&&(Object.defineProperty(t,e,i),i=null)}(i.prototype,"value",[e.memkey],Object.getOwnPropertyDescriptor(i.prototype,"value"),i.prototype),i),h=void 0;t.createReactWrapper=function(t,o){var i,s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:new u,c=(i=function(t){function r(e,r,o){var n;return n=t.call(this,e,r)||this,n._propsChanged=!0,n._injector=void 0,n.sheet=void 0,n._el=void 0,n._render=o,void 0===o.deps&&void 0===o.props||n.constructor.instances++,n}return a(r,t),r.prototype.shouldComponentUpdate=function(t){return this._propsChanged=n(this.props,t),this._propsChanged},r.prototype.componentWillUnmount=function(){e.defaultContext.getAtom(this,this.r,"r").destroyed(!0)},r.prototype._destroy=function(){var t=this._render;void 0===t.deps&&void 0===t.props||this.constructor.instances--,void 0!==this.sheet&&0===this.constructor.instances&&this.sheet.detach(),this.sheet=void 0,this._el=void 0,this.props=void 0,this._injector=void 0,this._render=void 0},r.prototype._getInjector=function(){var t=this.props.__lom_ctx||s;return this._injector=this.constructor.instances>0?t.copy():t,this._injector},r.prototype._state=function(t,e){var r=this._injector||this._getInjector();this._render.props&&e&&r.value(this._render.props,this.props,!0);var o=this.sheet,n=r.resolve(this._render.deps,this)[0];return void 0!==o&&this.sheet!==o&&o.detach(),n},r.prototype.r=function(t,e){var r=void 0,n=this._render,i=h;h=this._injector||this._getInjector();var s=void 0!==n.deps?this._state(void 0,e):void 0;try{r=n(this.props,s)}catch(t){var a=n.onError||o;r=a({error:t},void 0===a.deps?void 0:h.resolve(a.deps)[0])}return h=i,e||(this._el=r,this.forceUpdate(),this._el=void 0),this._propsChanged=!1,r},r.prototype.render=function(){return void 0===this._el?this.r(void 0,this._propsChanged):this._el},r}(t),r(i.prototype,"_state",[e.mem],Object.getOwnPropertyDescriptor(i.prototype,"_state"),i.prototype),r(i.prototype,"r",[e.detached],Object.getOwnPropertyDescriptor(i.prototype,"r"),i.prototype),i);return function(t){function e(e,r){c.call(this,e,r,t)}return e.instances=0,e.displayName=t.displayName||t.name,e.prototype=Object.create(c.prototype),e.prototype.constructor=e,e}},t.createCreateElement=function(t,e){return function(){var r=arguments[0],n=arguments[1],i=void 0,s="function"==typeof r&&void 0===r.prototype.render;switch(s?(void 0===r.__lom&&(r.__lom=t(r)),i=r.__lom,n?n.__lom_ctx=h:n={__lom_ctx:h}):i=r,n&&(n.onKeyPress&&(n.onKeyPress=o(n.onKeyPress)),n.onKeyDown&&(n.onKeyDown=o(n.onKeyDown)),n.onKeyUp&&(n.onKeyUp=o(n.onKeyUp)),n.onInput&&(n.onChange=o(n.onInput)),n.onChange&&(n.onChange=o(n.onChange))),arguments.length){case 2:return e(i,n);case 3:return e(i,n,arguments[2]);case 4:return e(i,n,arguments[2],arguments[3]);case 5:return e(i,n,arguments[2],arguments[3],arguments[4]);case 6:return e(i,n,arguments[2],arguments[3],arguments[4],arguments[5]);case 7:return e(i,n,arguments[2],arguments[3],arguments[4],arguments[5],arguments[6]);case 8:return e(i,n,arguments[2],arguments[3],arguments[4],arguments[5],arguments[6],arguments[7]);case 9:return e(i,n,arguments[2],arguments[3],arguments[4],arguments[5],arguments[6],arguments[7],arguments[8]);default:if(!1===s)return e.apply(null,arguments);for(var a=[i,n],c=2,p=arguments.length;c<p;c++)a.push(arguments[c]);return e.apply(null,a)}}},t.Injector=u,Object.defineProperty(t,"__esModule",{value:!0})});
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("lom_atom")):"function"==typeof define&&define.amd?define(["exports","lom_atom"],e):e(t["reactive-di"]={},t.lom_atom)}(this,function(t,e){"use strict";function r(t,e,r,o,n){var i={};return Object.keys(o).forEach(function(t){i[t]=o[t]}),i.enumerable=!!i.enumerable,i.configurable=!!i.configurable,("value"in i||i.initializer)&&(i.writable=!0),i=r.slice().reverse().reduce(function(r,o){return o(t,e,r)||r},i),n&&void 0!==i.initializer&&(i.value=i.initializer?i.initializer.call(n):void 0,i.initializer=void 0),void 0===i.initializer&&(Object.defineProperty(t,e,i),i=null),i}function o(t){function r(r){t(r),e.defaultContext.run()}return r.displayName=t.displayName||t.name,r}function n(t,e){if(t===e)return!1;if(!t&&e||!e&&t)return!0;var r=0;for(var o in t){if(t[o]!==e[o])return!0;r++}for(var n in e)r--;return 0!==r}var i,s="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},a=function(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,t.__proto__=e},c=0,u=function(){function t(){this.classes={}}return t.prototype.update=function(t){return this},t.prototype.attach=function(){return this},t.prototype.detach=function(){return this},t}(),p={createStyleSheet:function(t){return new u}},l=(i=function(){function t(t,e,r){if(this.parent=r,this.top=r?r.top:this,this._sheetProcessor=e||p,this._sticky=void 0,void 0!==t)for(var o=0;o<t.length;o++){var n=t[o];n instanceof Array?this.value(n[0],n[1],!0):"function"==typeof n?(void 0===this._sticky&&(this._sticky=new Set),this._sticky.add(n)):this.value(n.constructor,n,!0)}}return t.prototype.value=function(t,e,r,o){if(void 0!==e)return e;if(!0===t.theme){if(this.top===this){var n=void 0===o?this._sheetProcessor.createStyleSheet(this._fastCall(t)):o.update(this._fastCall(t));return n.attach(),n}return this.top.value(t)}if(void 0!==this.parent&&(void 0===this._sticky||!this._sticky.has(t))){c++;var i=this.parent.value(t);if(c--,void 0!==i)return i}return 0===c?this._fastNew(t):void 0},t.prototype._destroyProp=function(t,e){"function"!=typeof t||void 0===t.theme||void 0===e||e.detach()},t.prototype._destroy=function(){this._sticky=void 0,this.parent=void 0,this.top=void 0,this._sheetProcessor=void 0},t.prototype._fastNew=function(t){var e=this.resolve(t.deps);switch(e.length){case 1:return new t(e[0]);case 2:return new t(e[0],e[1]);case 3:return new t(e[0],e[1],e[2]);case 4:return new t(e[0],e[1],e[2],e[3]);case 5:return new t(e[0],e[1],e[2],e[3],e[4]);case 6:return new t(e[0],e[1],e[2],e[3],e[4],e[5]);default:return new(Function.prototype.bind.apply(t,[null].concat(e)))}},t.prototype._fastCall=function(t){var e=this.resolve(t.deps);switch(e.length){case 1:return t(e[0]);case 2:return t(e[0],e[1]);case 3:return t(e[0],e[1],e[2]);case 4:return t(e[0],e[1],e[2],e[3]);case 5:return t(e[0],e[1],e[2],e[3],e[4]);case 6:return t(e[0],e[1],e[2],e[3],e[4],e[5]);default:return t.apply(void 0,e)}},t.prototype.copy=function(e){return new t(e,this._sheetProcessor,this)},t.prototype.resolve=function(t){var e=[];if(void 0!==t)for(var r=0,o=t.length;r<o;r++){var n=t[r];if("object"===s(n)){var i={};for(var a in n){var c=n[a];i[a]=void 0===c.theme?this.value(c):this.value(c).classes}e.push(i)}else e.push(this.value(n))}return e},t}(),function(t,e,r,o,n){var i={};Object.keys(o).forEach(function(t){i[t]=o[t]}),i.enumerable=!!i.enumerable,i.configurable=!!i.configurable,("value"in i||i.initializer)&&(i.writable=!0),i=r.slice().reverse().reduce(function(r,o){return o(t,e,r)||r},i),n&&void 0!==i.initializer&&(i.value=i.initializer?i.initializer.call(n):void 0,i.initializer=void 0),void 0===i.initializer&&(Object.defineProperty(t,e,i),i=null)}(i.prototype,"value",[e.memkey],Object.getOwnPropertyDescriptor(i.prototype,"value"),i.prototype),i),h=void 0;t.createReactWrapper=function(t,o){var i,s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:new l,c=(i=function(t){function r(e,r,o){var n;return n=t.call(this,e,r)||this,n._propsChanged=!0,n._injector=void 0,n._el=void 0,n._render=o,void 0===o.deps&&void 0===o.props||n.constructor.instances++,n}return a(r,t),r.prototype.shouldComponentUpdate=function(t){return this._propsChanged=n(this.props,t),this._propsChanged},r.prototype.componentWillUnmount=function(){e.defaultContext.getAtom("r$",this).destroyed(!0)},r.prototype._destroy=function(){var t=this._render;void 0===t.deps&&void 0===t.props||this.constructor.instances--,this._el=void 0,this.props=void 0,this._injector=void 0,this._render=void 0},r.prototype._getInjector=function(){var t=this.props.__lom_ctx||s;return this._injector=this.constructor.instances>0?t.copy():t,this._injector},r.prototype._state=function(t,e){var r=this._injector||this._getInjector();return this._render.props&&e&&r.value(this._render.props,this.props,!0),r.resolve(this._render.deps)[0]},r.prototype.r=function(t,e){var r=void 0,n=this._render,i=h;h=this._injector||this._getInjector();var s=void 0!==n.deps?this._state(void 0,e):void 0;try{r=n(this.props,s)}catch(t){var a=n.onError||o;r=a({error:t},void 0===a.deps?void 0:h.resolve(a.deps)[0])}return h=i,e||(this._el=r,this.forceUpdate(),this._el=void 0),this._propsChanged=!1,r},r.prototype.render=function(){return void 0===this._el?this.r(void 0,this._propsChanged):this._el},r}(t),r(i.prototype,"r",[e.detached],Object.getOwnPropertyDescriptor(i.prototype,"r"),i.prototype),i);return function(t){function e(e,r){c.call(this,e,r,t)}return e.instances=0,e.displayName=t.displayName||t.name,e.prototype=Object.create(c.prototype),e.prototype.constructor=e,e}},t.createCreateElement=function(t,e){return function(){var r=arguments[0],n=arguments[1],i=void 0,s="function"==typeof r&&void 0===r.prototype.render;switch(s?(void 0===r.__lom&&(r.__lom=t(r)),i=r.__lom,n?n.__lom_ctx=h:n={__lom_ctx:h}):i=r,n&&(n.onKeyPress&&(n.onKeyPress=o(n.onKeyPress)),n.onKeyDown&&(n.onKeyDown=o(n.onKeyDown)),n.onKeyUp&&(n.onKeyUp=o(n.onKeyUp)),n.onInput&&(n.onChange=o(n.onInput)),n.onChange&&(n.onChange=o(n.onChange))),arguments.length){case 2:return e(i,n);case 3:return e(i,n,arguments[2]);case 4:return e(i,n,arguments[2],arguments[3]);case 5:return e(i,n,arguments[2],arguments[3],arguments[4]);case 6:return e(i,n,arguments[2],arguments[3],arguments[4],arguments[5]);case 7:return e(i,n,arguments[2],arguments[3],arguments[4],arguments[5],arguments[6]);case 8:return e(i,n,arguments[2],arguments[3],arguments[4],arguments[5],arguments[6],arguments[7]);case 9:return e(i,n,arguments[2],arguments[3],arguments[4],arguments[5],arguments[6],arguments[7],arguments[8]);default:if(!1===s)return e.apply(null,arguments);for(var a=[i,n],c=2,u=arguments.length;c<u;c++)a.push(arguments[c]);return e.apply(null,a)}}},t.Injector=l,Object.defineProperty(t,"__esModule",{value:!0})});
//# sourceMappingURL=reactive-di.umd.js.map
{
"name": "reactive-di",
"version": "4.0.0",
"version": "4.0.1",
"description": "Reactive dependency injection",

@@ -16,4 +16,4 @@ "publishConfig": {

"scripts": {
"major": "npm run release -- --release-as major",
"release": "npm test && npm run build && standard-version",
"major": "npm run release -- --release-as major && npm run postversion",
"release": "npm test && npm run build && standard-version && npm run postversion",
"postversion": "git push --follow-tags origin master && npm publish",

@@ -72,2 +72,3 @@ "build": "rimraf dist && rollup -c",

"rollup-plugin-uglify": "^2.0.1",
"sinon": "^3.0.0",
"standard-version": "^4.2.0",

@@ -77,4 +78,4 @@ "uglify-es": "^3.0.27"

"dependencies": {
"lom_atom": "^1.0.0"
"lom_atom": "^1.0.4"
}
}

@@ -7,19 +7,4 @@ # Reactive DI [![Build Status](https://secure.travis-ci.org/zerkalica/reactive-di.png)](http://travis-ci.org/zerkalica/reactive-di)

Running examples:
Examples: [source](https://github.com/zerkalica/rdi-examples), [demo](http://zerkalica.github.io/rdi-examples/)
```js
npm start
```
And open:
```
http://localhost:8080/autocomplete.html - autocomplete with debounce
http://localhost:8080/hello.html - hello world
http://localhost:8080/todo.html - simple todomvc
http://localhost:8080/opts.html - demonstartion of some rendering optimistation
```
[complex todomvc](https://github.com/zerkalica/reactive-di-todomvc) example app.
## Motivation

@@ -26,0 +11,0 @@

@@ -150,3 +150,2 @@ // @flow

_injector: Injector | void = undefined
sheet: ISheet<*> | void = undefined

@@ -171,3 +170,3 @@ constructor(

componentWillUnmount() {
defaultContext.getAtom(this, this.r, 'r').destroyed(true)
defaultContext.getAtom('r$', this).destroyed(true)
}

@@ -180,7 +179,2 @@

}
if (this.sheet !== undefined && this.constructor.instances === 0) {
this.sheet.detach()
}
this.sheet = undefined
this._el = undefined

@@ -202,3 +196,3 @@ this.props = (undefined: any)

@mem
// @mem
_state(next?: State, force?: boolean): State {

@@ -209,9 +203,4 @@ const injector = this._injector || this._getInjector()

}
const oldSheet = this.sheet
const state = injector.resolve(this._render.deps, this)[0]
const state = injector.resolve(this._render.deps)[0]
if (oldSheet !== undefined && this.sheet !== oldSheet) {
oldSheet.detach()
}
return state

@@ -218,0 +207,0 @@ }

@@ -5,4 +5,4 @@ // @flow

export type IArg = Function | {[id: string]: Function}
export type IProvideItem = Function | [Function, Function]
export type IArg = Function | {+[id: string]: Function}
export type IProvideItem = Function | Object | [Function, mixed]

@@ -15,2 +15,3 @@ export type IPropsWithContext = {

export interface ISheet<V: Object> {
update(props: V): ISheet<V>;
attach(): ISheet<V>;

@@ -27,13 +28,21 @@ detach(): ISheet<V>;

class FakeSheet<V: Object> implements ISheet<V> {
classes: Object = {}
update(props: V): ISheet<V> {
return this
}
attach(): ISheet<V> {
return this
}
detach(): ISheet<V> {
return this
}
}
const defaultSheetProcessor: IProcessor = {
createStyleSheet<V: Object>(cssProps: V): ISheet<*> {
return {
attach() {
return this
},
detach() {
return this
},
classes: ({}: Object)
}
return new FakeSheet()
}

@@ -43,11 +52,12 @@ }

export default class Injector {
map: Map<Function, *>
parent: Injector | void
top: Injector
_sheetProcessor: IProcessor
_sticky: Set<Function> | void
constructor(parent?: Injector, items?: IProvideItem[], sheetProcessor?: IProcessor) {
constructor(items?: IProvideItem[], sheetProcessor?: IProcessor, parent?: Injector) {
this.parent = parent
this.top = parent ? parent.top : this
this._sheetProcessor = sheetProcessor || defaultSheetProcessor
this._sticky = undefined
if (items !== undefined) {

@@ -59,3 +69,6 @@ for (let i = 0; i < items.length; i++) {

} else if (typeof item === 'function') {
this.value(item, null, true)
if (this._sticky === undefined) {
this._sticky = new Set()
}
this._sticky.add(item)
} else {

@@ -69,3 +82,3 @@ this.value(item.constructor, item, true)

@memkey
value<V>(key: Function, next?: V, force?: boolean): V | void {
value<V>(key: Function, next?: V, force?: boolean, oldValue?: V): V {
if (next !== undefined) return next

@@ -75,3 +88,5 @@

if (this.top === this) {
const sheet = this._sheetProcessor.createStyleSheet(this.instance(key))
const sheet = oldValue === undefined
? this._sheetProcessor.createStyleSheet(this._fastCall(key))
: (oldValue: any).update(this._fastCall(key))
sheet.attach()

@@ -83,3 +98,3 @@ return (sheet: any)

if (this.parent !== undefined) {
if (this.parent !== undefined && (this._sticky === undefined || !this._sticky.has(key))) {
chainCount++

@@ -93,9 +108,18 @@ const value: V | void = this.parent.value(key)

if (chainCount === 0) {
return this.instance(key)
return this._fastNew(key)
}
return (undefined: any)
}
_destroyProp(key?: string | Function, value?: mixed) {
if (typeof key === 'function' && key.theme !== undefined && value !== undefined) {
(value: any).detach()
return
}
}
_destroy() {
this._sticky = undefined
this.parent = undefined
this.map = (undefined: any)
this.top = (undefined: any)

@@ -105,3 +129,4 @@ this._sheetProcessor = (undefined: any)

_fastCall<V>(key: any, args: mixed[]): V {
_fastNew<V>(key: any): V {
const args = this.resolve(key.deps)
switch (args.length) {

@@ -113,2 +138,3 @@ case 1: return new key(args[0])

case 5: return new key(args[0], args[1], args[2], args[3], args[4])
case 6: return new key(args[0], args[1], args[2], args[3], args[4], args[5])
default: return new key(...args)

@@ -118,11 +144,20 @@ }

instance<V>(key: Function): V {
return this._fastCall(key, this.resolve(key.deps))
_fastCall<V>(key: Function): V {
const args = this.resolve(key.deps)
switch (args.length) {
case 1: return key(args[0])
case 2: return key(args[0], args[1])
case 3: return key(args[0], args[1], args[2])
case 4: return key(args[0], args[1], args[2], args[3])
case 5: return key(args[0], args[1], args[2], args[3], args[4])
case 6: return key(args[0], args[1], args[2], args[3], args[4], args[5])
default: return key(...args)
}
}
copy(items?: IProvideItem[]): Injector {
return new Injector(this, items, this._sheetProcessor)
return new Injector(items, this._sheetProcessor, this)
}
resolve(argDeps?: IArg[], acc?: {sheet: ISheet<*> | void}): any[] {
resolve(argDeps?: IArg[]): any[] {
const result = []

@@ -136,8 +171,5 @@ if (argDeps !== undefined) {

const key = argDep[prop]
if (key.theme === undefined) {
obj[prop] = this.value(key)
} else if (acc !== undefined) {
acc.sheet = ((this.value(key): any): ISheet<*>)
obj[prop] = acc.sheet.classes
}
obj[prop] = key.theme === undefined
? this.value(key)
: ((this.value(key): any): ISheet<*>).classes
}

@@ -144,0 +176,0 @@ result.push(obj)

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc