react-side-effect
Advanced tools
+37
-20
| import React, { Component } from 'react'; | ||
| import ExecutionEnvironment from 'exenv'; | ||
| import shallowEqual from 'shallowequal'; | ||
| function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
| 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; | ||
| } | ||
| 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; } | ||
| return obj; | ||
| } | ||
| 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 _inheritsLoose(subClass, superClass) { | ||
| subClass.prototype = Object.create(superClass.prototype); | ||
| subClass.prototype.constructor = subClass; | ||
| subClass.__proto__ = superClass; | ||
| } | ||
| var canUseDOM = !!(typeof window !== 'undefined' && window.document && window.document.createElement); | ||
| function withSideEffect(reducePropsToState, handleStateChangeOnClient, mapStateOnServer) { | ||
@@ -15,5 +30,7 @@ if (typeof reducePropsToState !== 'function') { | ||
| } | ||
| if (typeof handleStateChangeOnClient !== 'function') { | ||
| throw new Error('Expected handleStateChangeOnClient to be a function.'); | ||
| } | ||
| if (typeof mapStateOnServer !== 'undefined' && typeof mapStateOnServer !== 'function') { | ||
@@ -33,3 +50,3 @@ throw new Error('Expected mapStateOnServer to either be undefined or a function.'); | ||
| var mountedInstances = []; | ||
| var state = void 0; | ||
| var state; | ||
@@ -48,12 +65,13 @@ function emitChange() { | ||
| 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 | ||
| // Expose canUseDOM so tests can monkeypatch it | ||
| SideEffect.peek = function peek() { | ||
@@ -63,5 +81,2 @@ return state; | ||
| // Expose canUseDOM so tests can monkeypatch it | ||
| SideEffect.rewind = function rewind() { | ||
@@ -78,7 +93,9 @@ if (SideEffect.canUseDOM) { | ||
| SideEffect.prototype.shouldComponentUpdate = function shouldComponentUpdate(nextProps) { | ||
| var _proto = SideEffect.prototype; | ||
| _proto.shouldComponentUpdate = function shouldComponentUpdate(nextProps) { | ||
| return !shallowEqual(nextProps, this.props); | ||
| }; | ||
| SideEffect.prototype.componentWillMount = function componentWillMount() { | ||
| _proto.componentWillMount = function componentWillMount() { | ||
| mountedInstances.push(this); | ||
@@ -88,7 +105,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); | ||
@@ -99,3 +116,3 @@ mountedInstances.splice(index, 1); | ||
| SideEffect.prototype.render = function render() { | ||
| _proto.render = function render() { | ||
| return React.createElement(WrappedComponent, this.props); | ||
@@ -107,5 +124,5 @@ }; | ||
| SideEffect.displayName = 'SideEffect(' + getDisplayName(WrappedComponent) + ')'; | ||
| SideEffect.canUseDOM = ExecutionEnvironment.canUseDOM; | ||
| _defineProperty(SideEffect, "displayName", "SideEffect(" + getDisplayName(WrappedComponent) + ")"); | ||
| _defineProperty(SideEffect, "canUseDOM", canUseDOM); | ||
@@ -112,0 +129,0 @@ return SideEffect; |
+37
-20
@@ -7,11 +7,26 @@ 'use strict'; | ||
| var React__default = _interopDefault(React); | ||
| var ExecutionEnvironment = _interopDefault(require('exenv')); | ||
| var shallowEqual = _interopDefault(require('shallowequal')); | ||
| function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
| 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; | ||
| } | ||
| 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; } | ||
| return obj; | ||
| } | ||
| 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 _inheritsLoose(subClass, superClass) { | ||
| subClass.prototype = Object.create(superClass.prototype); | ||
| subClass.prototype.constructor = subClass; | ||
| subClass.__proto__ = superClass; | ||
| } | ||
| var canUseDOM = !!(typeof window !== 'undefined' && window.document && window.document.createElement); | ||
| function withSideEffect(reducePropsToState, handleStateChangeOnClient, mapStateOnServer) { | ||
@@ -21,5 +36,7 @@ if (typeof reducePropsToState !== 'function') { | ||
| } | ||
| if (typeof handleStateChangeOnClient !== 'function') { | ||
| throw new Error('Expected handleStateChangeOnClient to be a function.'); | ||
| } | ||
| if (typeof mapStateOnServer !== 'undefined' && typeof mapStateOnServer !== 'function') { | ||
@@ -39,3 +56,3 @@ throw new Error('Expected mapStateOnServer to either be undefined or a function.'); | ||
| var mountedInstances = []; | ||
| var state = void 0; | ||
| var state; | ||
@@ -54,12 +71,13 @@ function emitChange() { | ||
| 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 | ||
| // Expose canUseDOM so tests can monkeypatch it | ||
| SideEffect.peek = function peek() { | ||
@@ -69,5 +87,2 @@ return state; | ||
| // Expose canUseDOM so tests can monkeypatch it | ||
| SideEffect.rewind = function rewind() { | ||
@@ -84,7 +99,9 @@ if (SideEffect.canUseDOM) { | ||
| SideEffect.prototype.shouldComponentUpdate = function shouldComponentUpdate(nextProps) { | ||
| var _proto = SideEffect.prototype; | ||
| _proto.shouldComponentUpdate = function shouldComponentUpdate(nextProps) { | ||
| return !shallowEqual(nextProps, this.props); | ||
| }; | ||
| SideEffect.prototype.componentWillMount = function componentWillMount() { | ||
| _proto.componentWillMount = function componentWillMount() { | ||
| mountedInstances.push(this); | ||
@@ -94,7 +111,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); | ||
@@ -105,3 +122,3 @@ mountedInstances.splice(index, 1); | ||
| SideEffect.prototype.render = function render() { | ||
| _proto.render = function render() { | ||
| return React__default.createElement(WrappedComponent, this.props); | ||
@@ -113,5 +130,5 @@ }; | ||
| SideEffect.displayName = 'SideEffect(' + getDisplayName(WrappedComponent) + ')'; | ||
| SideEffect.canUseDOM = ExecutionEnvironment.canUseDOM; | ||
| _defineProperty(SideEffect, "displayName", "SideEffect(" + getDisplayName(WrappedComponent) + ")"); | ||
| _defineProperty(SideEffect, "canUseDOM", canUseDOM); | ||
@@ -118,0 +135,0 @@ return SideEffect; |
+133
-161
| (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)); | ||
| }(this, (function (React) { 'use strict'; | ||
| typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('react')) : | ||
| typeof define === 'function' && define.amd ? define(['react'], factory) : | ||
| (global = global || self, 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 createCommonjsModule(fn, module) { | ||
| return module = { exports: {} }, fn(module, module.exports), module.exports; | ||
| } | ||
| 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; | ||
| } | ||
| var exenv = createCommonjsModule(function (module) { | ||
| /*! | ||
| Copyright (c) 2015 Jed Watson. | ||
| Based on code that is Copyright 2013-2015, Facebook, Inc. | ||
| All rights reserved. | ||
| */ | ||
| /* global define */ | ||
| return obj; | ||
| } | ||
| (function () { | ||
| function _inheritsLoose(subClass, superClass) { | ||
| subClass.prototype = Object.create(superClass.prototype); | ||
| subClass.prototype.constructor = subClass; | ||
| subClass.__proto__ = superClass; | ||
| } | ||
| var canUseDOM = !!( | ||
| typeof window !== 'undefined' && | ||
| window.document && | ||
| window.document.createElement | ||
| ); | ||
| var shallowequal = function shallowEqual(objA, objB, compare, compareContext) { | ||
| var ExecutionEnvironment = { | ||
| var ret = compare ? compare.call(compareContext, objA, objB) : void 0; | ||
| canUseDOM: canUseDOM, | ||
| if(ret !== void 0) { | ||
| return !!ret; | ||
| } | ||
| canUseWorkers: typeof Worker !== 'undefined', | ||
| if(objA === objB) { | ||
| return true; | ||
| } | ||
| canUseEventListeners: | ||
| canUseDOM && !!(window.addEventListener || window.attachEvent), | ||
| if(typeof objA !== 'object' || !objA || | ||
| typeof objB !== 'object' || !objB) { | ||
| return false; | ||
| } | ||
| canUseViewport: canUseDOM && !!window.screen | ||
| var keysA = Object.keys(objA); | ||
| var keysB = Object.keys(objB); | ||
| }; | ||
| if(keysA.length !== keysB.length) { | ||
| return false; | ||
| } | ||
| if (typeof undefined === 'function' && typeof undefined.amd === 'object' && undefined.amd) { | ||
| undefined(function () { | ||
| return ExecutionEnvironment; | ||
| }); | ||
| } else if ('object' !== 'undefined' && module.exports) { | ||
| module.exports = ExecutionEnvironment; | ||
| } else { | ||
| window.ExecutionEnvironment = ExecutionEnvironment; | ||
| } | ||
| var bHasOwnProperty = Object.prototype.hasOwnProperty.bind(objB); | ||
| }()); | ||
| }); | ||
| // Test for A's keys different from B. | ||
| for(var idx = 0; idx < keysA.length; idx++) { | ||
| var shallowequal = function shallowEqual(objA, objB, compare, compareContext) { | ||
| var key = keysA[idx]; | ||
| var ret = compare ? compare.call(compareContext, objA, objB) : void 0; | ||
| if(!bHasOwnProperty(key)) { | ||
| return false; | ||
| } | ||
| if(ret !== void 0) { | ||
| return !!ret; | ||
| } | ||
| var valueA = objA[key]; | ||
| var valueB = objB[key]; | ||
| if(objA === objB) { | ||
| return true; | ||
| } | ||
| ret = compare ? compare.call(compareContext, valueA, valueB, key) : void 0; | ||
| if(typeof objA !== 'object' || !objA || | ||
| typeof objB !== 'object' || !objB) { | ||
| return false; | ||
| } | ||
| if(ret === false || | ||
| ret === void 0 && valueA !== valueB) { | ||
| return false; | ||
| } | ||
| var keysA = Object.keys(objA); | ||
| var keysB = Object.keys(objB); | ||
| } | ||
| if(keysA.length !== keysB.length) { | ||
| return false; | ||
| } | ||
| return true; | ||
| var bHasOwnProperty = Object.prototype.hasOwnProperty.bind(objB); | ||
| }; | ||
| // Test for A's keys different from B. | ||
| for(var idx = 0; idx < keysA.length; idx++) { | ||
| var canUseDOM = !!(typeof window !== 'undefined' && window.document && window.document.createElement); | ||
| function withSideEffect(reducePropsToState, handleStateChangeOnClient, mapStateOnServer) { | ||
| if (typeof reducePropsToState !== 'function') { | ||
| throw new Error('Expected reducePropsToState to be a function.'); | ||
| } | ||
| var key = keysA[idx]; | ||
| if (typeof handleStateChangeOnClient !== 'function') { | ||
| throw new Error('Expected handleStateChangeOnClient to be a function.'); | ||
| } | ||
| if(!bHasOwnProperty(key)) { | ||
| return false; | ||
| } | ||
| var valueA = objA[key]; | ||
| var valueB = objB[key]; | ||
| ret = compare ? compare.call(compareContext, valueA, valueB, key) : void 0; | ||
| if(ret === false || | ||
| ret === void 0 && valueA !== valueB) { | ||
| return false; | ||
| } | ||
| if (typeof mapStateOnServer !== 'undefined' && typeof mapStateOnServer !== 'function') { | ||
| throw new Error('Expected mapStateOnServer to either be undefined or a function.'); | ||
| } | ||
| return true; | ||
| }; | ||
| function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as 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, mapStateOnServer) { | ||
| 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 mapStateOnServer !== 'undefined' && typeof mapStateOnServer !== 'function') { | ||
| throw new Error('Expected mapStateOnServer to either be undefined or a function.'); | ||
| } | ||
| 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.'); | ||
| function getDisplayName(WrappedComponent) { | ||
| return WrappedComponent.displayName || WrappedComponent.name || 'Component'; | ||
| } | ||
| var mountedInstances = []; | ||
| var state = void 0; | ||
| function emitChange() { | ||
| state = reducePropsToState(mountedInstances.map(function (instance) { | ||
| return instance.props; | ||
| })); | ||
| if (SideEffect.canUseDOM) { | ||
| handleStateChangeOnClient(state); | ||
| } else if (mapStateOnServer) { | ||
| state = mapStateOnServer(state); | ||
| return function wrap(WrappedComponent) { | ||
| if (typeof WrappedComponent !== 'function') { | ||
| throw new Error('Expected WrappedComponent to be a React component.'); | ||
| } | ||
| } | ||
| var SideEffect = function (_Component) { | ||
| _inherits(SideEffect, _Component); | ||
| var mountedInstances = []; | ||
| var state; | ||
| function SideEffect() { | ||
| _classCallCheck(this, SideEffect); | ||
| function emitChange() { | ||
| state = reducePropsToState(mountedInstances.map(function (instance) { | ||
| return instance.props; | ||
| })); | ||
| return _possibleConstructorReturn(this, _Component.apply(this, arguments)); | ||
| if (SideEffect.canUseDOM) { | ||
| handleStateChangeOnClient(state); | ||
| } else if (mapStateOnServer) { | ||
| state = mapStateOnServer(state); | ||
| } | ||
| } | ||
| // Try to use displayName of wrapped component | ||
| SideEffect.peek = function peek() { | ||
| return state; | ||
| }; | ||
| var SideEffect = | ||
| /*#__PURE__*/ | ||
| function (_Component) { | ||
| _inheritsLoose(SideEffect, _Component); | ||
| // Expose canUseDOM so tests can monkeypatch it | ||
| function SideEffect() { | ||
| return _Component.apply(this, arguments) || this; | ||
| } | ||
| // Try to use displayName of wrapped component | ||
| // Expose canUseDOM so tests can monkeypatch it | ||
| SideEffect.peek = function peek() { | ||
| return state; | ||
| }; | ||
| SideEffect.rewind = function rewind() { | ||
| if (SideEffect.canUseDOM) { | ||
| throw new Error('You may only call rewind() on the server. Call peek() to read the current state.'); | ||
| } | ||
| SideEffect.rewind = function rewind() { | ||
| if (SideEffect.canUseDOM) { | ||
| throw new Error('You may only call rewind() on the server. Call peek() to read the current state.'); | ||
| } | ||
| var recordedState = state; | ||
| state = undefined; | ||
| mountedInstances = []; | ||
| return recordedState; | ||
| }; | ||
| var recordedState = state; | ||
| state = undefined; | ||
| mountedInstances = []; | ||
| return recordedState; | ||
| }; | ||
| SideEffect.prototype.shouldComponentUpdate = function shouldComponentUpdate(nextProps) { | ||
| return !shallowequal(nextProps, this.props); | ||
| }; | ||
| var _proto = SideEffect.prototype; | ||
| SideEffect.prototype.componentWillMount = function componentWillMount() { | ||
| mountedInstances.push(this); | ||
| emitChange(); | ||
| }; | ||
| _proto.shouldComponentUpdate = function shouldComponentUpdate(nextProps) { | ||
| return !shallowequal(nextProps, this.props); | ||
| }; | ||
| SideEffect.prototype.componentDidUpdate = function componentDidUpdate() { | ||
| emitChange(); | ||
| }; | ||
| _proto.componentWillMount = function componentWillMount() { | ||
| mountedInstances.push(this); | ||
| emitChange(); | ||
| }; | ||
| SideEffect.prototype.componentWillUnmount = function componentWillUnmount() { | ||
| var index = mountedInstances.indexOf(this); | ||
| mountedInstances.splice(index, 1); | ||
| emitChange(); | ||
| }; | ||
| _proto.componentDidUpdate = function componentDidUpdate() { | ||
| emitChange(); | ||
| }; | ||
| SideEffect.prototype.render = function render() { | ||
| return React__default.createElement(WrappedComponent, this.props); | ||
| }; | ||
| _proto.componentWillUnmount = function componentWillUnmount() { | ||
| var index = mountedInstances.indexOf(this); | ||
| mountedInstances.splice(index, 1); | ||
| emitChange(); | ||
| }; | ||
| return SideEffect; | ||
| }(React.Component); | ||
| _proto.render = function render() { | ||
| return React__default.createElement(WrappedComponent, this.props); | ||
| }; | ||
| SideEffect.displayName = 'SideEffect(' + getDisplayName(WrappedComponent) + ')'; | ||
| SideEffect.canUseDOM = exenv.canUseDOM; | ||
| return SideEffect; | ||
| }(React.Component); | ||
| _defineProperty(SideEffect, "displayName", "SideEffect(" + getDisplayName(WrappedComponent) + ")"); | ||
| return SideEffect; | ||
| }; | ||
| } | ||
| _defineProperty(SideEffect, "canUseDOM", canUseDOM); | ||
| return withSideEffect; | ||
| return SideEffect; | ||
| }; | ||
| } | ||
| }))); | ||
| return withSideEffect; | ||
| })); |
@@ -1,1 +0,1 @@ | ||
| !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,o=(function(e){var t,n;t=!("undefined"==typeof window||!window.document||!window.document.createElement),n={canUseDOM:t,canUseWorkers:"undefined"!=typeof Worker,canUseEventListeners:t&&!(!window.addEventListener&&!window.attachEvent),canUseViewport:t&&!!window.screen},e.exports?e.exports=n:window.ExecutionEnvironment=n}(n={exports:{}},n.exports),n.exports),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),c=Object.keys(t);if(i.length!==c.length)return!1;for(var f=Object.prototype.hasOwnProperty.bind(t),p=0;p<i.length;p++){var u=i[p];if(!f(u))return!1;var a=e[u],s=t[u];if(!1===(r=n?n.call(o,a,s,u):void 0)||void 0===r&&a!==s)return!1}return!0};return function(n,i,c){if("function"!=typeof n)throw new Error("Expected reducePropsToState to be a function.");if("function"!=typeof i)throw new Error("Expected handleStateChangeOnClient to be a function.");if(void 0!==c&&"function"!=typeof c)throw new Error("Expected mapStateOnServer to either be undefined or a function.");return function(f){if("function"!=typeof f)throw new Error("Expected WrappedComponent to be a React component.");var p=[],u=void 0;function a(){u=n(p.map(function(e){return e.props})),s.canUseDOM?i(u):c&&(u=c(u))}var s=function(e){function n(){return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,n),function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}(this,e.apply(this,arguments))}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(n,e),n.peek=function(){return u},n.rewind=function(){if(n.canUseDOM)throw new Error("You may only call rewind() on the server. Call peek() to read the current state.");var e=u;return u=void 0,p=[],e},n.prototype.shouldComponentUpdate=function(e){return!r(e,this.props)},n.prototype.componentWillMount=function(){p.push(this),a()},n.prototype.componentDidUpdate=function(){a()},n.prototype.componentWillUnmount=function(){var e=p.indexOf(this);p.splice(e,1),a()},n.prototype.render=function(){return t.createElement(f,this.props)},n}(e.Component);return s.displayName="SideEffect("+function(e){return e.displayName||e.name||"Component"}(f)+")",s.canUseDOM=o.canUseDOM,s}}}); | ||
| !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("react")):"function"==typeof define&&define.amd?define(["react"],t):(e=e||self).withSideEffect=t(e.React)}(this,function(e){"use strict";var t="default"in e?e.default:e;function n(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var r=function(e,t,n,r){var o=n?n.call(r,e,t):void 0;if(void 0!==o)return!!o;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),f=0;f<i.length;f++){var a=i[f];if(!c(a))return!1;var p=e[a],d=t[a];if(!1===(o=n?n.call(r,p,d,a):void 0)||void 0===o&&p!==d)return!1}return!0},o=!("undefined"==typeof window||!window.document||!window.document.createElement);return function(i,u,c){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.");if(void 0!==c&&"function"!=typeof c)throw new Error("Expected mapStateOnServer to either be undefined or a function.");return function(f){if("function"!=typeof f)throw new Error("Expected WrappedComponent to be a React component.");var a,p=[];function d(){a=i(p.map(function(e){return e.props})),l.canUseDOM?u(a):c&&(a=c(a))}var l=function(e){var n,o;function i(){return e.apply(this,arguments)||this}o=e,(n=i).prototype=Object.create(o.prototype),n.prototype.constructor=n,n.__proto__=o,i.peek=function(){return a},i.rewind=function(){if(i.canUseDOM)throw new Error("You may only call rewind() on the server. Call peek() to read the current state.");var e=a;return a=void 0,p=[],e};var u=i.prototype;return u.shouldComponentUpdate=function(e){return!r(e,this.props)},u.componentWillMount=function(){p.push(this),d()},u.componentDidUpdate=function(){d()},u.componentWillUnmount=function(){var e=p.indexOf(this);p.splice(e,1),d()},u.render=function(){return t.createElement(f,this.props)},i}(e.Component);return n(l,"displayName","SideEffect("+function(e){return e.displayName||e.name||"Component"}(f)+")"),n(l,"canUseDOM",o),l}}}); |
+12
-12
| { | ||
| "name": "react-side-effect", | ||
| "version": "1.1.5", | ||
| "version": "1.2.0", | ||
| "description": "Create components whose prop changes map to a global side effect", | ||
@@ -31,3 +31,3 @@ "main": "lib/index.js", | ||
| "contributors": [ | ||
| "Louis DeScioli <louis.descioli@gmail.com>" | ||
| "Louis DeScioli (https://descioli.design)" | ||
| ], | ||
@@ -38,14 +38,14 @@ "peerDependencies": { | ||
| "dependencies": { | ||
| "exenv": "^1.2.1", | ||
| "shallowequal": "^1.0.1" | ||
| }, | ||
| "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/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 +62,4 @@ "enzyme": "^2.7.0", | ||
| "rimraf": "^2.4.3", | ||
| "rollup": "^0.56.2", | ||
| "rollup-plugin-babel": "^3.0.2", | ||
| "rollup": "^1.20.3", | ||
| "rollup-plugin-babel": "^4.0.0", | ||
| "rollup-plugin-commonjs": "^8.3.0", | ||
@@ -66,0 +66,0 @@ "rollup-plugin-node-resolve": "^3.0.3", |
+3
-3
@@ -15,3 +15,3 @@ # React Side Effect [](https://npmjs.com/react-side-effect) [](https://www.npmjs.com/package/react-side-effect) | ||
| ``` | ||
| ```html | ||
| <script src="https://unpkg.com/react/umd/react.development.js" type="text/javascript"></script> | ||
@@ -23,3 +23,3 @@ <script src="https://unpkg.com/react-side-effect/lib/index.umd.js" type="text/javascript"></script> | ||
| ``` | ||
| ```html | ||
| <script src="https://unpkg.com/react/umd/react.production.min.js" type="text/javascript"></script> | ||
@@ -39,3 +39,3 @@ <script src="https://unpkg.com/react-side-effect/lib/index.umd.min.js" type="text/javascript"></script> | ||
| ```js | ||
| ```jsx | ||
| // RootComponent.js | ||
@@ -42,0 +42,0 @@ return ( |
2
-33.33%345
3.92%22806
-10.68%25
4.17%- Removed
- Removed