Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
view-container / dist / models / StyleSheetManager.js
Size: Mime:
"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
    result["default"] = mod;
    return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
// @flow
const react_1 = __importStar(require("react"));
const prop_types_1 = __importDefault(require("prop-types"));
const StyleSheet_1 = __importDefault(require("./StyleSheet"));
const ServerStyleSheet_1 = __importDefault(require("./ServerStyleSheet"));
const constants_1 = require("../constants");
/* this error is used for makeStyleTag */
const targetPropErr = process.env.NODE_ENV !== 'production'
    ? `
The StyleSheetManager expects a valid target or sheet prop!
- Does this error occur on the client and is your target falsy?
- Does this error occur on the server and is the sheet falsy?
`.trim()
    : '';
class StyleSheetManager extends react_1.Component {
    getChildContext() {
        return { [constants_1.CONTEXT_KEY]: this.sheetInstance };
    }
    componentWillMount() {
        if (this.props.sheet) {
            this.sheetInstance = this.props.sheet;
        }
        else if (this.props.target) {
            this.sheetInstance = new StyleSheet_1.default(this.props.target);
        }
        else {
            throw new Error(targetPropErr);
        }
    }
    render() {
        /* eslint-disable react/prop-types */
        // Flow v0.43.1 will report an error accessing the `children` property,
        // but v0.47.0 will not. It is necessary to use a type cast instead of
        // a "fixme" comment to satisfy both Flow versions.
        return react_1.default.Children.only(this.props.children);
    }
}
StyleSheetManager.childContextTypes = {
    [constants_1.CONTEXT_KEY]: prop_types_1.default.oneOfType([
        prop_types_1.default.instanceOf(StyleSheet_1.default),
        prop_types_1.default.instanceOf(ServerStyleSheet_1.default),
    ]).isRequired,
};
StyleSheetManager.propTypes = {
    sheet: prop_types_1.default.oneOfType([
        prop_types_1.default.instanceOf(StyleSheet_1.default),
        prop_types_1.default.instanceOf(ServerStyleSheet_1.default),
    ]),
    target: prop_types_1.default.shape({
        appendChild: prop_types_1.default.func.isRequired,
    }),
};
exports.default = StyleSheetManager;
//# sourceMappingURL=StyleSheetManager.js.map