Add files
This commit is contained in:
commit
bb80829159
18195 changed files with 2122994 additions and 0 deletions
125
509bba0_unpacked_with_node_modules/~/react-side-effect/lib/index.js
generated
vendored
Executable file
125
509bba0_unpacked_with_node_modules/~/react-side-effect/lib/index.js
generated
vendored
Executable file
|
@ -0,0 +1,125 @@
|
|||
'use strict';
|
||||
|
||||
var _react = require('react');
|
||||
|
||||
var _react2 = _interopRequireDefault(_react);
|
||||
|
||||
var _exenv = require('exenv');
|
||||
|
||||
var _exenv2 = _interopRequireDefault(_exenv);
|
||||
|
||||
var _shallowequal = require('shallowequal');
|
||||
|
||||
var _shallowequal2 = _interopRequireDefault(_shallowequal);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
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; }
|
||||
|
||||
module.exports = 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.');
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
var SideEffect = function (_Component) {
|
||||
_inherits(SideEffect, _Component);
|
||||
|
||||
function SideEffect() {
|
||||
_classCallCheck(this, SideEffect);
|
||||
|
||||
return _possibleConstructorReturn(this, _Component.apply(this, arguments));
|
||||
}
|
||||
|
||||
// Try to use displayName of wrapped component
|
||||
SideEffect.peek = function peek() {
|
||||
return state;
|
||||
};
|
||||
|
||||
// Expose canUseDOM so tests can monkeypatch it
|
||||
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
SideEffect.prototype.shouldComponentUpdate = function shouldComponentUpdate(nextProps) {
|
||||
return !(0, _shallowequal2.default)(nextProps, this.props);
|
||||
};
|
||||
|
||||
SideEffect.prototype.componentWillMount = function componentWillMount() {
|
||||
mountedInstances.push(this);
|
||||
emitChange();
|
||||
};
|
||||
|
||||
SideEffect.prototype.componentDidUpdate = function componentDidUpdate() {
|
||||
emitChange();
|
||||
};
|
||||
|
||||
SideEffect.prototype.componentWillUnmount = function componentWillUnmount() {
|
||||
var index = mountedInstances.indexOf(this);
|
||||
mountedInstances.splice(index, 1);
|
||||
emitChange();
|
||||
};
|
||||
|
||||
SideEffect.prototype.render = function render() {
|
||||
return _react2.default.createElement(WrappedComponent, this.props);
|
||||
};
|
||||
|
||||
return SideEffect;
|
||||
}(_react.Component);
|
||||
|
||||
SideEffect.displayName = 'SideEffect(' + getDisplayName(WrappedComponent) + ')';
|
||||
SideEffect.canUseDOM = _exenv2.default.canUseDOM;
|
||||
|
||||
|
||||
return SideEffect;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
//////////////////
|
||||
// WEBPACK FOOTER
|
||||
// ./~/react-side-effect/lib/index.js
|
||||
// module id = 2802
|
||||
// module chunks = 4
|
Loading…
Add table
Add a link
Reference in a new issue