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

react-clientside-effect

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-clientside-effect - npm Package Compare versions

Comparing version 1.0.0 to 1.2.0

56

lib/index.es.js

@@ -0,17 +1,16 @@

import _inheritsLoose from '@babel/runtime/helpers/inheritsLoose';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import React, { Component } from 'react';
import shallowEqual from 'shallowequal';
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function withSideEffect(reducePropsToState, handleStateChangeOnClient) {
if (process.env.NODE_ENV !== "production") {
if (typeof reducePropsToState !== 'function') {
throw new Error('Expected reducePropsToState to be a function.');
}
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
function withSideEffect(reducePropsToState, handleStateChangeOnClient) {
if (typeof reducePropsToState !== 'function') {
throw new Error('Expected reducePropsToState to be a function.');
if (typeof handleStateChangeOnClient !== 'function') {
throw new Error('Expected handleStateChangeOnClient to be a function.');
}
}
if (typeof handleStateChangeOnClient !== 'function') {
throw new Error('Expected handleStateChangeOnClient to be a function.');
}

@@ -23,8 +22,10 @@ function getDisplayName(WrappedComponent) {

return function wrap(WrappedComponent) {
if (typeof WrappedComponent !== 'function') {
throw new Error('Expected WrappedComponent to be a React component.');
if (process.env.NODE_ENV !== "production") {
if (typeof WrappedComponent !== 'function') {
throw new Error('Expected WrappedComponent to be a React component.');
}
}
var mountedInstances = [];
var state = void 0;
var state;

@@ -35,26 +36,26 @@ function emitChange() {

}));
handleStateChangeOnClient(state);
}
var SideEffect = function (_Component) {
_inherits(SideEffect, _Component);
var SideEffect =
/*#__PURE__*/
function (_Component) {
_inheritsLoose(SideEffect, _Component);
function SideEffect() {
_classCallCheck(this, SideEffect);
return _possibleConstructorReturn(this, _Component.apply(this, arguments));
return _Component.apply(this, arguments) || this;
}
// Try to use displayName of wrapped component
SideEffect.peek = function peek() {
return state;
};
// Try to use displayName of wrapped component
var _proto = SideEffect.prototype;
SideEffect.prototype.shouldComponentUpdate = function shouldComponentUpdate(nextProps) {
_proto.shouldComponentUpdate = function shouldComponentUpdate(nextProps) {
return !shallowEqual(nextProps, this.props);
};
SideEffect.prototype.componentDidMount = function componentDidMount() {
_proto.componentDidMount = function componentDidMount() {
mountedInstances.push(this);

@@ -64,7 +65,7 @@ emitChange();

SideEffect.prototype.componentDidUpdate = function componentDidUpdate() {
_proto.componentDidUpdate = function componentDidUpdate() {
emitChange();
};
SideEffect.prototype.componentWillUnmount = function componentWillUnmount() {
_proto.componentWillUnmount = function componentWillUnmount() {
var index = mountedInstances.indexOf(this);

@@ -75,3 +76,3 @@ mountedInstances.splice(index, 1);

SideEffect.prototype.render = function render() {
_proto.render = function render() {
return React.createElement(WrappedComponent, this.props);

@@ -83,5 +84,4 @@ };

SideEffect.displayName = 'SideEffect(' + getDisplayName(WrappedComponent) + ')';
_defineProperty(SideEffect, "displayName", "SideEffect(" + getDisplayName(WrappedComponent) + ")");
return SideEffect;

@@ -88,0 +88,0 @@ };

@@ -5,2 +5,4 @@ 'use strict';

var _inheritsLoose = _interopDefault(require('@babel/runtime/helpers/inheritsLoose'));
var _defineProperty = _interopDefault(require('@babel/runtime/helpers/defineProperty'));
var React = require('react');

@@ -10,15 +12,12 @@ var React__default = _interopDefault(React);

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function withSideEffect(reducePropsToState, handleStateChangeOnClient) {
if (process.env.NODE_ENV !== "production") {
if (typeof reducePropsToState !== 'function') {
throw new Error('Expected reducePropsToState to be a function.');
}
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
function withSideEffect(reducePropsToState, handleStateChangeOnClient) {
if (typeof reducePropsToState !== 'function') {
throw new Error('Expected reducePropsToState to be a function.');
if (typeof handleStateChangeOnClient !== 'function') {
throw new Error('Expected handleStateChangeOnClient to be a function.');
}
}
if (typeof handleStateChangeOnClient !== 'function') {
throw new Error('Expected handleStateChangeOnClient to be a function.');
}

@@ -30,8 +29,10 @@ function getDisplayName(WrappedComponent) {

return function wrap(WrappedComponent) {
if (typeof WrappedComponent !== 'function') {
throw new Error('Expected WrappedComponent to be a React component.');
if (process.env.NODE_ENV !== "production") {
if (typeof WrappedComponent !== 'function') {
throw new Error('Expected WrappedComponent to be a React component.');
}
}
var mountedInstances = [];
var state = void 0;
var state;

@@ -42,26 +43,26 @@ function emitChange() {

}));
handleStateChangeOnClient(state);
}
var SideEffect = function (_Component) {
_inherits(SideEffect, _Component);
var SideEffect =
/*#__PURE__*/
function (_Component) {
_inheritsLoose(SideEffect, _Component);
function SideEffect() {
_classCallCheck(this, SideEffect);
return _possibleConstructorReturn(this, _Component.apply(this, arguments));
return _Component.apply(this, arguments) || this;
}
// Try to use displayName of wrapped component
SideEffect.peek = function peek() {
return state;
};
// Try to use displayName of wrapped component
var _proto = SideEffect.prototype;
SideEffect.prototype.shouldComponentUpdate = function shouldComponentUpdate(nextProps) {
_proto.shouldComponentUpdate = function shouldComponentUpdate(nextProps) {
return !shallowEqual(nextProps, this.props);
};
SideEffect.prototype.componentDidMount = function componentDidMount() {
_proto.componentDidMount = function componentDidMount() {
mountedInstances.push(this);

@@ -71,7 +72,7 @@ emitChange();

SideEffect.prototype.componentDidUpdate = function componentDidUpdate() {
_proto.componentDidUpdate = function componentDidUpdate() {
emitChange();
};
SideEffect.prototype.componentWillUnmount = function componentWillUnmount() {
_proto.componentWillUnmount = function componentWillUnmount() {
var index = mountedInstances.indexOf(this);

@@ -82,3 +83,3 @@ mountedInstances.splice(index, 1);

SideEffect.prototype.render = function render() {
_proto.render = function render() {
return React__default.createElement(WrappedComponent, this.props);

@@ -90,5 +91,4 @@ };

SideEffect.displayName = 'SideEffect(' + getDisplayName(WrappedComponent) + ')';
_defineProperty(SideEffect, "displayName", "SideEffect(" + getDisplayName(WrappedComponent) + ")");
return SideEffect;

@@ -95,0 +95,0 @@ };

(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('react')) :
typeof define === 'function' && define.amd ? define(['react'], factory) :
(global.withSideEffect = factory(global.React));
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('react')) :
typeof define === 'function' && define.amd ? define(['react'], factory) :
(global.withSideEffect = factory(global.React));
}(this, (function (React) { 'use strict';
var React__default = 'default' in React ? React['default'] : React;
var React__default = 'default' in React ? React['default'] : React;
//
function _inheritsLoose(subClass, superClass) {
subClass.prototype = Object.create(superClass.prototype);
subClass.prototype.constructor = subClass;
subClass.__proto__ = superClass;
}
var shallowequal = function shallowEqual(objA, objB, compare, compareContext) {
var ret = compare ? compare.call(compareContext, objA, objB) : void 0;
var inheritsLoose = _inheritsLoose;
if (ret !== void 0) {
return !!ret;
}
function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
if (objA === objB) {
return true;
return obj;
}
if (typeof objA !== "object" || !objA || typeof objB !== "object" || !objB) {
return false;
}
var defineProperty = _defineProperty;
var keysA = Object.keys(objA);
var keysB = Object.keys(objB);
//
if (keysA.length !== keysB.length) {
return false;
}
var shallowequal = function shallowEqual(objA, objB, compare, compareContext) {
var ret = compare ? compare.call(compareContext, objA, objB) : void 0;
var bHasOwnProperty = Object.prototype.hasOwnProperty.bind(objB);
if (ret !== void 0) {
return !!ret;
}
// Test for A's keys different from B.
for (var idx = 0; idx < keysA.length; idx++) {
var key = keysA[idx];
if (objA === objB) {
return true;
}
if (!bHasOwnProperty(key)) {
if (typeof objA !== "object" || !objA || typeof objB !== "object" || !objB) {
return false;
}
var valueA = objA[key];
var valueB = objB[key];
var keysA = Object.keys(objA);
var keysB = Object.keys(objB);
ret = compare ? compare.call(compareContext, valueA, valueB, key) : void 0;
if (ret === false || (ret === void 0 && valueA !== valueB)) {
if (keysA.length !== keysB.length) {
return false;
}
}
return true;
};
var bHasOwnProperty = Object.prototype.hasOwnProperty.bind(objB);
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
// Test for A's keys different from B.
for (var idx = 0; idx < keysA.length; idx++) {
var key = keysA[idx];
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
if (!bHasOwnProperty(key)) {
return false;
}
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var valueA = objA[key];
var valueB = objB[key];
function withSideEffect(reducePropsToState, handleStateChangeOnClient) {
if (typeof reducePropsToState !== 'function') {
throw new Error('Expected reducePropsToState to be a function.');
}
if (typeof handleStateChangeOnClient !== 'function') {
throw new Error('Expected handleStateChangeOnClient to be a function.');
}
ret = compare ? compare.call(compareContext, valueA, valueB, key) : void 0;
function getDisplayName(WrappedComponent) {
return WrappedComponent.displayName || WrappedComponent.name || 'Component';
}
return function wrap(WrappedComponent) {
if (typeof WrappedComponent !== 'function') {
throw new Error('Expected WrappedComponent to be a React component.');
if (ret === false || (ret === void 0 && valueA !== valueB)) {
return false;
}
}
var mountedInstances = [];
var state = void 0;
return true;
};
function emitChange() {
state = reducePropsToState(mountedInstances.map(function (instance) {
return instance.props;
}));
function withSideEffect(reducePropsToState, handleStateChangeOnClient) {
if (process.env.NODE_ENV !== "production") {
if (typeof reducePropsToState !== 'function') {
throw new Error('Expected reducePropsToState to be a function.');
}
handleStateChangeOnClient(state);
if (typeof handleStateChangeOnClient !== 'function') {
throw new Error('Expected handleStateChangeOnClient to be a function.');
}
}
var SideEffect = function (_Component) {
_inherits(SideEffect, _Component);
function getDisplayName(WrappedComponent) {
return WrappedComponent.displayName || WrappedComponent.name || 'Component';
}
function SideEffect() {
_classCallCheck(this, SideEffect);
return function wrap(WrappedComponent) {
if (process.env.NODE_ENV !== "production") {
if (typeof WrappedComponent !== 'function') {
throw new Error('Expected WrappedComponent to be a React component.');
}
}
return _possibleConstructorReturn(this, _Component.apply(this, arguments));
var mountedInstances = [];
var state;
function emitChange() {
state = reducePropsToState(mountedInstances.map(function (instance) {
return instance.props;
}));
handleStateChangeOnClient(state);
}
SideEffect.peek = function peek() {
return state;
};
// Try to use displayName of wrapped component
var SideEffect =
/*#__PURE__*/
function (_Component) {
inheritsLoose(SideEffect, _Component);
function SideEffect() {
return _Component.apply(this, arguments) || this;
}
SideEffect.prototype.shouldComponentUpdate = function shouldComponentUpdate(nextProps) {
return !shallowequal(nextProps, this.props);
};
// Try to use displayName of wrapped component
SideEffect.peek = function peek() {
return state;
};
SideEffect.prototype.componentDidMount = function componentDidMount() {
mountedInstances.push(this);
emitChange();
};
var _proto = SideEffect.prototype;
SideEffect.prototype.componentDidUpdate = function componentDidUpdate() {
emitChange();
};
_proto.shouldComponentUpdate = function shouldComponentUpdate(nextProps) {
return !shallowequal(nextProps, this.props);
};
SideEffect.prototype.componentWillUnmount = function componentWillUnmount() {
var index = mountedInstances.indexOf(this);
mountedInstances.splice(index, 1);
emitChange();
};
_proto.componentDidMount = function componentDidMount() {
mountedInstances.push(this);
emitChange();
};
SideEffect.prototype.render = function render() {
return React__default.createElement(WrappedComponent, this.props);
};
_proto.componentDidUpdate = function componentDidUpdate() {
emitChange();
};
return SideEffect;
}(React.Component);
_proto.componentWillUnmount = function componentWillUnmount() {
var index = mountedInstances.indexOf(this);
mountedInstances.splice(index, 1);
emitChange();
};
SideEffect.displayName = 'SideEffect(' + getDisplayName(WrappedComponent) + ')';
_proto.render = function render() {
return React__default.createElement(WrappedComponent, this.props);
};
return SideEffect;
}(React.Component);
return SideEffect;
};
}
defineProperty(SideEffect, "displayName", "SideEffect(" + getDisplayName(WrappedComponent) + ")");
return withSideEffect;
return SideEffect;
};
}
return withSideEffect;
})));

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

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("react")):"function"==typeof define&&define.amd?define(["react"],e):t.withSideEffect=e(t.React)}(this,function(t){"use strict";var e="default"in t?t.default:t,n=function(t,e,n,o){var r=n?n.call(o,t,e):void 0;if(void 0!==r)return!!r;if(t===e)return!0;if("object"!=typeof t||!t||"object"!=typeof e||!e)return!1;var i=Object.keys(t),f=Object.keys(e);if(i.length!==f.length)return!1;for(var p=Object.prototype.hasOwnProperty.bind(e),u=0;u<i.length;u++){var c=i[u];if(!p(c))return!1;var a=t[c],s=e[c];if(!1===(r=n?n.call(o,a,s,c):void 0)||void 0===r&&a!==s)return!1}return!0};return function(o,r){if("function"!=typeof o)throw new Error("Expected reducePropsToState to be a function.");if("function"!=typeof r)throw new Error("Expected handleStateChangeOnClient to be a function.");return function(i){if("function"!=typeof i)throw new Error("Expected WrappedComponent to be a React component.");var f=[],p=void 0;function u(){p=o(f.map(function(t){return t.props})),r(p)}var c=function(t){function o(){return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,o),function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}(this,t.apply(this,arguments))}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}(o,t),o.peek=function(){return p},o.prototype.shouldComponentUpdate=function(t){return!n(t,this.props)},o.prototype.componentDidMount=function(){f.push(this),u()},o.prototype.componentDidUpdate=function(){u()},o.prototype.componentWillUnmount=function(){var t=f.indexOf(this);f.splice(t,1),u()},o.prototype.render=function(){return e.createElement(i,this.props)},o}(t.Component);return c.displayName="SideEffect("+function(t){return t.displayName||t.name||"Component"}(i)+")",c}}});
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("react")):"function"==typeof define&&define.amd?define(["react"],t):e.withSideEffect=t(e.React)}(this,function(e){"use strict";var t="default"in e?e.default:e;var n=function(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t};var o=function(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e},r=function(e,t,n,o){var r=n?n.call(o,e,t):void 0;if(void 0!==r)return!!r;if(e===t)return!0;if("object"!=typeof e||!e||"object"!=typeof t||!t)return!1;var i=Object.keys(e),u=Object.keys(t);if(i.length!==u.length)return!1;for(var c=Object.prototype.hasOwnProperty.bind(t),p=0;p<i.length;p++){var f=i[p];if(!c(f))return!1;var a=e[f],d=t[f];if(!1===(r=n?n.call(o,a,d,f):void 0)||void 0===r&&a!==d)return!1}return!0};return function(i,u){if("production"!==process.env.NODE_ENV){if("function"!=typeof i)throw new Error("Expected reducePropsToState to be a function.");if("function"!=typeof u)throw new Error("Expected handleStateChangeOnClient to be a function.")}return function(c){if("production"!==process.env.NODE_ENV&&"function"!=typeof c)throw new Error("Expected WrappedComponent to be a React component.");var p,f=[];function a(){p=i(f.map(function(e){return e.props})),u(p)}var d=function(e){function o(){return e.apply(this,arguments)||this}n(o,e),o.peek=function(){return p};var i=o.prototype;return i.shouldComponentUpdate=function(e){return!r(e,this.props)},i.componentDidMount=function(){f.push(this),a()},i.componentDidUpdate=function(){a()},i.componentWillUnmount=function(){var e=f.indexOf(this);f.splice(e,1),a()},i.render=function(){return t.createElement(c,this.props)},o}(e.Component);return o(d,"displayName","SideEffect("+function(e){return e.displayName||e.name||"Component"}(c)+")"),d}}});
{
"name": "react-clientside-effect",
"version": "1.0.0",
"version": "1.2.0",
"description": "Create components whose prop changes map to a global side effect",
"main": "lib/index.js",
"jsnext:main": "lib/index.es.js",
"module": "lib/index.es.js",
"scripts": {

@@ -37,13 +39,16 @@ "build": "node scripts/build.js",

"dependencies": {
"@babel/runtime": "^7.0.0",
"shallowequal": "^1.1.0"
},
"devDependencies": {
"babel-cli": "^6.18.0",
"babel-core": "^6.21.0",
"@babel/cli": "^7.0.0",
"@babel/core": "^7.0.0",
"@babel/node": "^7.0.0",
"@babel/plugin-proposal-class-properties": "^7.0.0",
"@babel/plugin-proposal-object-rest-spread": "^7.0.0",
"@babel/plugin-transform-runtime": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"@babel/preset-react": "^7.0.0",
"@babel/register": "^7.0.0",
"babel-plugin-add-module-exports": "^0.2.1",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-preset-env": "^1.6.0",
"babel-preset-react": "^6.16.0",
"babel-register": "^6.18.0",
"chai": "^3.2.0",

@@ -62,4 +67,4 @@ "enzyme": "^2.7.0",

"rimraf": "^2.4.3",
"rollup": "^0.56.2",
"rollup-plugin-babel": "^3.0.2",
"rollup": "^0.67.1",
"rollup-plugin-babel": "^4.0.3",
"rollup-plugin-commonjs": "^8.3.0",

@@ -66,0 +71,0 @@ "rollup-plugin-node-resolve": "^3.0.3",

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