fps-now
Version:
FPS meter for evergreen browsers
107 lines (82 loc) • 3.27 kB
JavaScript
;
exports.__esModule = true;
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _ = _interopRequireDefault(require("../"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
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; } return obj; }
var styles = {
text: {
fontSize: '11px',
lineHeight: '15px',
color: 'rgb(40, 40, 40)',
fontFamily: 'monospace'
},
wrapper: {
position: 'absolute',
top: 3,
right: 3,
borderRadius: 3,
background: 'rgba(0, 0, 0, 0.1)',
padding: '8px 16px',
minWidth: 30,
textAlign: 'center'
}
};
var Wrapper = function Wrapper(_ref) {
var children = _ref.children;
return _react.default.createElement("div", {
style: styles.wrapper
}, children);
};
var Text = function Text(_ref2) {
var children = _ref2.children;
return _react.default.createElement("span", {
style: styles.text
}, children);
};
var FPS =
/*#__PURE__*/
function (_Component) {
_inheritsLoose(FPS, _Component);
function FPS() {
var _this;
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = _Component.call.apply(_Component, [this].concat(args)) || this;
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "state", {
fps: 0
});
_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "onTick", function (graph) {
_this.setState(function (s) {
return {
fps: graph.toFixed(2)
};
});
});
return _this;
}
var _proto = FPS.prototype;
_proto.componentWillMount = function componentWillMount() {
this.fps = _.default.of({
visual: false,
averageFPS: true
});
this.fps.on('tick', this.onTick);
};
_proto.componentDidMount = function componentDidMount() {
this.fps.start();
};
_proto.componentWillUnmount = function componentWillUnmount() {
delete this.fps;
};
_proto.render = function render() {
return _react.default.createElement(Wrapper, null, _react.default.createElement(Text, null, this.state.fps));
};
return FPS;
}(_react.Component);
exports.default = FPS;