addons/isl/src/third-party/jotai-devtools/utils/redux-extension/getReduxExtension.tsblame
View source
b69ab311// Ignore nocheck warning in third-party
b69ab312// eslint-disable-next-line @typescript-eslint/ban-ts-comment
b69ab313// @ts-nocheck
b69ab314import { isDev as __DEV__ } from '../../../../utils';
b69ab315
b69ab316// Original but incomplete type of the redux extension package
b69ab317type Extension = NonNullable<typeof window.__REDUX_DEVTOOLS_EXTENSION__>;
b69ab318
b69ab319export type ReduxExtension = {
b69ab3110 /** Create a connection to the extension.
b69ab3111 * This will connect a store (like an atom) to the extension and
b69ab3112 * display it within the extension tab.
b69ab3113 *
b69ab3114 * @param options https://github.com/reduxjs/redux-devtools/blob/main/extension/docs/API/Arguments.md
b69ab3115 * @returns https://github.com/reduxjs/redux-devtools/blob/main/extension/docs/API/Methods.md#connectoptions
b69ab3116 */
b69ab3117 connect: Extension['connect'];
b69ab3118
b69ab3119 /** Disconnects all existing connections to the redux extension.
b69ab3120 * Only use this when you are sure that no other connection exists
b69ab3121 * or you want to remove all existing connections.
b69ab3122 */
b69ab3123 disconnect?: () => void;
b69ab3124
b69ab3125 /** Have a look at the documentation for more methods:
b69ab3126 * https://github.com/reduxjs/redux-devtools/blob/main/extension/docs/API/Methods.md
b69ab3127 */
b69ab3128};
b69ab3129
b69ab3130/** Returns the global redux extension object if available */
b69ab3131export const getReduxExtension = (
b69ab3132 enabled = __DEV__,
b69ab3133): ReduxExtension | undefined => {
b69ab3134 if (!enabled) {
b69ab3135 return undefined;
b69ab3136 }
b69ab3137
b69ab3138 const reduxExtension = window.__REDUX_DEVTOOLS_EXTENSION__;
b69ab3139 if (!reduxExtension && __DEV__) {
b69ab3140 console.warn('Please install/enable Redux devtools extension');
b69ab3141 return undefined;
b69ab3142 }
b69ab3143
b69ab3144 return reduxExtension;
b69ab3145};