UNPKG

@redux-devtools/core

Version:
69 lines 2.61 kB
import _extends from "@babel/runtime/helpers/extends"; import React, { Children, Component } from 'react'; import { connect, Provider, ReactReduxContext } from 'react-redux'; import { instrument } from '@redux-devtools/instrument'; function logError(type) { if (type === 'NoStore') { console.error('Redux DevTools could not render. You must pass the Redux store ' + 'to <DevTools> either as a "store" prop or by wrapping it in a ' + '<Provider store={store}>.'); } else { console.error('Redux DevTools could not render. Did you forget to include ' + 'DevTools.instrument() in your store enhancer chain before ' + 'using createStore()?'); } } export default function createDevTools(children) { const monitorElement = Children.only(children); const monitorProps = monitorElement.props; const Monitor = monitorElement.type; const ConnectedMonitor = connect(state => state)(Monitor); return class DevTools extends Component { static instrument = options => instrument((state, action) => Monitor.update(monitorProps, state, action), options); constructor(props) { super(props); if (ReactReduxContext) { if (this.props.store && !this.props.store.liftedStore) { logError('NoLiftedStore'); } return; } if (!props.store) { logError('NoStore'); return; } this.liftedStore = props.store.liftedStore; if (!this.liftedStore) { logError('NoLiftedStore'); } } render() { if (ReactReduxContext) { // For react-redux@6 if (this.props.store) { if (!this.props.store.liftedStore) { return null; } return /*#__PURE__*/React.createElement(Provider, { store: this.props.store.liftedStore }, /*#__PURE__*/React.createElement(ConnectedMonitor, monitorProps)); } return /*#__PURE__*/React.createElement(ReactReduxContext.Consumer, null, props => { if (!props || !props.store) { logError('NoStore'); return null; } if (!props.store.liftedStore) { logError('NoLiftedStore'); return null; } return /*#__PURE__*/React.createElement(Provider, { store: props.store.liftedStore }, /*#__PURE__*/React.createElement(ConnectedMonitor, monitorProps)); }); } if (!this.liftedStore) { return null; } return /*#__PURE__*/React.createElement(ConnectedMonitor, _extends({}, monitorProps, { store: this.liftedStore })); } }; }