Repository: pmndrs/zustand
File: src/middleware/devtools.ts (TypeScript)

Code before:

    type S = ReturnType<typeof fn> & {
      [store: string]: ReturnType<typeof fn>
    }
    type PartialState = Partial<S> | ((s: S) => Partial<S>)

    let extensionConnector:
      | (typeof window)['__REDUX_DEVTOOLS_EXTENSION__']
      | false
    try {
      extensionConnector =
        (enabled ?? import.meta.env?.MODE !== 'production') &&
        window.__REDUX_DEVTOOLS_EXTENSION__
    } catch {
      // ignored
    }

    if (!extensionConnector) {
      return fn(set, get, api)
    }

    const { connection, ...connectionInformation } =
      extractConnectionInformation(store, extensionConnector, options)

    const isActionBlacklisted = (action: { type: string }): boolean => {
      if (!actionBlacklist) return false
      if (Array.isArray(actionBlacklist)) {
        return actionBlacklist.includes(action.type)
      }
      if (typeof actionBlacklist === 'function') {
        return actionBlacklist(action)
      }
      return false
    }

    let isRecording = true
    ;(api.setState as any) = ((state, replace, nameOrAction: Action) => {
      const r = set(state, replace as any)
      if (!isRecording) return r
      const action: { type: string } =
        nameOrAction === undefined
          ? {
              type:
                anonymousActionType ||
                findCallerName(new Error().stack) ||
                'anonymous',
            }
          : typeof nameOrAction === 'string'
            ? { type: nameOrAction }
            : nameOrAction


Review comment (suggestion):
Just stylistic preference.

```suggestion
      if (!actionBlacklist) {
        return false
      }
```

Or:
```ts
const isActionBlacklisted = (action: { type: string }): boolean =>
  !actionBlacklist ? false
  : Array.isArray(actionBlacklist) ? actionBlacklist.includes(action.type)
  : typeof actionBlacklist === 'function' ? actionBlacklist(action)
  : false
```
but maybe it's not very readable.

Hm, I don't think we need `!actionBlacklist ? false` at all.

So, it can be:
```suggestion
```

Code after:
      [store: string]: ReturnType<typeof fn>
    }
    type PartialState = Partial<S> | ((s: S) => Partial<S>)

    let extensionConnector:
      | (typeof window)['__REDUX_DEVTOOLS_EXTENSION__']
      | false
    try {
      extensionConnector =
        (enabled ?? import.meta.env?.MODE !== 'production') &&
        window.__REDUX_DEVTOOLS_EXTENSION__
    } catch {
      // ignored
    }

    if (!extensionConnector) {
      return fn(set, get, api)
    }

    const { connection, ...connectionInformation } =
      extractConnectionInformation(store, extensionConnector, options)

    let isRecording = true
    ;(api.setState as any) = ((state, replace, nameOrAction: Action) => {
      const r = set(state, replace as any)
      if (!isRecording) return r
      const action: { type: string } =
        nameOrAction === undefined
          ? {
              type:
                anonymousActionType ||
                findCallerName(new Error().stack) ||
                'anonymous',
            }
          : typeof nameOrAction === 'string'
            ? { type: nameOrAction }
            : nameOrAction
      if (store === undefined) {
        connection?.send(action, get())
        return r
      }
      connection?.send(
        {
          ...action,
          type: `${store}/${action.type}`,
        },
        {
          ...getTrackedConnectionState(options.name),
          [store]: api.getState(),
        },
      )