MCPcopy Create free account
hub / github.com/krasimir/react-in-patterns / wrapWithTheme

Function wrapWithTheme

code/styling/public/app.js:21875–21962  ·  view source on GitHub ↗
(Component$$1)

Source from the content-addressed store, hash-verified

21873/* globals ReactClass */
21874
21875var wrapWithTheme = function wrapWithTheme(Component$$1) {
21876 var _WithTheme$contextTyp;
21877
21878 var componentName = Component$$1.displayName || Component$$1.name || 'Component';
21879 var isStatelessFunctionalComponent = typeof Component$$1 === 'function' && !(Component$$1.prototype && 'isReactComponent' in Component$$1.prototype);
21880
21881 // NOTE: We can't pass a ref to a stateless functional component
21882 var shouldSetInnerRef = isStyledComponent(Component$$1) || isStatelessFunctionalComponent;
21883
21884 var WithTheme = function (_React$Component) {
21885 inherits(WithTheme, _React$Component);
21886
21887 function WithTheme() {
21888 var _temp, _this, _ret;
21889
21890 classCallCheck(this, WithTheme);
21891
21892 for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
21893 args[_key] = arguments[_key];
21894 }
21895
21896 return _ret = (_temp = (_this = possibleConstructorReturn(this, _React$Component.call.apply(_React$Component, [this].concat(args))), _this), _this.state = {}, _this.unsubscribeId = -1, _temp), possibleConstructorReturn(_this, _ret);
21897 }
21898
21899 // NOTE: This is so that isStyledComponent passes for the innerRef unwrapping
21900
21901
21902 WithTheme.prototype.componentWillMount = function componentWillMount() {
21903 var _this2 = this;
21904
21905 var defaultProps = this.constructor.defaultProps;
21906
21907 var styledContext = this.context[CHANNEL_NEXT];
21908 var themeProp = determineTheme(this.props, undefined, defaultProps);
21909 if (styledContext === undefined && themeProp === undefined && process.env.NODE_ENV !== 'production') {
21910 // eslint-disable-next-line no-console
21911 console.warn('[withTheme] You are not using a ThemeProvider nor passing a theme prop or a theme in defaultProps');
21912 } else if (styledContext === undefined && themeProp !== undefined) {
21913 this.setState({ theme: themeProp });
21914 } else {
21915 var subscribe = styledContext.subscribe;
21916
21917 this.unsubscribeId = subscribe(function (nextTheme) {
21918 var theme = determineTheme(_this2.props, nextTheme, defaultProps);
21919 _this2.setState({ theme: theme });
21920 });
21921 }
21922 };
21923
21924 WithTheme.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps) {
21925 var defaultProps = this.constructor.defaultProps;
21926
21927 this.setState(function (oldState) {
21928 var theme = determineTheme(nextProps, oldState.theme, defaultProps);
21929
21930 return { theme: theme };
21931 });
21932 };

Callers

nothing calls this directly

Calls 3

isStyledComponentFunction · 0.85
inheritsFunction · 0.85
subscribeFunction · 0.70

Tested by

no test coverage detected