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

Code before:
          )
          didWarnAboutPrefix = true
        }
        return ''
      },
      set: () => {
        if (!didWarnAboutPrefix) {
          console.warn(
            '[zustand devtools middleware] along with `api.devtools`, `api.devtools.prefix` is deprecated.\n' +
              'We no longer prefix the actions/names' +
              devtoolsOptions.name ===
              undefined
              ? ', pass the `name` option to create a separate instance of devtools for each store.'
              : ', because the `name` option already creates a separate instance of devtools for each store.'
          )
          didWarnAboutPrefix = true
        }
      },
    })

    let isRecording = true
    ;(api.setState as NamedSet<S>) = (state, replace, nameOrAction) => {
      set(state, replace)
      if (!isRecording) return
      extension.send(
        nameOrAction === undefined
          ? { type: devtoolsOptions.anonymousActionType || 'anonymous' }
          : typeof nameOrAction === 'string'
          ? { type: nameOrAction }
          : nameOrAction,
        get()
      )
    }
    const setStateFromDevtools: SetState<S> = (...a) => {
      isRecording = false
      set(...a)
      isRecording = true
    }

    const initialState = fn(api.setState, get, api)
    extension.init(initialState)

    extension.subscribe((message: any) => {
      switch (message.type) {
        case 'ACTION':
          return parseJsonThen<{ type: unknown; state?: PartialState<S> }>(
            message.payload,
            (action) => {
              if (action.type === '__setState') {
                setStateFromDevtools(action.state as PartialState<S>)
                return

Review comment (suggestion):
I suppose falsy check instead of nullish check is enough (can't imagine if anyone wants an empty string for action type). There's no other code using nullish check in this repo. So, want to make it consistent.

Code after:
          didWarnAboutPrefix = true
        }
        return ''
      },
      set: () => {
        if (!didWarnAboutPrefix) {
          console.warn(
            '[zustand devtools middleware] along with `api.devtools`, `api.devtools.prefix` is deprecated.\n' +
              'We no longer prefix the actions/names' +
              devtoolsOptions.name ===
              undefined
              ? ', pass the `name` option to create a separate instance of devtools for each store.'
              : ', because the `name` option already creates a separate instance of devtools for each store.'
          )
          didWarnAboutPrefix = true
        }
      },
    })

    let isRecording = true
    ;(api.setState as NamedSet<S>) = (state, replace, nameOrAction) => {
      set(state, replace)
      if (!isRecording) return
      extension.send(
        nameOrAction === undefined
          ? { type: devtoolsOptions.anonymousActionType || 'anonymous' }
          : typeof nameOrAction === 'string'
          ? { type: nameOrAction }
          : nameOrAction,
        get()
      )
    }
    const setStateFromDevtools: SetState<S> = (...a) => {
      isRecording = false
      set(...a)
      isRecording = true
    }

    const initialState = fn(api.setState, get, api)
    extension.init(initialState)

    extension.subscribe((message: any) => {
      switch (message.type) {
        case 'ACTION':
          return parseJsonThen<{ type: unknown; state?: PartialState<S> }>(
            message.payload,
            (action) => {
              if (action.type === '__setState') {
                setStateFromDevtools(action.state as PartialState<S>)
                return
              }