(fn, devtoolsOptions = {})
| 187 | |
| 188 | const devtoolsImpl: DevtoolsImpl = |
| 189 | (fn, devtoolsOptions = {}) => |
| 190 | (set, get, api) => { |
| 191 | const { enabled, anonymousActionType, store, ...options } = devtoolsOptions |
| 192 | |
| 193 | type S = ReturnType<typeof fn> & { |
| 194 | [store: string]: ReturnType<typeof fn> |
| 195 | } |
| 196 | type PartialState = Partial<S> | ((s: S) => Partial<S>) |
| 197 | |
| 198 | let extensionConnector: |
| 199 | | (typeof window)['__REDUX_DEVTOOLS_EXTENSION__'] |
| 200 | | false |
| 201 | try { |
| 202 | extensionConnector = |
| 203 | (enabled ?? import.meta.env?.MODE !== 'production') && |
| 204 | window.__REDUX_DEVTOOLS_EXTENSION__ |
| 205 | } catch { |
| 206 | // ignored |
| 207 | } |
| 208 | |
| 209 | if (!extensionConnector) { |
| 210 | return fn(set, get, api) |
| 211 | } |
| 212 | |
| 213 | const { connection, ...connectionInformation } = |
| 214 | extractConnectionInformation(store, extensionConnector, options) |
| 215 | |
| 216 | let isRecording = true |
| 217 | api.setState = ((state, replace, nameOrAction: Action) => { |
| 218 | const r = set(state, replace as any) |
| 219 | if (!isRecording) return r |
| 220 | const action: { type: string } = |
| 221 | nameOrAction === undefined |
| 222 | ? { |
| 223 | type: |
| 224 | anonymousActionType || |
| 225 | findCallerName(new Error().stack) || |
| 226 | 'anonymous', |
| 227 | } |
| 228 | : typeof nameOrAction === 'string' |
| 229 | ? { type: nameOrAction } |
| 230 | : nameOrAction |
| 231 | if (store === undefined) { |
| 232 | connection?.send(action, get()) |
| 233 | return r |
| 234 | } |
| 235 | connection?.send( |
| 236 | { |
| 237 | ...action, |
| 238 | type: `${store}/${action.type}`, |
| 239 | }, |
| 240 | { |
| 241 | ...getTrackedConnectionState(options.name), |
| 242 | [store]: api.getState(), |
| 243 | }, |
| 244 | ) |
| 245 | return r |
| 246 | }) as NamedSet<S> |
nothing calls this directly
no test coverage detected
searching dependent graphs…