viser-react
Version:
viser-react is react of viser.
99 lines (77 loc) • 3.05 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var PropTypes = _interopRequireWildcard(require("prop-types"));
var React = _interopRequireWildcard(require("react"));
var ReactDOM = _interopRequireWildcard(require("react-dom"));
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
var __extends = void 0 && (void 0).__extends || function () {
var _extendStatics = function extendStatics(d, b) {
_extendStatics = Object.setPrototypeOf || {
__proto__: []
} instanceof Array && function (d, b) {
d.__proto__ = b;
} || function (d, b) {
for (var p in b) {
if (b.hasOwnProperty(p)) d[p] = b[p];
}
};
return _extendStatics(d, b);
};
return function (d, b) {
_extendStatics(d, b);
function __() {
this.constructor = d;
}
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
}();
var isReact16 = ReactDOM.createPortal !== undefined;
function generateRandomNum() {
return Math.floor(new Date().getTime() + Math.random() * 10000).toString();
}
var View = function (_super) {
__extends(View, _super);
function View(props) {
var _this = _super.call(this, props) || this;
_this.displayName = 'View';
_this.state = {
hasInViews: true,
viewId: _this.props.viewId || generateRandomNum()
};
return _this;
}
View.prototype.getChildContext = function () {
return {
hasInViews: this.state.hasInViews,
viewId: this.state.viewId
};
};
View.prototype.componentDidUpdate = function () {
this.context.centralizedUpdates(this);
};
View.prototype.componentDidMount = function () {
this.context.centralizedUpdates(this);
};
View.prototype.render = function () {
if (isReact16) {
return this.props.children;
} else {
return React.Children.only(this.props.children);
}
};
View.childContextTypes = {
hasInViews: PropTypes.bool,
viewId: PropTypes.string
};
View.contextTypes = {
centralizedUpdates: PropTypes.func,
hasInViews: PropTypes.bool
};
return View;
}(React.Component);
var _default = View;
exports.default = _default;