import React from"react";import PropTypes from"prop-types";import warning from"tiny-warning";const MAX_SIGNED_31_BIT_INT=1073741823,commonjsGlobal="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{};function getUniqueId(){let e="__global_unique_id__";return commonjsGlobal[e]=(commonjsGlobal[e]||0)+1}function objectIs(e,t){return e===t?0!==e||1/e==1/t:e!=e&&t!=t}function createEventEmitter(e){let t=[];return{on(e){t.push(e)},off(e){t=t.filter((t=>t!==e))},get:()=>e,set(o,n){e=o,t.forEach((t=>t(e,n)))}}}function onlyChild(e){return Array.isArray(e)?e[0]:e}export default function createReactContext(e,t){const o="__create-react-context-"+getUniqueId()+"__";class Provider extends React.Component{emitter=createEventEmitter(this.props.value);static childContextTypes={[o]:PropTypes.object.isRequired};getChildContext(){return{[o]:this.emitter}}componentWillReceiveProps(e){if(this.props.value!==e.value){let o,n=this.props.value,i=e.value;objectIs(n,i)?o=0:(o="function"==typeof t?t(n,i):1073741823,"production"!==process.env.NODE_ENV&&warning((1073741823&o)===o,"calculateChangedBits: Expected the return value to be a 31-bit integer. Instead received: "+o),o|=0,0!==o&&this.emitter.set(e.value,o))}}render(){return this.props.children}}class Consumer extends React.Component{static contextTypes={[o]:PropTypes.object};observedBits;state={value:this.getValue()};componentWillReceiveProps(e){let{observedBits:t}=e;this.observedBits=null==t?1073741823:t}componentDidMount(){this.context[o]&&this.context[o].on(this.onUpdate);let{observedBits:e}=this.props;this.observedBits=null==e?1073741823:e}componentWillUnmount(){this.context[o]&&this.context[o].off(this.onUpdate)}getValue(){return this.context[o]?this.context[o].get():e}onUpdate=(e,t)=>{0!=((0|this.observedBits)&t)&&this.setState({value:this.getValue()})};render(){return onlyChild(this.props.children)(this.state.value)}}return{Provider:Provider,Consumer:Consumer}}
//# sourceMappingURL=miniCreateReactContext.js.map