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