1 | "use strict";
|
2 |
|
3 | exports.__esModule = true;
|
4 | exports.flush = flush;
|
5 | exports["default"] = void 0;
|
6 |
|
7 | var _react = require("react");
|
8 |
|
9 | var _stylesheetRegistry = _interopRequireDefault(require("./stylesheet-registry"));
|
10 |
|
11 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
12 |
|
13 | function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
|
14 |
|
15 | var styleSheetRegistry = new _stylesheetRegistry["default"]();
|
16 |
|
17 | var JSXStyle = function (_Component) {
|
18 | _inheritsLoose(JSXStyle, _Component);
|
19 |
|
20 | function JSXStyle(props) {
|
21 | var _this;
|
22 |
|
23 | _this = _Component.call(this, props) || this;
|
24 | _this.prevProps = {};
|
25 | return _this;
|
26 | }
|
27 |
|
28 | JSXStyle.dynamic = function dynamic(info) {
|
29 | return info.map(function (tagInfo) {
|
30 | var baseId = tagInfo[0];
|
31 | var props = tagInfo[1];
|
32 | return styleSheetRegistry.computeId(baseId, props);
|
33 | }).join(' ');
|
34 | }
|
35 | ;
|
36 |
|
37 | var _proto = JSXStyle.prototype;
|
38 |
|
39 | _proto.shouldComponentUpdate = function shouldComponentUpdate(otherProps) {
|
40 | return this.props.id !== otherProps.id ||
|
41 |
|
42 | String(this.props.dynamic) !== String(otherProps.dynamic);
|
43 | };
|
44 |
|
45 | _proto.componentWillUnmount = function componentWillUnmount() {
|
46 | styleSheetRegistry.remove(this.props);
|
47 | };
|
48 |
|
49 | _proto.render = function render() {
|
50 |
|
51 |
|
52 | if (this.shouldComponentUpdate(this.prevProps)) {
|
53 |
|
54 | if (this.prevProps.id) {
|
55 | styleSheetRegistry.remove(this.prevProps);
|
56 | }
|
57 |
|
58 | styleSheetRegistry.add(this.props);
|
59 | this.prevProps = this.props;
|
60 | }
|
61 |
|
62 | return null;
|
63 | };
|
64 |
|
65 | return JSXStyle;
|
66 | }(_react.Component);
|
67 |
|
68 | exports["default"] = JSXStyle;
|
69 |
|
70 | function flush() {
|
71 | var cssRules = styleSheetRegistry.cssRules();
|
72 | styleSheetRegistry.flush();
|
73 | return cssRules;
|
74 | } |
\ | No newline at end of file |