UNPKG

2.8 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = undefined;
7
8var _class, _temp;
9
10var _react = require('react');
11
12var _react2 = _interopRequireDefault(_react);
13
14var _propTypes = require('prop-types');
15
16var _propTypes2 = _interopRequireDefault(_propTypes);
17
18var _styleKeeper = require('../style-keeper');
19
20var _styleKeeper2 = _interopRequireDefault(_styleKeeper);
21
22function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
24function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
25
26function _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; }
27
28function _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; }
29
30var StyleSheet = (_temp = _class = function (_PureComponent) {
31 _inherits(StyleSheet, _PureComponent);
32
33 function StyleSheet() {
34 _classCallCheck(this, StyleSheet);
35
36 var _this = _possibleConstructorReturn(this, _PureComponent.apply(this, arguments));
37
38 _this._onChange = function () {
39 setTimeout(function () {
40 _this._isMounted && _this.setState(_this._getCSSState());
41 }, 0);
42 };
43
44 _this.state = _this._getCSSState();
45 return _this;
46 }
47
48 StyleSheet.prototype.componentDidMount = function componentDidMount() {
49 this._isMounted = true;
50 this._subscription = this.context._radiumStyleKeeper.subscribe(this._onChange);
51 this._onChange();
52 };
53
54 StyleSheet.prototype.componentWillUnmount = function componentWillUnmount() {
55 this._isMounted = false;
56 if (this._subscription) {
57 this._subscription.remove();
58 }
59 };
60
61 StyleSheet.prototype._getCSSState = function _getCSSState() {
62 return { css: this.context._radiumStyleKeeper.getCSS() };
63 };
64
65 StyleSheet.prototype.render = function render() {
66 return _react2.default.createElement('style', { dangerouslySetInnerHTML: { __html: this.state.css } });
67 };
68
69 return StyleSheet;
70}(_react.PureComponent), _class.contextTypes = {
71 _radiumStyleKeeper: _propTypes2.default.instanceOf(_styleKeeper2.default)
72}, _temp);
73exports.default = StyleSheet;
74module.exports = exports['default'];
\No newline at end of file