@emotion/core
Advanced tools
Comparing version 0.6.0 to 0.6.2
@@ -11,19 +11,57 @@ 'use strict'; | ||
// $FlowFixMe | ||
var CSSContext = React.createContext(null); | ||
var defaultCache = createCache(); | ||
function consumer(instance, func) { | ||
return React.createElement(CSSContext.Consumer, null, function (context) { | ||
if (context === null) { | ||
if (utils.isBrowser && process.env.NODE_ENV !== 'test') { | ||
return func(defaultCache); | ||
} | ||
function _inheritsLoose(subClass, superClass) { | ||
subClass.prototype = Object.create(superClass.prototype); | ||
subClass.prototype.constructor = subClass; | ||
subClass.__proto__ = superClass; | ||
} | ||
if (instance.emotionCache === undefined) { | ||
instance.emotionCache = createCache(); | ||
function _render() { | ||
return React.createElement(CSSContext.Provider, { | ||
value: this.emotionCache | ||
}, this.props.children(this.emotionCache)); | ||
} | ||
var BasicProvider = | ||
/*#__PURE__*/ | ||
function (_React$Component) { | ||
_inheritsLoose(BasicProvider, _React$Component); | ||
function BasicProvider(props) { | ||
var _this; | ||
_this = _React$Component.call(this, props) || this; | ||
_this.emotionCache = createCache(); | ||
return _this; | ||
} | ||
var _proto = BasicProvider.prototype; | ||
_proto.render = _render; | ||
return BasicProvider; | ||
}(React.Component); // $FlowFixMe | ||
var CSSContext = React.createContext(utils.isBrowser && process.env.NODE_ENV !== 'test' ? createCache() : null); | ||
function withCSSContext(func) { | ||
return function (props) { | ||
function _ref(newContext) { | ||
return func(props, newContext); | ||
} | ||
return React.createElement(CSSContext.Consumer, null, function (context) { | ||
if (context === null) { | ||
return React.createElement(BasicProvider, null, _ref); | ||
} else { | ||
return func(props, context); | ||
} | ||
}); | ||
}; | ||
} | ||
function consume(func) { | ||
function _ref2(newContext) { | ||
return func(newContext); | ||
} | ||
return React.createElement(CSSContext.Provider, { | ||
value: instance.emotionCache | ||
}, func(instance.emotionCache)); | ||
return React.createElement(CSSContext.Consumer, null, function (context) { | ||
if (context === null) { | ||
return React.createElement(BasicProvider, null, _ref2); | ||
} else { | ||
@@ -36,3 +74,4 @@ return func(context); | ||
exports.CSSContext = CSSContext; | ||
exports.consumer = consumer; | ||
exports.withCSSContext = withCSSContext; | ||
exports.consume = consume; | ||
//# sourceMappingURL=index.cjs.js.map |
import { isBrowser } from '@emotion/utils'; | ||
import { createContext, createElement } from 'react'; | ||
import { createElement, Component, createContext } from 'react'; | ||
import createCache from '@emotion/cache'; | ||
// $FlowFixMe | ||
var CSSContext = createContext(null); | ||
var defaultCache = createCache(); | ||
function consumer(instance, func) { | ||
return createElement(CSSContext.Consumer, null, function (context) { | ||
if (context === null) { | ||
if (isBrowser && process.env.NODE_ENV !== 'test') { | ||
return func(defaultCache); | ||
} | ||
function _inheritsLoose(subClass, superClass) { | ||
subClass.prototype = Object.create(superClass.prototype); | ||
subClass.prototype.constructor = subClass; | ||
subClass.__proto__ = superClass; | ||
} | ||
if (instance.emotionCache === undefined) { | ||
instance.emotionCache = createCache(); | ||
function _render() { | ||
return createElement(CSSContext.Provider, { | ||
value: this.emotionCache | ||
}, this.props.children(this.emotionCache)); | ||
} | ||
var BasicProvider = | ||
/*#__PURE__*/ | ||
function (_React$Component) { | ||
_inheritsLoose(BasicProvider, _React$Component); | ||
function BasicProvider(props) { | ||
var _this; | ||
_this = _React$Component.call(this, props) || this; | ||
_this.emotionCache = createCache(); | ||
return _this; | ||
} | ||
var _proto = BasicProvider.prototype; | ||
_proto.render = _render; | ||
return BasicProvider; | ||
}(Component); // $FlowFixMe | ||
var CSSContext = createContext(isBrowser && process.env.NODE_ENV !== 'test' ? createCache() : null); | ||
function withCSSContext(func) { | ||
return function (props) { | ||
function _ref(newContext) { | ||
return func(props, newContext); | ||
} | ||
return createElement(CSSContext.Consumer, null, function (context) { | ||
if (context === null) { | ||
return createElement(BasicProvider, null, _ref); | ||
} else { | ||
return func(props, context); | ||
} | ||
}); | ||
}; | ||
} | ||
function consume(func) { | ||
function _ref2(newContext) { | ||
return func(newContext); | ||
} | ||
return createElement(CSSContext.Provider, { | ||
value: instance.emotionCache | ||
}, func(instance.emotionCache)); | ||
return createElement(CSSContext.Consumer, null, function (context) { | ||
if (context === null) { | ||
return createElement(BasicProvider, null, _ref2); | ||
} else { | ||
@@ -28,3 +66,3 @@ return func(context); | ||
export { CSSContext, consumer }; | ||
export { CSSContext, withCSSContext, consume }; | ||
//# sourceMappingURL=index.es.js.map |
{ | ||
"name": "@emotion/core", | ||
"version": "0.6.0", | ||
"version": "0.6.2", | ||
"main": "dist/index.cjs.js", | ||
@@ -18,7 +18,5 @@ "module": "dist/index.es.js", | ||
"dependencies": { | ||
"@emotion/cache": "^0.6.0", | ||
"@emotion/sheet": "^0.6.0", | ||
"@emotion/cache": "^0.6.2", | ||
"@emotion/types": "^0.6.0", | ||
"@emotion/utils": "^0.5.0", | ||
"emotion-utils": "^9.1.0" | ||
"@emotion/utils": "^0.5.0" | ||
}, | ||
@@ -25,0 +23,0 @@ "peerDependencies": { |
@@ -30,11 +30,45 @@ // @flow | ||
type BasicProviderProps = { | ||
children: CSSContextType => React.Node | ||
} | ||
class BasicProvider extends React.Component<BasicProviderProps> { | ||
emotionCache = createCache() | ||
render() { | ||
return ( | ||
<CSSContext.Provider value={this.emotionCache}> | ||
{this.props.children(this.emotionCache)} | ||
</CSSContext.Provider> | ||
) | ||
} | ||
} | ||
// $FlowFixMe | ||
export const CSSContext: Context<CSSContextType> = React.createContext(null) | ||
export const CSSContext: Context<CSSContextType> = React.createContext( | ||
isBrowser && process.env.NODE_ENV !== 'test' ? createCache() : null | ||
) | ||
let defaultCache = createCache() | ||
export function withCSSContext<Props>( | ||
func: (props: Props, context: CSSContextType) => React.Node | ||
): React.StatelessFunctionalComponent<Props> { | ||
return (props: Props) => ( | ||
<CSSContext.Consumer> | ||
{context => { | ||
if (context === null) { | ||
return ( | ||
<BasicProvider> | ||
{newContext => { | ||
return func(props, newContext) | ||
}} | ||
</BasicProvider> | ||
) | ||
} else { | ||
return func(props, context) | ||
} | ||
}} | ||
</CSSContext.Consumer> | ||
) | ||
} | ||
export function consumer( | ||
instance: { emotionCache?: CSSContextType }, | ||
func: CSSContextType => React.Node | ||
) { | ||
export function consume(func: CSSContextType => React.Node) { | ||
return ( | ||
@@ -44,12 +78,8 @@ <CSSContext.Consumer> | ||
if (context === null) { | ||
if (isBrowser && process.env.NODE_ENV !== 'test') { | ||
return func(defaultCache) | ||
} | ||
if (instance.emotionCache === undefined) { | ||
instance.emotionCache = createCache() | ||
} | ||
return ( | ||
<CSSContext.Provider value={instance.emotionCache}> | ||
{func(instance.emotionCache)} | ||
</CSSContext.Provider> | ||
<BasicProvider> | ||
{newContext => { | ||
return func(newContext) | ||
}} | ||
</BasicProvider> | ||
) | ||
@@ -56,0 +86,0 @@ } else { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
52846
4
196
4
- Removed@emotion/sheet@^0.6.0
- Removedemotion-utils@^9.1.0
- Removedemotion-utils@9.1.0(transitive)
Updated@emotion/cache@^0.6.2