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

urc

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

urc - npm Package Compare versions

Comparing version 1.0.2 to 1.0.3

dist/createMobxAtom.es.js

5

CHANGELOG.md

@@ -5,2 +5,7 @@ # Change Log

<a name="1.0.3"></a>
## [1.0.3](https://github.com/zerkalica/lom_atom/compare/v1.0.2...v1.0.3) (2018-03-09)
<a name="1.0.2"></a>

@@ -7,0 +12,0 @@ ## [1.0.2](https://github.com/zerkalica/lom_atom/compare/v1.0.1...v1.0.2) (2018-03-06)

207

dist/urc.es.js

@@ -1,46 +0,34 @@

function createConnect(_ref) {
var ReactAtom = _ref.ReactAtom,
renderError = _ref.renderError,
BaseComponent = _ref.BaseComponent;
var AtomizedComponent =
/*#__PURE__*/
function () {
function AtomizedComponent() {}
var AtomizedComponent =
/*#__PURE__*/
function () {
function AtomizedComponent() {}
var _proto = AtomizedComponent.prototype;
var _proto = AtomizedComponent.prototype;
_proto.componentWillMount = function componentWillMount() {
var props = this.props;
this._lastData = null;
this._lastError = null;
if (this.__componentWillMount) this.__componentWillMount();
this.__atom = new AtomizedComponent.ReactAtom(props && props.id ? props.id : this.constructor.displayName, this);
};
_proto.componentWillMount = function componentWillMount() {
var props = this.props;
this._lastData = null;
this._lastError = null;
if (this.__componentWillMount) this.__componentWillMount();
this.__atom = new ReactAtom(props && props.id ? props.id : this.constructor.displayName, this);
};
_proto.shouldComponentUpdate = function shouldComponentUpdate(props, state, context) {
var oldProps = this.props;
var count = 0;
_proto.shouldComponentUpdate = function shouldComponentUpdate(props, state, context) {
var oldProps = this.props;
var count = 0;
for (var k in oldProps) {
count++;
for (var k in oldProps) {
count++;
if (oldProps[k] !== props[k]) {
this.__atom.reset();
if (oldProps[k] !== props[k]) {
this.__atom.reset();
return true;
}
return true;
}
}
for (var _k in props) {
count--;
for (var _k in props) {
count--;
if (oldProps[_k] !== props[_k]) {
this.__atom.reset();
return true;
}
}
if (count !== 0) {
if (oldProps[_k] !== props[_k]) {
this.__atom.reset();

@@ -50,63 +38,103 @@

}
}
return this.__shouldComponentUpdate ? this.__shouldComponentUpdate(props, state, context) : false;
};
if (count !== 0) {
this.__atom.reset();
_proto.componentWillUnmount = function componentWillUnmount() {
if (this.__componentWillUnmount) this.__componentWillUnmount();
return true;
}
this.__atom.destructor();
return this.__shouldComponentUpdate ? this.__shouldComponentUpdate(props, state, context) : false;
};
this.__atom = null;
this._lastData = null;
this._lastError = null;
};
_proto.componentWillUnmount = function componentWillUnmount() {
if (this.__componentWillUnmount) this.__componentWillUnmount();
_proto.componentDidCatch = function componentDidCatch(error, init) {
if (this.__componentDidCatch) this.__componentDidCatch(error, init);
this.__atom.destructor();
this.__atom = null;
this._lastData = null;
this._lastError = null;
};
_proto.componentDidCatch = function componentDidCatch(error, init) {
if (this.__componentDidCatch) {
this.__componentDidCatch(error, init);
} else {
this._lastError = error;
this.forceUpdate();
};
}
};
_proto.__value = function __value(propsChanged) {
var data = null;
var context = this.context;
_proto._getContext = function _getContext(key, propsChanged) {
return this.context;
};
try {
if (this._lastError) throw this._lastError;
data = this.__render(this.props, this.__atom.extendContext(this.context, this.constructor, propsChanged));
this._lastData = data;
} catch (error) {
this._lastError = null;
_proto.__value = function __value(propsChanged) {
var data = null;
if (renderError) {
data = renderError.call(this, {
error: error,
children: this._lastData,
origProps: this.props
}, this.__atom.extendContext(this.context, renderError, propsChanged));
} else {
console.error(error);
}
try {
if (this._lastError) throw this._lastError;
data = this.__render(this.props, this._getContext(this.constructor, propsChanged));
this._lastData = data;
} catch (error) {
this._lastError = null;
if (this._renderError) {
data = this._renderError({
error: error,
children: this._lastData,
origProps: this.props
}, this._getContext(this._renderError, propsChanged));
} else {
throw error;
}
}
return data;
};
return data;
};
_proto.render = function render() {
return this.__atom.value();
};
_proto.render = function render() {
return this.__atom.value();
};
return AtomizedComponent;
}();
return AtomizedComponent;
}();
var replacement = AtomizedComponent.prototype;
var replacementKeys = Object.getOwnPropertyNames(replacement);
function mergeKeys(src, dest) {
for (var i = 0; i < src.length; i++) {
var key = src[i];
if (dest.indexOf(key) === -1) dest.push(key);
}
return dest;
}
function createConnect(_ref) {
var ReactAtom = _ref.ReactAtom,
renderError = _ref.renderError,
BaseComponent = _ref.BaseComponent,
MixinComponent = _ref.MixinComponent;
AtomizedComponent.ReactAtom = ReactAtom;
var replacement = (MixinComponent || AtomizedComponent).prototype;
replacement._renderError = renderError;
var keys = Object.getOwnPropertyNames(AtomizedComponent.prototype);
if (replacement !== AtomizedComponent.prototype) {
mergeKeys(Object.getOwnPropertyNames(replacement), keys);
}
var replacementKeys = keys.filter(function (prop) {
return prop !== 'constructor';
});
var names = new Map();
return function reactConnect(Parent) {
if (Parent.isConnected) throw new Error((Parent.displayName || Parent.name) + " already connected");
Parent.isConnected = true;
var cls = Parent;
if (cls.prototype.render === undefined && typeof Parent === 'function') {
if (typeof cls.prototype.render !== 'function' && typeof Parent === 'function') {
if (!BaseComponent) throw new Error('Setup createConnect with BaseComponent');
cls = function cls(props, context) {
cls = function ConnectedComponent(props, context) {
return BaseComponent.call(this, props, context) || this;

@@ -119,11 +147,24 @@ };

cls.displayName = Parent.displayName || Parent.name;
cls.contextTypes = Parent.contextTypes;
cls.propTypes = Parent.propTypes;
cls.defaultProps = Parent.defaultProps;
var props = Object.getOwnPropertyNames(Parent);
for (var i = 0; i < props.length; i++) {
var key = props[i];
if (!(key in cls)) cls[key] = Parent[key];
}
}
var prefix = names.get(cls.displayName);
if (prefix !== undefined) {
prefix++;
names.set(cls.displayName, prefix);
cls.displayName = cls.displayName + prefix;
} else {
names.set(cls.displayName, 0);
}
var target = cls.prototype;
for (var i = 0; i < replacementKeys.length; i++) {
var _key = replacementKeys[i];
for (var _i = 0; _i < replacementKeys.length; _i++) {
var _key = replacementKeys[_i];
if (_key in target) target['__' + _key] = target[_key];

@@ -137,3 +178,3 @@ target[_key] = replacement[_key];

export { createConnect };
export { createConnect, AtomizedComponent };
//# sourceMappingURL=urc.es.js.map

@@ -5,47 +5,35 @@ 'use strict';

function createConnect(_ref) {
var ReactAtom = _ref.ReactAtom,
renderError = _ref.renderError,
BaseComponent = _ref.BaseComponent;
var AtomizedComponent =
/*#__PURE__*/
function () {
function AtomizedComponent() {}
var AtomizedComponent =
/*#__PURE__*/
function () {
function AtomizedComponent() {}
var _proto = AtomizedComponent.prototype;
var _proto = AtomizedComponent.prototype;
_proto.componentWillMount = function componentWillMount() {
var props = this.props;
this._lastData = null;
this._lastError = null;
if (this.__componentWillMount) this.__componentWillMount();
this.__atom = new AtomizedComponent.ReactAtom(props && props.id ? props.id : this.constructor.displayName, this);
};
_proto.componentWillMount = function componentWillMount() {
var props = this.props;
this._lastData = null;
this._lastError = null;
if (this.__componentWillMount) this.__componentWillMount();
this.__atom = new ReactAtom(props && props.id ? props.id : this.constructor.displayName, this);
};
_proto.shouldComponentUpdate = function shouldComponentUpdate(props, state, context) {
var oldProps = this.props;
var count = 0;
_proto.shouldComponentUpdate = function shouldComponentUpdate(props, state, context) {
var oldProps = this.props;
var count = 0;
for (var k in oldProps) {
count++;
for (var k in oldProps) {
count++;
if (oldProps[k] !== props[k]) {
this.__atom.reset();
if (oldProps[k] !== props[k]) {
this.__atom.reset();
return true;
}
return true;
}
}
for (var _k in props) {
count--;
for (var _k in props) {
count--;
if (oldProps[_k] !== props[_k]) {
this.__atom.reset();
return true;
}
}
if (count !== 0) {
if (oldProps[_k] !== props[_k]) {
this.__atom.reset();

@@ -55,63 +43,103 @@

}
}
return this.__shouldComponentUpdate ? this.__shouldComponentUpdate(props, state, context) : false;
};
if (count !== 0) {
this.__atom.reset();
_proto.componentWillUnmount = function componentWillUnmount() {
if (this.__componentWillUnmount) this.__componentWillUnmount();
return true;
}
this.__atom.destructor();
return this.__shouldComponentUpdate ? this.__shouldComponentUpdate(props, state, context) : false;
};
this.__atom = null;
this._lastData = null;
this._lastError = null;
};
_proto.componentWillUnmount = function componentWillUnmount() {
if (this.__componentWillUnmount) this.__componentWillUnmount();
_proto.componentDidCatch = function componentDidCatch(error, init) {
if (this.__componentDidCatch) this.__componentDidCatch(error, init);
this.__atom.destructor();
this.__atom = null;
this._lastData = null;
this._lastError = null;
};
_proto.componentDidCatch = function componentDidCatch(error, init) {
if (this.__componentDidCatch) {
this.__componentDidCatch(error, init);
} else {
this._lastError = error;
this.forceUpdate();
};
}
};
_proto.__value = function __value(propsChanged) {
var data = null;
var context = this.context;
_proto._getContext = function _getContext(key, propsChanged) {
return this.context;
};
try {
if (this._lastError) throw this._lastError;
data = this.__render(this.props, this.__atom.extendContext(this.context, this.constructor, propsChanged));
this._lastData = data;
} catch (error) {
this._lastError = null;
_proto.__value = function __value(propsChanged) {
var data = null;
if (renderError) {
data = renderError.call(this, {
error: error,
children: this._lastData,
origProps: this.props
}, this.__atom.extendContext(this.context, renderError, propsChanged));
} else {
console.error(error);
}
try {
if (this._lastError) throw this._lastError;
data = this.__render(this.props, this._getContext(this.constructor, propsChanged));
this._lastData = data;
} catch (error) {
this._lastError = null;
if (this._renderError) {
data = this._renderError({
error: error,
children: this._lastData,
origProps: this.props
}, this._getContext(this._renderError, propsChanged));
} else {
throw error;
}
}
return data;
};
return data;
};
_proto.render = function render() {
return this.__atom.value();
};
_proto.render = function render() {
return this.__atom.value();
};
return AtomizedComponent;
}();
return AtomizedComponent;
}();
var replacement = AtomizedComponent.prototype;
var replacementKeys = Object.getOwnPropertyNames(replacement);
function mergeKeys(src, dest) {
for (var i = 0; i < src.length; i++) {
var key = src[i];
if (dest.indexOf(key) === -1) dest.push(key);
}
return dest;
}
function createConnect(_ref) {
var ReactAtom = _ref.ReactAtom,
renderError = _ref.renderError,
BaseComponent = _ref.BaseComponent,
MixinComponent = _ref.MixinComponent;
AtomizedComponent.ReactAtom = ReactAtom;
var replacement = (MixinComponent || AtomizedComponent).prototype;
replacement._renderError = renderError;
var keys = Object.getOwnPropertyNames(AtomizedComponent.prototype);
if (replacement !== AtomizedComponent.prototype) {
mergeKeys(Object.getOwnPropertyNames(replacement), keys);
}
var replacementKeys = keys.filter(function (prop) {
return prop !== 'constructor';
});
var names = new Map();
return function reactConnect(Parent) {
if (Parent.isConnected) throw new Error((Parent.displayName || Parent.name) + " already connected");
Parent.isConnected = true;
var cls = Parent;
if (cls.prototype.render === undefined && typeof Parent === 'function') {
if (typeof cls.prototype.render !== 'function' && typeof Parent === 'function') {
if (!BaseComponent) throw new Error('Setup createConnect with BaseComponent');
cls = function cls(props, context) {
cls = function ConnectedComponent(props, context) {
return BaseComponent.call(this, props, context) || this;

@@ -124,11 +152,24 @@ };

cls.displayName = Parent.displayName || Parent.name;
cls.contextTypes = Parent.contextTypes;
cls.propTypes = Parent.propTypes;
cls.defaultProps = Parent.defaultProps;
var props = Object.getOwnPropertyNames(Parent);
for (var i = 0; i < props.length; i++) {
var key = props[i];
if (!(key in cls)) cls[key] = Parent[key];
}
}
var prefix = names.get(cls.displayName);
if (prefix !== undefined) {
prefix++;
names.set(cls.displayName, prefix);
cls.displayName = cls.displayName + prefix;
} else {
names.set(cls.displayName, 0);
}
var target = cls.prototype;
for (var i = 0; i < replacementKeys.length; i++) {
var _key = replacementKeys[i];
for (var _i = 0; _i < replacementKeys.length; _i++) {
var _key = replacementKeys[_i];
if (_key in target) target['__' + _key] = target[_key];

@@ -143,2 +184,3 @@ target[_key] = replacement[_key];

exports.createConnect = createConnect;
exports.AtomizedComponent = AtomizedComponent;
//# sourceMappingURL=urc.js.map

@@ -7,47 +7,35 @@ (function (global, factory) {

function createConnect(_ref) {
var ReactAtom = _ref.ReactAtom,
renderError = _ref.renderError,
BaseComponent = _ref.BaseComponent;
var AtomizedComponent =
/*#__PURE__*/
function () {
function AtomizedComponent() {}
var AtomizedComponent =
/*#__PURE__*/
function () {
function AtomizedComponent() {}
var _proto = AtomizedComponent.prototype;
var _proto = AtomizedComponent.prototype;
_proto.componentWillMount = function componentWillMount() {
var props = this.props;
this._lastData = null;
this._lastError = null;
if (this.__componentWillMount) this.__componentWillMount();
this.__atom = new AtomizedComponent.ReactAtom(props && props.id ? props.id : this.constructor.displayName, this);
};
_proto.componentWillMount = function componentWillMount() {
var props = this.props;
this._lastData = null;
this._lastError = null;
if (this.__componentWillMount) this.__componentWillMount();
this.__atom = new ReactAtom(props && props.id ? props.id : this.constructor.displayName, this);
};
_proto.shouldComponentUpdate = function shouldComponentUpdate(props, state, context) {
var oldProps = this.props;
var count = 0;
_proto.shouldComponentUpdate = function shouldComponentUpdate(props, state, context) {
var oldProps = this.props;
var count = 0;
for (var k in oldProps) {
count++;
for (var k in oldProps) {
count++;
if (oldProps[k] !== props[k]) {
this.__atom.reset();
if (oldProps[k] !== props[k]) {
this.__atom.reset();
return true;
}
return true;
}
}
for (var _k in props) {
count--;
for (var _k in props) {
count--;
if (oldProps[_k] !== props[_k]) {
this.__atom.reset();
return true;
}
}
if (count !== 0) {
if (oldProps[_k] !== props[_k]) {
this.__atom.reset();

@@ -57,63 +45,103 @@

}
}
return this.__shouldComponentUpdate ? this.__shouldComponentUpdate(props, state, context) : false;
};
if (count !== 0) {
this.__atom.reset();
_proto.componentWillUnmount = function componentWillUnmount() {
if (this.__componentWillUnmount) this.__componentWillUnmount();
return true;
}
this.__atom.destructor();
return this.__shouldComponentUpdate ? this.__shouldComponentUpdate(props, state, context) : false;
};
this.__atom = null;
this._lastData = null;
this._lastError = null;
};
_proto.componentWillUnmount = function componentWillUnmount() {
if (this.__componentWillUnmount) this.__componentWillUnmount();
_proto.componentDidCatch = function componentDidCatch(error, init) {
if (this.__componentDidCatch) this.__componentDidCatch(error, init);
this.__atom.destructor();
this.__atom = null;
this._lastData = null;
this._lastError = null;
};
_proto.componentDidCatch = function componentDidCatch(error, init) {
if (this.__componentDidCatch) {
this.__componentDidCatch(error, init);
} else {
this._lastError = error;
this.forceUpdate();
};
}
};
_proto.__value = function __value(propsChanged) {
var data = null;
var context = this.context;
_proto._getContext = function _getContext(key, propsChanged) {
return this.context;
};
try {
if (this._lastError) throw this._lastError;
data = this.__render(this.props, this.__atom.extendContext(this.context, this.constructor, propsChanged));
this._lastData = data;
} catch (error) {
this._lastError = null;
_proto.__value = function __value(propsChanged) {
var data = null;
if (renderError) {
data = renderError.call(this, {
error: error,
children: this._lastData,
origProps: this.props
}, this.__atom.extendContext(this.context, renderError, propsChanged));
} else {
console.error(error);
}
try {
if (this._lastError) throw this._lastError;
data = this.__render(this.props, this._getContext(this.constructor, propsChanged));
this._lastData = data;
} catch (error) {
this._lastError = null;
if (this._renderError) {
data = this._renderError({
error: error,
children: this._lastData,
origProps: this.props
}, this._getContext(this._renderError, propsChanged));
} else {
throw error;
}
}
return data;
};
return data;
};
_proto.render = function render() {
return this.__atom.value();
};
_proto.render = function render() {
return this.__atom.value();
};
return AtomizedComponent;
}();
return AtomizedComponent;
}();
var replacement = AtomizedComponent.prototype;
var replacementKeys = Object.getOwnPropertyNames(replacement);
function mergeKeys(src, dest) {
for (var i = 0; i < src.length; i++) {
var key = src[i];
if (dest.indexOf(key) === -1) dest.push(key);
}
return dest;
}
function createConnect(_ref) {
var ReactAtom = _ref.ReactAtom,
renderError = _ref.renderError,
BaseComponent = _ref.BaseComponent,
MixinComponent = _ref.MixinComponent;
AtomizedComponent.ReactAtom = ReactAtom;
var replacement = (MixinComponent || AtomizedComponent).prototype;
replacement._renderError = renderError;
var keys = Object.getOwnPropertyNames(AtomizedComponent.prototype);
if (replacement !== AtomizedComponent.prototype) {
mergeKeys(Object.getOwnPropertyNames(replacement), keys);
}
var replacementKeys = keys.filter(function (prop) {
return prop !== 'constructor';
});
var names = new Map();
return function reactConnect(Parent) {
if (Parent.isConnected) throw new Error((Parent.displayName || Parent.name) + " already connected");
Parent.isConnected = true;
var cls = Parent;
if (cls.prototype.render === undefined && typeof Parent === 'function') {
if (typeof cls.prototype.render !== 'function' && typeof Parent === 'function') {
if (!BaseComponent) throw new Error('Setup createConnect with BaseComponent');
cls = function cls(props, context) {
cls = function ConnectedComponent(props, context) {
return BaseComponent.call(this, props, context) || this;

@@ -126,11 +154,24 @@ };

cls.displayName = Parent.displayName || Parent.name;
cls.contextTypes = Parent.contextTypes;
cls.propTypes = Parent.propTypes;
cls.defaultProps = Parent.defaultProps;
var props = Object.getOwnPropertyNames(Parent);
for (var i = 0; i < props.length; i++) {
var key = props[i];
if (!(key in cls)) cls[key] = Parent[key];
}
}
var prefix = names.get(cls.displayName);
if (prefix !== undefined) {
prefix++;
names.set(cls.displayName, prefix);
cls.displayName = cls.displayName + prefix;
} else {
names.set(cls.displayName, 0);
}
var target = cls.prototype;
for (var i = 0; i < replacementKeys.length; i++) {
var _key = replacementKeys[i];
for (var _i = 0; _i < replacementKeys.length; _i++) {
var _key = replacementKeys[_i];
if (_key in target) target['__' + _key] = target[_key];

@@ -145,2 +186,3 @@ target[_key] = replacement[_key];

exports.createConnect = createConnect;
exports.AtomizedComponent = AtomizedComponent;

@@ -147,0 +189,0 @@ Object.defineProperty(exports, '__esModule', { value: true });

{
"name": "urc",
"version": "1.0.2",
"version": "1.0.3",
"description": "Universal react connect decorator builder",

@@ -19,3 +19,3 @@ "publishConfig": {

"release": "npm test && npm run build && standard-version && git push --follow-tags origin master && npm publish",
"build": "rimraf dist && rollup -c && cp index.js.flow.tpl $npm_package_main.flow && cp index.js.flow.tpl $npm_package_module.flow",
"build": "rimraf dist && rollup -c && cp index.js.flow.tpl $npm_package_main.flow && cp createMobxAtom.js.flow.tpl dist/createMobxAtom.js.flow",
"test": "flow check",

@@ -22,0 +22,0 @@ "test.dev": "mocha --growl --watch",

@@ -32,22 +32,25 @@ import babel from 'rollup-plugin-babel'

}
//console.log(JSON.stringify(babelrc,0,' '))
const commonConf = {
input: 'src/index.js',
plugins: [
babel(babelrc)
].concat(process.env.UGLIFY === '1' ? [uglify(uglifyOpts, minify)] : []),
output: [
{sourcemap: true, file: pkg.module, format: 'es'},
function getOutput(name) {
return [
{sourcemap: true, file: `dist/${name}.es.js`, format: 'es'},
{sourcemap: true, file: `dist/${name}.js`, format: 'cjs'},
{sourcemap: true, file: `dist/${name}.umd.js`, format: 'umd', name: name}
]
}
const plugins = [
babel(babelrc)
].concat(process.env.UGLIFY === '1' ? [uglify(uglifyOpts, minify)] : [])
export default [
commonConf,
Object.assign({}, commonConf, {
output: [
{sourcemap: true, file: pkg.main, format: 'cjs'},
{sourcemap: true, file: pkg['umd:main'], format: 'umd', name: pkg.name}
]
})
{
input: 'src/index.js',
plugins,
output: getOutput(pkg.name)
},
{
input: 'src/createMobxAtom.js',
plugins,
output: getOutput('createMobxAtom')
}
]
// @flow
import type {IReactAtom, IRenderError, IReactHost} from './interfaces'
import AtomizedComponent from './AtomizedComponent'
export interface IReactHost<Element> {
__value(propsChanged: boolean): Element;
forceUpdate(): void;
function mergeKeys(src: string[], dest: string[]): string[] {
for (let i = 0; i < src.length; i++) {
const key = src[i]
if (dest.indexOf(key) === -1) dest.push(key)
}
return dest
}
export interface IReactAtom<Element> {
constructor(displayName: string, owner: IReactHost<Element>): self;
reset(): void;
destructor(): void;
value(): Element;
extendContext<Src, Dest: Src>(context: Src, key: Function, propsChanged: boolean): Dest;
}
type ErrorProps = {error: Error, children: any}
export type IRenderError<Element, Context> = (props: ErrorProps, context: Context) => Element
export default function createConnect<Element>(
{ReactAtom, renderError, BaseComponent}: {
{ReactAtom, renderError, BaseComponent, MixinComponent}: {
ReactAtom: Class<IReactAtom<Element>>;
renderError?: IRenderError<Element, *>;
BaseComponent?: Function;
MixinComponent?: Class<IReactHost<Element>>
}
) {
class AtomizedComponent<Props: Object, State, Context> implements IReactHost<Element> {
static displayName: string
props: Props
context: Context
AtomizedComponent.ReactAtom = (ReactAtom: Class<IReactAtom<any>>)
const replacement: Object = (MixinComponent || AtomizedComponent).prototype
replacement._renderError = renderError
let keys = Object.getOwnPropertyNames(AtomizedComponent.prototype)
if (replacement !== AtomizedComponent.prototype) {
mergeKeys(Object.getOwnPropertyNames(replacement), keys)
}
__atom: IReactAtom<Element>
_lastData: ?Element
const replacementKeys: string[] = keys
.filter((prop) => prop !== 'constructor')
__componentWillMount: void | () => void
__componentWillUnmount: void | () => void
__shouldComponentUpdate: void | (props: Props, state: State, context: Context) => boolean
__render: (props: Props, context: Context) => Element
__componentDidCatch: (error: Error, init: any) => void;
const names: Map<string, number> = new Map()
forceUpdate: () => void
componentWillMount() {
const props = this.props
this._lastData = null
this._lastError = null
if (this.__componentWillMount) this.__componentWillMount()
this.__atom = new ReactAtom(
props && props.id
? props.id
: this.constructor.displayName,
this
)
}
shouldComponentUpdate(props: Props, state: State, context: Context) {
const oldProps = this.props
let count = 0
for (let k in oldProps) {
count++
if (oldProps[k] !== props[k]) {
this.__atom.reset()
return true
}
}
for (let k in props) {
count--
if (oldProps[k] !== props[k]) {
this.__atom.reset()
return true
}
}
if (count !== 0) {
this.__atom.reset()
return true
}
return this.__shouldComponentUpdate ? this.__shouldComponentUpdate(props, state, context) : false
}
componentWillUnmount() {
if (this.__componentWillUnmount) this.__componentWillUnmount()
this.__atom.destructor()
this.__atom = (null: any)
this._lastData = null
this._lastError = null
}
_lastError: ?Error
componentDidCatch(error: Error, init: any) {
if (this.__componentDidCatch) this.__componentDidCatch(error, init)
this._lastError = error
this.forceUpdate()
}
__value(propsChanged: boolean): Element {
let data: Element = (null: any)
const context = this.context
try {
if (this._lastError) throw this._lastError
data = this.__render(
this.props,
this.__atom.extendContext(this.context, this.constructor, propsChanged)
)
this._lastData = data
} catch (error) {
this._lastError = null
if (renderError) {
data = renderError.call(
this,
{error, children: this._lastData, origProps: this.props},
this.__atom.extendContext(this.context, renderError, propsChanged)
)
} else {
console.error(error)
}
}
return data
}
render(): Element {
return this.__atom.value()
}
}
const replacement: Object = AtomizedComponent.prototype
const replacementKeys: string[] = Object.getOwnPropertyNames(replacement)
return function reactConnect<ComponentClass: Function>(
Parent: ComponentClass
): ComponentClass {
if (Parent.isConnected) throw new Error(`${Parent.displayName || Parent.name} already connected`)
Parent.isConnected = true
let cls = Parent
if (cls.prototype.render === undefined && typeof Parent === 'function') {
if (typeof cls.prototype.render !== 'function' && typeof Parent === 'function') {
if (!BaseComponent) throw new Error('Setup createConnect with BaseComponent')
cls = function(props, context) {
cls = function ConnectedComponent(props, context) {
return BaseComponent.call(this, props, context) || this

@@ -143,7 +50,18 @@ }

cls.displayName = Parent.displayName || Parent.name
cls.contextTypes = Parent.contextTypes
cls.propTypes = Parent.propTypes
cls.defaultProps = Parent.defaultProps
const props = Object.getOwnPropertyNames(Parent)
for (let i = 0; i < props.length; i++) {
const key = props[i]
if (!(key in cls)) cls[key] = Parent[key]
}
}
let prefix = names.get(cls.displayName)
if (prefix !== undefined) {
prefix++
names.set(cls.displayName, prefix)
cls.displayName = cls.displayName + prefix
} else {
names.set(cls.displayName, 0)
}
const target = cls.prototype

@@ -150,0 +68,0 @@ for (let i = 0; i < replacementKeys.length; i++) {

// @flow
import type {IReactAtom, IReactHost} from './createConnect'
import type {IReactAtom, IReactHost} from './interfaces'

@@ -53,6 +53,2 @@ interface IMobxReaction {

extendContext<Src, Dest: Src>(context: Src, key: Function, propsChanged: boolean): Dest {
return (context: any)
}
destructor() {

@@ -59,0 +55,0 @@ this._reaction.dispose()

// @flow
import type {IReactAtom, IReactHost} from './createConnect'
export type {IReactAtom, IReactHost, IRenderError, ErrorProps} from './interfaces'
export {default as createConnect} from './createConnect'
export type {
IReactHost,
IReactAtom
}
export {default as AtomizedComponent} from './AtomizedComponent'

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