| 1 | // Ignore nocheck warning in third-party |
| 2 | // eslint-disable-next-line @typescript-eslint/ban-ts-comment |
| 3 | // @ts-nocheck |
| 4 | import { isDev as __DEV__ } from '../../../../utils'; |
| 5 | |
| 6 | // Original but incomplete type of the redux extension package |
| 7 | type Extension = NonNullable<typeof window.__REDUX_DEVTOOLS_EXTENSION__>; |
| 8 | |
| 9 | export type ReduxExtension = { |
| 10 | /** Create a connection to the extension. |
| 11 | * This will connect a store (like an atom) to the extension and |
| 12 | * display it within the extension tab. |
| 13 | * |
| 14 | * @param options https://github.com/reduxjs/redux-devtools/blob/main/extension/docs/API/Arguments.md |
| 15 | * @returns https://github.com/reduxjs/redux-devtools/blob/main/extension/docs/API/Methods.md#connectoptions |
| 16 | */ |
| 17 | connect: Extension['connect']; |
| 18 | |
| 19 | /** Disconnects all existing connections to the redux extension. |
| 20 | * Only use this when you are sure that no other connection exists |
| 21 | * or you want to remove all existing connections. |
| 22 | */ |
| 23 | disconnect?: () => void; |
| 24 | |
| 25 | /** Have a look at the documentation for more methods: |
| 26 | * https://github.com/reduxjs/redux-devtools/blob/main/extension/docs/API/Methods.md |
| 27 | */ |
| 28 | }; |
| 29 | |
| 30 | /** Returns the global redux extension object if available */ |
| 31 | export const getReduxExtension = ( |
| 32 | enabled = __DEV__, |
| 33 | ): ReduxExtension | undefined => { |
| 34 | if (!enabled) { |
| 35 | return undefined; |
| 36 | } |
| 37 | |
| 38 | const reduxExtension = window.__REDUX_DEVTOOLS_EXTENSION__; |
| 39 | if (!reduxExtension && __DEV__) { |
| 40 | console.warn('Please install/enable Redux devtools extension'); |
| 41 | return undefined; |
| 42 | } |
| 43 | |
| 44 | return reduxExtension; |
| 45 | }; |
| 46 | |